提交 cd2eb03f authored 作者: Ian Goodfellow's avatar Ian Goodfellow

improved doc of tensor.nnet.binary_crossentropy

上级 99f22814
...@@ -1410,11 +1410,14 @@ def graph_merge_softmax_with_crossentropy_softmax(node): ...@@ -1410,11 +1410,14 @@ def graph_merge_softmax_with_crossentropy_softmax(node):
def binary_crossentropy(output, target): def binary_crossentropy(output, target):
""" """
Compute the crossentropy of binary output wrt binary target. Compute the crossentropy of binary random variables
output and target are each expectations of binary random
variables; target may be exactly 0 or 1 but output must
lie strictly between 0 and 1.
@note: we could use the x log y op to support output=0
@ and output=1. The gradient would still be undefined though.
@note: We do not sum, crossentropy is computed by component. @note: We do not sum, crossentropy is computed by component.
@todo: Rewrite as a scalar, and then broadcast to tensor. @todo: Rewrite as a scalar, and then broadcast to tensor.
@todo: This is essentially duplicated as cost.cross_entropy
@warning: OUTPUT and TARGET are reversed in cost.cross_entropy
""" """
return -(target * tensor.log(output) + (1.0 - target) * tensor.log(1.0 - output)) return -(target * tensor.log(output) + (1.0 - target) * tensor.log(1.0 - output))
......
...@@ -13,8 +13,8 @@ from theano.tests import unittest_tools ...@@ -13,8 +13,8 @@ from theano.tests import unittest_tools
def cross_entropy(target, output, axis=1): def cross_entropy(target, output, axis=1):
""" """
@todo: This is essentially duplicated as nnet_ops.binary_crossentropy @todo: This is essentially duplicated as tensor.nnet.binary_crossentropy
@warning: OUTPUT and TARGET are reversed in nnet_ops.binary_crossentropy @warning: OUTPUT and TARGET are reversed in tensor.nnet.binary_crossentropy
""" """
return -T.mean(target * T.log(output) + (1 - target) * T.log(1 - output), axis=axis) return -T.mean(target * T.log(output) + (1 - target) * T.log(1 - output), axis=axis)
def quadratic(target, output, axis=1): def quadratic(target, output, axis=1):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论