# HG changeset patch # User Frederic Bastien # Date 1286996682 14400 # Node ID 1b97fae7ea0d3873aca21fefd6d2398b6259fad1 # Parent 4efa2630f430098b37febaf69e5364d97f86ccc3 added the parameter noise_value to binomial_noise formula. diff -r 4efa2630f430 -r 1b97fae7ea0d pylearn/formulas/noise.py --- a/pylearn/formulas/noise.py Wed Oct 13 10:19:48 2010 -0400 +++ b/pylearn/formulas/noise.py Wed Oct 13 15:04:42 2010 -0400 @@ -22,7 +22,7 @@ """ @tags.tags('noise','binomial','salt') -def binomial_noise(theano_rng,input,noise_lvl): +def binomial_noise(theano_rng, input, noise_lvl, noise_value=0): """ Return `inp` with randomly-chosen elements set to zero. @@ -32,13 +32,21 @@ :param input: input :type noise_lvl: float :param noise_lvl: The probability of setting each element to zero. + :type noise_value: Theano scalar variable + :param noise_value: The value that we want when their is noise. """ mask = theano_rng.binomial( - size = inp.shape, + size = input.shape, n = 1, p = 1 - noise_lvl, - dtype=inp.dtype) - return mask * input + dtype=input.dtype) + value = theano.tensor.as_tensor_variable(noise_value) + if value.type.ndim!=0: + raise Exception('binomial_noise only support scalar noise_value') + if noise_value==0: + return mask * input + else: + return mask * input + noise_value*(not mask) @tags.tags('noise','binomial NLP','pepper','salt')