예제 #1
0
 def test_vars_view(self):
     _, model, _ = models.multidimensional_model()
     with model:
         app = self.inference().approx
         posterior = app.random(10)
         x_sampled = app.view(posterior, 'x').eval()
     assert x_sampled.shape == (10, ) + model['x'].dshape
예제 #2
0
 def test_vars_view(self):
     _, model, _ = models.multidimensional_model()
     with model:
         app = self.inference().approx
         posterior = app.random(10)
         x_sampled = app.view(posterior, 'x').eval()
     assert x_sampled.shape == (10,) + model['x'].dshape
예제 #3
0
 def test_approximate(self):
     with models.multidimensional_model()[1]:
         meth = ADVI()
         fit(10, method=meth)
         with pytest.raises(KeyError):
             fit(10, method='undefined')
         with pytest.raises(TypeError):
             fit(10, method=1)
예제 #4
0
 def test_combined(self):
     with models.multidimensional_model()[1]:
         self.assertRaises(ValueError,
                           fit,
                           10,
                           method='advi->fullrank_advi',
                           frac=1)
         fit(10, method='advi->fullrank_advi', frac=.5)
예제 #5
0
 def test_sampling(self):
     with models.multidimensional_model()[1]:
         full_rank = FullRankADVI()
         approx = full_rank.fit(20)
         trace0 = approx.sample_vp(10000)
         histogram = Histogram(trace0)
     trace1 = histogram.sample_vp(100000)
     np.testing.assert_allclose(trace0['x'].mean(0), trace1['x'].mean(0), atol=0.01)
     np.testing.assert_allclose(trace0['x'].var(0), trace1['x'].var(0), atol=0.01)
예제 #6
0
 def test_sampling(self):
     with models.multidimensional_model()[1]:
         full_rank = FullRankADVI()
         approx = full_rank.fit(20)
         trace0 = approx.sample(10000)
         approx = Empirical(trace0)
     trace1 = approx.sample(100000)
     np.testing.assert_allclose(trace0['x'].mean(0), trace1['x'].mean(0), atol=0.01)
     np.testing.assert_allclose(trace0['x'].var(0), trace1['x'].var(0), atol=0.01)
예제 #7
0
 def test_length_of_hist(self):
     with models.multidimensional_model()[1]:
         inf = self.inference()
         assert len(inf.hist) == 0
         inf.fit(10)
         assert len(inf.hist) == 10
         assert not np.isnan(inf.hist).any()
         inf.fit(self.NITER, obj_optimizer=self.optimizer)
         assert len(inf.hist) == self.NITER + 10
         assert not np.isnan(inf.hist).any()
예제 #8
0
 def test_length_of_hist(self):
     with models.multidimensional_model()[1]:
         inf = self.inference()
         assert len(inf.hist) == 0
         inf.fit(10)
         assert len(inf.hist) == 10
         assert not np.isnan(inf.hist).any()
         inf.fit(self.NITER, obj_optimizer=self.optimizer)
         assert len(inf.hist) == self.NITER + 10
         assert not np.isnan(inf.hist).any()
예제 #9
0
 def test_vars_view_dynamic_size(self):
     _, model, _ = models.multidimensional_model()
     with model:
         app = self.inference().approx
         i = tt.iscalar('i')
         i.tag.test_value = 1
         posterior = app.random(i)
     x_sampled = app.view(posterior, 'x').eval({i: 10})
     assert x_sampled.shape == (10,) + model['x'].dshape
     x_sampled = app.view(posterior, 'x').eval({i: 1})
     assert x_sampled.shape == (1,) + model['x'].dshape
예제 #10
0
 def test_vars_view_dynamic_size(self):
     _, model, _ = models.multidimensional_model()
     with model:
         app = self.inference().approx
         i = tt.iscalar('i')
         i.tag.test_value = 1
         posterior = app.random(i)
     x_sampled = app.view(posterior, 'x').eval({i: 10})
     assert x_sampled.shape == (10, ) + model['x'].dshape
     x_sampled = app.view(posterior, 'x').eval({i: 1})
     assert x_sampled.shape == (1, ) + model['x'].dshape
