Ejemplo n.º 1
0
 def test_aevb_empirical(self):
     _, model, _ = models.exponential_beta(n=2)
     x = model.x
     mu = theano.shared(x.init_value)
     rho = theano.shared(np.zeros_like(x.init_value))
     with model:
         inference = ADVI(local_rv={x: (mu, rho)})
         approx = inference.approx
         trace0 = approx.sample(10000)
         approx = Empirical(trace0, local_rv={x: (mu, rho)})
         trace1 = approx.sample(10000)
         approx.random(no_rand=True)
         approx.random_fn(no_rand=True)
     np.testing.assert_allclose(trace0['y'].mean(0),
                                trace1['y'].mean(0),
                                atol=0.02)
     np.testing.assert_allclose(trace0['y'].var(0),
                                trace1['y'].var(0),
                                atol=0.02)
     np.testing.assert_allclose(trace0['x'].mean(0),
                                trace1['x'].mean(0),
                                atol=0.02)
     np.testing.assert_allclose(trace0['x'].var(0),
                                trace1['x'].var(0),
                                atol=0.02)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def test_aevb_empirical():
    _, model, _ = models.exponential_beta(n=2)
    x = model.x
    mu = theano.shared(x.init_value)
    rho = theano.shared(np.zeros_like(x.init_value))
    with model:
        inference = ADVI(local_rv={x: (mu, rho)})
        approx = inference.approx
        trace0 = approx.sample(10000)
        approx = Empirical(trace0, local_rv={x: (mu, rho)})
        trace1 = approx.sample(10000)
    np.testing.assert_allclose(trace0['y'].mean(0), trace1['y'].mean(0), atol=0.02)
    np.testing.assert_allclose(trace0['y'].var(0), trace1['y'].var(0), atol=0.02)
    np.testing.assert_allclose(trace0['x'].mean(0), trace1['x'].mean(0), atol=0.02)
    np.testing.assert_allclose(trace0['x'].var(0), trace1['x'].var(0), atol=0.02)