changeset 1381:0673e6af650a

Added regularization terms
author boulanni <nicolas_boulanger@hotmail.com>
date Mon, 06 Dec 2010 13:33:07 -0500
parents 785aeb7a4df2
children 00116be92710
files doc/formulas.txt pylearn/formulas/regularization.py
diffstat 2 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/doc/formulas.txt	Fri Dec 03 09:09:00 2010 -0500
+++ b/doc/formulas.txt	Mon Dec 06 13:33:07 2010 -0500
@@ -20,4 +20,8 @@
 .. automodule:: pylearn.formulas.noise
     :members:
  
+pylearn.formulas.regularization
+----------------------
+.. automodule:: pylearn.formulas.regularization
+    :members:
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pylearn/formulas/regularization.py	Mon Dec 06 13:33:07 2010 -0500
@@ -0,0 +1,49 @@
+
+"""
+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)
+