comparison nnet_ops.py @ 382:b4efd192d880

Moved xent loss to nnet_ups
author Joseph Turian <turian@gmail.com>
date Tue, 08 Jul 2008 01:58:16 -0400
parents e4473d9697d7
children 344d1f874af7
comparison
equal deleted inserted replaced
381:e4473d9697d7 382:b4efd192d880
377 """ % dict(locals(), **sub) 377 """ % dict(locals(), **sub)
378 378
379 def crossentropy_softmax_1hot(x, y_idx, **kwargs): 379 def crossentropy_softmax_1hot(x, y_idx, **kwargs):
380 b = tensor.zeros_like(x[0,:]) 380 b = tensor.zeros_like(x[0,:])
381 return crossentropy_softmax_1hot_with_bias(x, b, y_idx, **kwargs) 381 return crossentropy_softmax_1hot_with_bias(x, b, y_idx, **kwargs)
382
383 def binary_crossentropy(output, target):
384 """
385 Compute the crossentropy of binary output wrt binary target.
386 @note: We do not sum, crossentropy is computed by component.
387 @todo: Rewrite as a scalar, and then broadcast to tensor.
388 """
389 return -(target * t.log(output) + (1 - target) * t.log(1 - output))