(target: Tensor, output: Tensor)
| 313 | |
| 314 | describeMathCPUAndGPU('binaryCrossentropy', () => { |
| 315 | function _binaryCrossentropy(target: Tensor, output: Tensor): Tensor { |
| 316 | const targetComplement = tfc.add(scalar(1), tfc.neg(target)); |
| 317 | const outputComplement = tfc.add(scalar(1), tfc.neg(output)); |
| 318 | return tfc.mean( |
| 319 | tfc.neg(tfc.add( |
| 320 | tfc.mul(target, tfc.log(output)), |
| 321 | tfc.mul(targetComplement, tfc.log(outputComplement)))), |
| 322 | -1); |
| 323 | } |
| 324 | |
| 325 | it('from sigmoid', () => { |
| 326 | const x = tensor2d([[0.3, 0.7], [0.4, 0.6]], [2, 2]); |