In [1]:
from bussilab import potts
import numpy as np
import matplotlib.pyplot as plt
In [2]:
m=potts.Model(6)
In [3]:
h=np.random.uniform(size=6)
J=np.reshape(np.random.uniform(size=36),(6,6))
J=m.fixJ(J) # make symmetric and cancel diagonal
h,J
Out[3]:
(array([0.88896261, 0.09934222, 0.45486963, 0.22375098, 0.9102452 ,
0.46952976]),
array([[0. , 0.44811401, 0.44179955, 0.60276147, 0.53811439,
0.59348674],
[0.44811401, 0. , 0.7390881 , 0.67438462, 0.62920129,
0.39100428],
[0.44179955, 0.7390881 , 0. , 0.51378989, 0.03647317,
0.28402245],
[0.60276147, 0.67438462, 0.51378989, 0. , 0.70031567,
0.89372253],
[0.53811439, 0.62920129, 0.03647317, 0.70031567, 0. ,
0.69047674],
[0.59348674, 0.39100428, 0.28402245, 0.89372253, 0.69047674,
0. ]]))
In [4]:
result=m.compute(h,J)
In [5]:
infer=m.infer(result[1])
h_inferred,J_inferred=infer.h,infer.J
In [6]:
h_inferred,J_inferred
Out[6]:
(array([0.88896262, 0.09934222, 0.45486963, 0.22375098, 0.91024519,
0.46952976]),
array([[0. , 0.44811401, 0.44179955, 0.60276146, 0.5381144 ,
0.59348673],
[0.44811401, 0. , 0.73908811, 0.67438462, 0.62920129,
0.39100428],
[0.44179955, 0.73908811, 0. , 0.51378989, 0.03647317,
0.28402245],
[0.60276146, 0.67438462, 0.51378989, 0. , 0.70031569,
0.89372252],
[0.5381144 , 0.62920129, 0.03647317, 0.70031569, 0. ,
0.69047674],
[0.59348673, 0.39100428, 0.28402245, 0.89372252, 0.69047674,
0. ]]))
In [7]:
plt.plot(h,h_inferred,"x")
plt.show()
np.sum((h-h_inferred)**2)
Out[7]:
3.0177189225292775e-16
In [8]:
plt.plot(J.flatten(),J_inferred.flatten(),"x")
plt.show()
np.sum((J-J_inferred)**2)
Out[8]:
2.195972799014477e-15