changeset 1326:1b97fae7ea0d

added the parameter noise_value to binomial_noise formula.
author Frederic Bastien <nouiz@nouiz.org>
date Wed, 13 Oct 2010 15:04:42 -0400
parents 4efa2630f430
children 9a7dbcd0ebcf
files pylearn/formulas/noise.py
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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')