annotate cost.py @ 430:c096e2820131

merge
author Yoshua Bengio <bengioy@iro.umontreal.ca>
date Tue, 29 Jul 2008 09:36:09 -0400
parents 319bf28c2dd5
children 0f366ecb11ee
rev   line source
413
f63dfb0ac7dc Added cost functions
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
1 """
f63dfb0ac7dc Added cost functions
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
2 Cost functions.
f63dfb0ac7dc Added cost functions
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
3 """
f63dfb0ac7dc Added cost functions
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
4
415
319bf28c2dd5 Small bugfix
Joseph Turian <turian@iro.umontreal.ca>
parents: 413
diff changeset
5 import theano.tensor as T
319bf28c2dd5 Small bugfix
Joseph Turian <turian@iro.umontreal.ca>
parents: 413
diff changeset
6
413
f63dfb0ac7dc Added cost functions
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
7 def quadratic(target, output, axis=1):
f63dfb0ac7dc Added cost functions
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
8 return T.mean(T.sqr(target - output), axis)
f63dfb0ac7dc Added cost functions
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
9
f63dfb0ac7dc Added cost functions
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
10 def cross_entropy(target, output, axis=1):
f63dfb0ac7dc Added cost functions
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
11 return -T.mean(target * T.log2(output) + (1 - target) * T.log2(1 - output), axis=axis)