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
Esempio n. 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
 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)
 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)
Esempio n. 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)
 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)
Esempio n. 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()
 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()
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 13
0
 def test_combined(self):
     with models.multidimensional_model()[1]:
         fit(10, method='advi->fullrank_advi', frac=.5)
 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)
Esempio n. 15
0
        def test_pickling(self):
            with models.multidimensional_model()[1]:
                inference = self.inference()

            inference = pickle.loads(pickle.dumps(inference))
            inference.fit(20)
Esempio n. 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)
Esempio n. 17
0
 def test_from_advi(self):
     with models.multidimensional_model()[1]:
         advi = ADVI()
         full_rank = FullRankADVI.from_advi(advi)
         full_rank.fit(20)
Esempio n. 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)
Esempio n. 19
0
 def test_profile(self):
     with models.multidimensional_model()[1]:
         self.inference().run_profiling(10)
Esempio n. 20
0
 def test_profile(self):
     with models.multidimensional_model()[1]:
         self.inference().run_profiling(10)
Esempio n. 21
0
        def test_pickling(self):
            with models.multidimensional_model()[1]:
                inference = self.inference()

            inference = pickle.loads(pickle.dumps(inference))
            inference.fit(20)
Esempio n. 22
0
 def test_approximate(self):
     with models.multidimensional_model()[1]:
         fit(10, method='fullrank_advi')
Esempio n. 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)
Esempio n. 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)
Esempio n. 25
0
 def test_from_advi(self):
     with models.multidimensional_model()[1]:
         advi = ADVI()
         full_rank = FullRankADVI.from_advi(advi)
         full_rank.fit(20)
Esempio n. 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)