-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexperiment.py
82 lines (70 loc) · 2.32 KB
/
experiment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
### experiments from the paper
### not all of these made it into the paper, but they give a good idea of how
### the code works
from sage.all import *
import numpy.random
from collections import deque
import random
import numpy as np
import my_bliss
from my_graphs import *
import cProfile, pstats, StringIO
from test import *
import itertools
import time
### computes the total variation distance comparing different sampling methods
def complete_pairwise_dtv():
model = gen_complete_pairwise_factorgraph(6)
gibbs = model.gibbs_transition()
# print(gibbs)
# print(sum(gibbs))
within_orbit = model.orbit_transition()
orbitalmcmc = np.matmul(within_orbit, gibbs)
# unif = model.uniform_transition()
burnside = model.burnside_mh_transition(4)
M = orbitalmcmc
pv = model.brute_force_prob_vector()
start = np.zeros([2**len(model.variables)])
start[10] = 1
# print(np.linalg.matrix_power(M, 5))
print("-------------------")
print("pure gibbs")
model.total_variation(gibbs, start, 100)
print("-------------------")
print("lifted MCMC")
model.total_variation(orbitalmcmc, start, 100)
print("------------------")
print("orbit jump MCMC")
model.total_variation(burnside, start, 100)
def complete_pairwise_exact():
model = gen_complete_pairwise_factorgraph(6)
print("partition: %f" % model.partition())
def pigeonhole_dtv():
model = mk_pigeonhole_fg(2,5)
gibbs = model.gibbs_transition()
# print(gibbs)
# print(sum(gibbs))
within_orbit = model.orbit_transition()
orbitalmcmc = np.matmul(within_orbit, gibbs)
# unif = model.uniform_transition()
burnside = model.burnside_mh_transition(4)
M = orbitalmcmc
pv = model.brute_force_prob_vector()
start = np.zeros([2**len(model.variables)])
start[10] = 1
# print(np.linalg.matrix_power(M, 5))
print("-------------------")
print("pure gibbs")
model.total_variation(gibbs, start, 100)
print("-------------------")
print("lifted MCMC")
model.total_variation(orbitalmcmc, start, 100)
print("------------------")
print("orbit jump MCMC")
model.total_variation(burnside, start, 100)
def pigeonhole_exact_lifted():
model = mk_pigeonhole_fg(2,5)
model.partition()
if __name__ == "__main__":
# run your test here if you want
pigeonhole_dtv()