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)
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_from_full_rank(another_simple_model): with another_simple_model: fr = FullRank() full_rank = FullRankADVI.from_full_rank(fr) full_rank.fit(20)
def test_from_advi(another_simple_model): with another_simple_model: advi = ADVI() full_rank = FullRankADVI.from_advi(advi) full_rank.fit(20)
def test_from_mean_field(another_simple_model): with another_simple_model: advi = ADVI() full_rank = FullRankADVI.from_mean_field(advi.approx) full_rank.fit(20)
def test_from_advi(self): with models.multidimensional_model()[1]: advi = ADVI() full_rank = FullRankADVI.from_advi(advi) full_rank.fit(20)
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)
approx.randidx(1).eval() approx.random_fn(no_rand=True) approx.random_fn(no_rand=False) approx.histogram_logp.eval() def test_init_from_noize(self): with models.multidimensional_model()[1]: approx = Empirical.from_noise(100) assert approx.histogram.eval().shape == (100, 6) _model = models.simple_model()[1] with _model: pm.Potential('pot', tt.ones((10, 10))) _advi = ADVI() _fullrank_advi = FullRankADVI() _svgd = SVGD() @pytest.mark.parametrize( ['method', 'kwargs', 'error'], [('undefined', dict(), KeyError), (1, dict(), TypeError), (_advi, dict(start={}), None), (_fullrank_advi, dict(), None), (_svgd, dict(), None), ('advi', dict(), None), ('advi->fullrank_advi', dict(frac=.1), None), ('advi->fullrank_advi', dict(frac=1), ValueError), ('fullrank_advi', dict(), None), ('svgd', dict(), None), ('svgd', dict(start={}), None), ('svgd', dict(local_rv={_model.free_RVs[0]: (0, 1)}), ValueError)]) def test_fit(method, kwargs, error): with _model: