annotate cost.py @ 413:f63dfb0ac7dc

Added cost functions
author Joseph Turian <turian@iro.umontreal.ca>
date Fri, 11 Jul 2008 15:26:41 -0400
parents
children 319bf28c2dd5
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
f63dfb0ac7dc Added cost functions
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
5 def quadratic(target, output, axis=1):
f63dfb0ac7dc Added cost functions
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
6 return T.mean(T.sqr(target - output), axis)
f63dfb0ac7dc Added cost functions
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
7
f63dfb0ac7dc Added cost functions
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
8 def cross_entropy(target, output, axis=1):
f63dfb0ac7dc Added cost functions
Joseph Turian <turian@iro.umontreal.ca>
parents:
diff changeset
9 return -T.mean(target * T.log2(output) + (1 - target) * T.log2(1 - output), axis=axis)