-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun_Me.py
More file actions
95 lines (45 loc) · 1.67 KB
/
Run_Me.py
File metadata and controls
95 lines (45 loc) · 1.67 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
==================
MPF on Potts Model
==================
There are 4 steps:
1- Generate the Original coupling matrix randomly
2- Generate a sample from the above matrix
3- Fit MPF to the sample and find the Fit coupling matrix
4- Compare the Original and Fit coupling matrices
"""
from Gibbs_Potts import sampler
from MPF_Fitter import MPF
from Plots import coupling, covariance
import numpy as np
def main():
"""
Parameters
----------
q : Potts model parameter -- q equals 2 converges to Ising model
dim : size of the coupling matrices
nsample : sample size -- for bigger q should be bigger
seed : for consistancy
"""
q = 10
dim = 40
nsamples = 50000
seed = 13
# 1- Generate the original coupling matrix randomly
rng = np.random.RandomState(seed)
J_orig = rng.randn(dim, dim)/np.sqrt(dim)
np.fill_diagonal(J_orig, 0.)
J_orig = (J_orig + J_orig.T) / 2.
# 2- Generate a sample from the above matrix
o = sampler(q, dim, rng)
samples_orig = o.sampler(J_orig, nsamples)
# 3- Fit MPF to the sample and find the Fit coupling matrix
J_fit = o.minimizer(samples_orig)
# 4- Compare the Original and Fit coupling matrices
coupling(J_orig, J_fit)
# Also compare the covariance of the samples from Original and Fit coupling matrices
samples_fit = o.sampler(J_fit, nsamples)
covariance(J_orig, J_fit, samples_orig, samples_fit)
print (J_orig - J_fit).min(), (J_orig - J_fit).max()
if __name__ == '__main__':
main()