예제 #11
0
 def test_vars_view_dynamic_size_numpy(self):
     _, model, _ = models.multidimensional_model()
     with model:
         app = self.inference().approx
         i = tt.iscalar('i')
         i.tag.test_value = 1
     x_sampled = app.view(app.random_fn(10), 'x')
     assert x_sampled.shape == (10, ) + model['x'].dshape
     x_sampled = app.view(app.random_fn(1), 'x')
     assert x_sampled.shape == (1, ) + model['x'].dshape
     x_sampled = app.view(app.random_fn(), 'x')
     assert x_sampled.shape == () + model['x'].dshape
예제 #12
0
 def test_vars_view_dynamic_size_numpy(self):
     _, model, _ = models.multidimensional_model()
     with model:
         app = self.inference().approx
         i = tt.iscalar('i')
         i.tag.test_value = 1
     x_sampled = app.view(app.random_fn(10), 'x')
     assert x_sampled.shape == (10,) + model['x'].dshape
     x_sampled = app.view(app.random_fn(1), 'x')
     assert x_sampled.shape == (1,) + model['x'].dshape
     x_sampled = app.view(app.random_fn(), 'x')
     assert x_sampled.shape == () + model['x'].dshape
예제 #13
0
 def test_combined(self):
     with models.multidimensional_model()[1]:
         fit(10, method='advi->fullrank_advi', frac=.5)
예제 #14
0
 def test_combined(self):
     with models.multidimensional_model()[1]:
         with pytest.raises(ValueError):
             fit(10, method='advi->fullrank_advi', frac=1)
         fit(10, method='advi->fullrank_advi', frac=.5)
예제 #15
0
        def test_pickling(self):
            with models.multidimensional_model()[1]:
                inference = self.inference()

            inference = pickle.loads(pickle.dumps(inference))
            inference.fit(20)
예제 #16
0
 def test_init_from_noize(self):
     with models.multidimensional_model()[1]:
         approx = Empirical.from_noise(100)
         assert approx.histogram.eval().shape == (100, 6)
예제 #17
0
 def test_from_advi(self):
     with models.multidimensional_model()[1]:
         advi = ADVI()
         full_rank = FullRankADVI.from_advi(advi)
         full_rank.fit(20)
예제 #18
0
 def test_from_mean_field(self):
     with models.multidimensional_model()[1]:
         advi = ADVI()
         full_rank = FullRankADVI.from_mean_field(advi.approx)
         full_rank.fit(20)
예제 #19
0
 def test_profile(self):
     with models.multidimensional_model()[1]:
         self.inference().run_profiling(10)
예제 #20
0
 def test_profile(self):
     with models.multidimensional_model()[1]:
         self.inference().run_profiling(10)
예제 #21
0
        def test_pickling(self):
            with models.multidimensional_model()[1]:
                inference = self.inference()

            inference = pickle.loads(pickle.dumps(inference))
            inference.fit(20)
예제 #22
0
 def test_approximate(self):
     with models.multidimensional_model()[1]:
         fit(10, method='fullrank_advi')
예제 #23
0
 def test_from_mean_field(self):
     with models.multidimensional_model()[1]:
         advi = ADVI()
         full_rank = FullRankADVI.from_mean_field(advi.approx)
         full_rank.fit(20)
예제 #24
0
 def test_approximate(self):
     with models.multidimensional_model()[1]:
         meth = ADVI()
         fit(10, method=meth)
         self.assertRaises(KeyError, fit, 10, method='undefined')
         self.assertRaises(TypeError, fit, 10, method=1)
예제 #25
0
 def test_from_advi(self):
     with models.multidimensional_model()[1]:
         advi = ADVI()
         full_rank = FullRankADVI.from_advi(advi)
         full_rank.fit(20)
예제 #26
0
 def test_init_from_noize(self):
     with models.multidimensional_model()[1]:
         histogram = Histogram.from_noise(100)
         assert histogram.histogram.eval().shape == (100, 6)