Skip to content

Commit

Permalink
add test for density with generators
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrine committed Jan 19, 2017
1 parent 1630a76 commit 91011b5
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion pymc3/tests/test_model.py
@@ -1,5 +1,6 @@
import unittest
from theano import theano, tensor as tt
import numpy as np
import pymc3 as pm
from pymc3.distributions import HalfCauchy, Normal
from pymc3 import Potential, Deterministic
Expand Down Expand Up @@ -127,4 +128,32 @@ def test_density_scaling(self):
with pm.Model() as model2:
Normal('n', observed=[[1]], total_size=2)
p2 = theano.function([], model2.logpt)
self.assertEqual(p1() * 2, p2())
self.assertEqual(p1() * 2, p2())

def test_density_scaling_with_genarator(self):
# We have different size generators
def gen1():
i = 0
while True:
yield np.ones((10, 100)) * i
i += 1

def gen2():
i = 0
while True:
yield np.ones((20, 100)) * i
i += 1

# We have same size models
with pm.Model() as model1:
Normal('n', observed=gen1(), total_size=100)
p1 = theano.function([], model1.logpt)

with pm.Model() as model2:
Normal('n', observed=gen2(), total_size=100)
p2 = theano.function([], model2.logpt)

# We want densities to be equal
for _ in range(10):
np.testing.assert_almost_equal(p1(), p2())
# Done

0 comments on commit 91011b5

Please sign in to comment.