def test_hmc(): # load test data datadir = os.path.join(os.path.dirname(phasemodel.__file__), 'tests', 'testdata') mdict = np.load(os.path.join(datadir, 'three_phases_v2.npz')) for var in mdict.files: globals()[var] = mdict[var] sz = K_true.shape[0] # convert coupling from complex 3x3 to real 6x6 matrix M = kappa2m(K_true) # some settings opts = hmc2.opt(nsamples=10**3, nomit=10**3, steps=50, stepadj=.15, persistence=False) # generate test data utils.tic() samps = hmc2.hmc2(en.f_phasedist, np.zeros(sz), opts, en.g_phasedist, M) data = utils.smod(samps.T) utils.toc() # fit test data K_fit = phasemodel.model.fit_model(data) print K_true print K_fit K_error = (abs(K_true - K_fit)).mean() print """ mean-absolute-difference = %6.8f; expect: 0.1 """ % (K_error)
def test_hmc_biased(): # generate random coupling dim = 5 K_true = np.random.randn(dim + 1, dim + 1) + 1j * np.random.randn(dim + 1, dim + 1) K_true[np.diag(np.ones(dim + 1, bool))] = 0 K_true = .5 * (K_true + np.conj(K_true.T)) # convert coupling from complex 3x3 to real 6x6 matrix M = kappa2m(K_true) # some settings opts = hmc2.opt(nsamples=10**3, nomit=10**3, steps=50, stepadj=.15, persistence=False) # generate test data utils.tic() samps = hmc2.hmc2(en.f_phasedist_biased, np.zeros(dim), opts, en.g_phasedist_biased, M) data = utils.smod(samps.T) utils.toc() # fit test data K_fit = phasemodel.model.fit_model_biased(data) print K_true print K_fit K_error = (abs(K_true - K_fit)).mean() print """ mean-absolute-difference = %6.8f; expect: 0.2 """ % (K_error)
def test_hmc(): # load test data datadir = os.path.join(os.path.dirname(phasemodel.__file__),'tests','testdata') mdict = np.load(os.path.join(datadir,'three_phases_v2.npz')) for var in mdict.files: globals()[var] = mdict[var] sz = K_true.shape[0] # convert coupling from complex 3x3 to real 6x6 matrix M = kappa2m(K_true); # some settings opts = hmc2.opt( nsamples = 10**3, nomit = 10**3, steps = 50, stepadj = .15, persistence = False) # generate test data utils.tic() samps = hmc2.hmc2(en.f_phasedist,np.zeros(sz),opts,en.g_phasedist,M) data = utils.smod(samps.T) utils.toc() # fit test data K_fit = phasemodel.model.fit_model(data); print K_true print K_fit K_error = (abs(K_true-K_fit)).mean() print """ mean-absolute-difference = %6.8f; expect: 0.1 """%(K_error)
def test_hmc_biased(): # generate random coupling dim = 5 K_true = np.random.randn(dim+1,dim+1)+1j*np.random.randn(dim+1,dim+1) K_true[np.diag(np.ones(dim+1,bool))] = 0 K_true = .5*(K_true+np.conj(K_true.T)) # convert coupling from complex 3x3 to real 6x6 matrix M = kappa2m(K_true); # some settings opts = hmc2.opt( nsamples = 10**3, nomit = 10**3, steps = 50, stepadj = .15, persistence = False) # generate test data utils.tic() samps = hmc2.hmc2(en.f_phasedist_biased,np.zeros(dim),opts,en.g_phasedist_biased,M) data = utils.smod(samps.T) utils.toc() # fit test data K_fit = phasemodel.model.fit_model_biased(data); print K_true print K_fit K_error = (abs(K_true-K_fit)).mean() print """ mean-absolute-difference = %6.8f; expect: 0.2 """%(K_error)