Skip to content

Commit

Permalink
Add test for apply_noise
Browse files Browse the repository at this point in the history
  • Loading branch information
bartvm committed Jan 15, 2015
1 parent fbf56bf commit 033dd9a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/test_graph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from numpy.testing import assert_allclose
from theano import tensor
from theano.tensor.shared_randomstreams import RandomStreams

from blocks.bricks import Brick
from blocks.graph import ComputationGraph
from blocks.graph import apply_noise, ComputationGraph
from tests.bricks.test_bricks import TestBrick


Expand Down Expand Up @@ -38,3 +40,15 @@ def test_computation_graph():
cg2 = cg.replace({z: r})
assert set(cg2.inputs) == {r}
assert set([v.name for v in cg2.outputs]) == {'a', 'b'}


def test_apply_noise():
x = tensor.scalar()
y = tensor.scalar()
z = x + y

cg = ComputationGraph([z])
rng = RandomStreams(1)
noised_cg = apply_noise(cg, [y], 1, rng)
assert_allclose(noised_cg.outputs[0].eval({x: 1., y: 1.}),
2 + RandomStreams(1).normal().eval())

0 comments on commit 033dd9a

Please sign in to comment.