提交 f47b288c authored 作者: Razvan Pascanu's avatar Razvan Pascanu

fix to failing test for scan

This test fails because of small numbers (the gradients are especially susceptible to small numbers). Increasing the range from which we sample, it doesn't mean that there will not be a seed there for which the sampled numbers are small enough (or a few entries are small enough) to get in that instability region
上级 5f8e9721
......@@ -2725,9 +2725,18 @@ class T_Scan(unittest.TestCase):
grad_fn = theano.function([xinit, w], [gx,gw],
allow_input_downcast = True)
rng = numpy.random.RandomState(utt.fetch_seed())
v_x = numpy.array(rng.uniform(size=(5,2,3), low=-3., high=3.),
# If numbers are small, the gradients with respect to x are samll
# and the numeric differentiation becomes unstable.
# To fix this issue I unsreu we are sampling numbers larger then in
# absolute value then 1
v_x = numpy.array(rng.uniform(size=(5,2,3), low=1., high=3.),
dtype=theano.config.floatX)
v_w = numpy.array(rng.uniform(size=(2,2), low=-3., high=3.), dtype= theano.config.floatX)
# making some entries to be smaller then 1
pos = rng.uniform(size=(5, 2, 3), low=0., high=1) < .5
v_x[pos] = -1 * v_x[pos]
v_w = numpy.array(rng.uniform(size=(2,2), low=1., high=3.), dtype= theano.config.floatX)
pos = rng.uniform(size=(2,2), low=0., high=1.) < .5
v_w[pos] = -1 * v_w[pos]
analytic_grad = grad_fn(v_x, v_w)
num_grad = multiple_outputs_numeric_grad(cost_fn,
[v_x, v_w])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论