import numpy as np import theano.tensor as T import matplotlib.pyplot as plt np.random.seed(2016) nbasis=36 ndims=12 n_steps=1000 half_window=False rand_val = rand(ndims,nbasis/2,density=0.1) W = np.concatenate([rand_val.toarray(), -rand_val.toarray()],axis=1) logalpha = np.random.randn(nbasis,1) PoT_instance = ProductOfT(nbatch=100,ndims=ndims,nbasis=nbasis,W=W,logalpha=logalpha) simulate = hmc.wrapper_hmc(s_rng=s_rng,energy_fn=rw.E_val,dim=dim) a = np.zeros([1,10,n_samples]) b = np.zeros([2,10,n_samples]) for ii in np.arange(n_steps): a[:,:,ii],b[:,:,ii] = simulate() print "Acceptance Rate" print a[:,:,ii] print "Samples" print b[:,:,ii] ac_df = autocorrelation(df,half_window) #Now, we can run the same autocorrelation from the data we will extract from the data frame #but with the theano function ac= hmc.normed_autocorrelation(df)
#Temp script to test the fast HMC from mjhmc.fast import hmc from mjhmc.fast.distributions_T import RoughWell import theano.tensor as T import numpy as np import time tm1 = time.time() seed = 1234 s_rng = T.shared_randomstreams.RandomStreams(seed) ndims = 64 nbatch = 250 rw = RoughWell(nbatch=nbatch) simulate = hmc.wrapper_hmc(s_rng=s_rng,energy_fn=rw.E_val,dim=[ndims,nbatch]) n_samples = 1000 a = np.zeros([1,nbatch,n_samples]) b = np.zeros([ndims,nbatch,n_samples]) for ii in np.arange(n_samples): a[:,:,ii],b[:,:,ii] = simulate() print "Acceptance Rate" print a[:,:,ii] print "Samples" print b[:,:,ii] tm2 = time.time() print tm2-tm1