コード例 #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)