def test_autocorrelation_bad_init(self): """ Tests that the legacy and fast ac implementations produce identical output when the sampler is initialized with a bias set of samples :returns: None :rtype: None """ gaussian = MultimodalGaussian() sample_df = sample_to_df(MarkovJumpHMC, gaussian, num_steps=1000) slow_ac_df = slow_autocorrelation(sample_df) slow_ac = slow_ac_df.autocorrelation.as_matrix() fast_ac_df = autocorrelation(sample_df) fast_ac = fast_ac_df.autocorrelation.as_matrix() self.assertTrue(np.isclose(slow_ac, fast_ac, atol=TOL).all())
def test_autocorrelation_good_init_half_window(self): """ Tests that the legacy and fast ac implementations produce identical output when the sampler is not initialized in a biased manner (meaning we don't have to worry about variance mismatch) runs on the half window :returns: None :rtype: None """ gaussian = Gaussian() sample_df = sample_to_df(MarkovJumpHMC, gaussian, num_steps=1000) slow_ac_df = slow_autocorrelation(sample_df, half_window=True) slow_ac = slow_ac_df.autocorrelation.as_matrix() fast_ac_df = autocorrelation(sample_df, half_window=True) fast_ac = fast_ac_df.autocorrelation.as_matrix() self.assertTrue(np.isclose(slow_ac, fast_ac, atol=TOL).all())
import time np.random.seed(2015) nbasis=36 ndims=12 n_steps=30000 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,lognu=logalpha) df = sample_to_df(MarkovJumpHMC,Gaussian(ndims=10),num_steps=n_steps) tm1 = time.time() ac_df = slow_autocorrelation(df,half_window) tm2 = time.time() print tm2-tm1 #Now, we can run the same autocorrelation from the data we will extract from the data frame #but with the theano function tm1 = time.time() ac= autocorrelation(df) tm2 = time.time() print tm2-tm1 #We can compare the two plots individually and on a single plot #Drop Mic and leave. n_grad_evals = ac_df['num grad'].astype(int) fig = plt.figure() plt.plot(n_grad_evals,ac['autocorrelation'],'r')