Mercurial > pylearn
view pylearn/formulas/noise.py @ 1208:0186805a93e7
removed import that is not used.
author | Frederic Bastien <nouiz@nouiz.org> |
---|---|
date | Tue, 21 Sep 2010 14:42:38 -0400 |
parents | be53f56b37b8 |
children | b9bc9d5a08cc |
line wrap: on
line source
""" This script define the different symbolic noise functions. The noise contract is simple: noise_lvl is a symbolic variable going from 0 to 1. 0: no changement. 1: max noise. """ import theano from tags import tags s=""" * A latex mathematical description of the formulas(for picture representation in generated documentation) * Tags(for searching): * a list of lower lovel fct used * category(name of the submodule itself) * Tell if we did some work to make it more numerical stable. Do theano do the optimization needed? * Tell if the grad is numericaly stable? Do theano do the optimization needed? * Tell if work on gpu/not/unknow * Tell alternate name * Tell the domaine, range of the input/output(range should use the english notation of including or excluding) """ @tags('noise','binomial','salt') def binomial_noise(theano_rng,inp,noise_lvl): """ This add binomial noise to inp. Only the salt part of pepper and salt. :type inp: Theano Variable :param inp: The input that we want to add noise :type noise_lvl: float :param noise_lvl: The % of noise. Between 0(no noise) and 1. """ return theano_rng.binomial( size = inp.shape, n = 1, p = 1 - noise_lvl, dtype=theano.config.floatX) * inp @tags('noise','binomial NLP','pepper','salt') def pepper_and_salt_noise(theano_rng,inp,noise_lvl): """ This add pepper and salt noise to inp :type inp: Theano Variable :param inp: The input that we want to add noise :type noise_lvl: tuple(float,float) :param noise_lvl: The % of noise for the salt and pepper. Between 0(no noise) and 1. """ return theano_rng.binomial( size = inp.shape, n = 1, p = 1 - noise_lvl[0], dtype=theano.config.floatX) * inp \ + (inp==0) * theano_rng.binomial( size = inp.shape, n = 1, p = noise_lvl[1], dtype=theano.config.floatX) @tags('noise','gauss','gaussian') def gaussian_noise(theano_rng,inp,noise_lvl): """ This add gaussian NLP noise to inp :type inp: Theano Variable :param inp: The input that we want to add noise :type noise_lvl: float :param noise_lvl: The standard deviation of the gaussian. """ return theano_rng.normal( size = inp.shape, std = noise_lvl, dtype=theano.config.floatX) + inp