Mercurial > pylearn
view pylearn/formulas/regularization.py @ 1381:0673e6af650a
Added regularization terms
author | boulanni <nicolas_boulanger@hotmail.com> |
---|---|
date | Mon, 06 Dec 2010 13:33:07 -0500 |
parents | |
children |
line wrap: on
line source
""" Different symbolic regularization and sparsity functions. """ import theano import theano.tensor as T from tags import tags __authors__ = "Frederic Bastien, Nicolas Boulanger-Lewandowski, .." __copyright__ = "(c) 2010, Universite de Montreal" __license__ = "3-clause BSD License" __contact__ = "theano-user <theano-users@googlegroups.com>" @tags('regularization', 'L1') def l1(x, target = 0, axis_sum = -1, axis_mean = 0): """ Construct the L1 regularization penalty :math:`\sum|x-target|` :type x: Theano variable :param x: Weights or other variable to regularize :type target: Theano variable :param target: Target of x :type axis_sum: Scalar :param axis_sum: Axis along which the penalty terms will be summed (e.g. output units) :type axis_mean: Scalar :param axis_mean: Axis along which the penalty terms will be averaged (e.g. minibatches) :note: no stabilization required """ return T.mean(T.sum(T.abs_(x - target), axis_sum), axis_mean) @tags('regularization', 'L2') def l2(x, target = 0, axis_sum = -1, axis_mean = 0): """ Construct the L2 regularization penalty :math:`\sum(x-target)^2` :type x: Theano variable :param x: Weights or other variable to regularize :type target: Theano variable :param target: Target of x :type axis_sum: Scalar :param axis_sum: Axis along which the penalty terms will be summed (e.g. output units) :type axis_mean: Scalar :param axis_mean: Axis along which the penalty terms will be averaged (e.g. minibatches) :note: no stabilization required """ return T.mean(T.sum((x - target)**2, axis_sum), axis_mean)