changeset 1122:be53f56b37b8

Added example cost formula with tags and created a formulas page in the doc
author boulanni <nicolas_boulanger@hotmail.com>
date Tue, 14 Sep 2010 23:24:59 -0400
parents 1f5465622394
children 1a1c0c3adcca
files doc/formulas.txt doc/index.txt pylearn/formulas/costs.py pylearn/formulas/noise.py
diffstat 4 files changed, 40 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/formulas.txt	Tue Sep 14 23:24:59 2010 -0400
@@ -0,0 +1,14 @@
+
+.. contents:: Formulas categories
+
+pylearn.formulas.costs
+-----------------------
+.. automodule:: pylearn.formulas.costs
+    :members:
+
+pylearn.formulas.noise
+-----------------------
+.. automodule:: pylearn.formulas.noise
+    :members:
+ 
+
--- a/doc/index.txt	Tue Sep 14 23:14:00 2010 -0400
+++ b/doc/index.txt	Tue Sep 14 23:24:59 2010 -0400
@@ -24,6 +24,7 @@
 
 For the moment, the following documentation is available.
 
+* `Formulas <formulas.html>`_ -- Built-in math formulas optimized for speed and robustness
 * :doc:`io.SeriesTables module <seriestables>` -- Saves error series and other statistics during training
 * `API <api/>`_ -- The automatically-generated API documentation
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pylearn/formulas/costs.py	Tue Sep 14 23:24:59 2010 -0400
@@ -0,0 +1,22 @@
+"""
+This script defines a few often used cost functions.
+"""
+import theano
+import theano.tensor as T
+from tags import tags
+
+@tags('cost','binary','cross-entropy')
+def binary_crossentropy(output, target):
+    """ Compute the crossentropy of binary output wrt binary target.
+
+    .. math::
+                L_{CE} \equiv t\log(o) + (1-t)\log(1-o) 
+
+    :type output: Theano variable
+    :param output: Binary output or prediction :math:`\in[0,1]`
+    :type target: Theano variable
+    :param target: Binary target usually :math:`\in\{0,1\}`
+    """
+    return -(target * tensor.log(output) + (1.0 - target) * tensor.log(1.0 - output))
+
+
--- a/pylearn/formulas/noise.py	Tue Sep 14 23:14:00 2010 -0400
+++ b/pylearn/formulas/noise.py	Tue Sep 14 23:24:59 2010 -0400
@@ -1,14 +1,13 @@
 """
 
-This script define the different symbolic noise functions
-The noise contract is simple: noise_lvl is a symbolic variable going from 0 to 1
+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
 import theano.tensor as T
-import tags
+from tags import tags
 s="""
 * A latex mathematical description of the formulas(for picture representation in generated documentation)
 * Tags(for searching):