def jsDivergence( targetReal, targetInft, predReal, predInft ): m = td.multiply( 0.5, 0.0, *td.add( targetReal, targetInft, predReal, predInft ) ) tpart = td.multiply( targetReal, targetInft, *td.log( *td.divide( targetReal, targetInft, *m ) ) ) ppart = td.multiply( predReal, predInft, *td.log( *td.divide( predReal, predInft, *m ) ) ) return td.multiply( 0.5, 0.0, *td.add( *tpart, *ppart ) )
def crossEntropy( targetReal, targetInft, predReal, predInft ): return td.multiply( *td.neg( targetReal, targetInft ), *td.log( predReal, predInft ) )
def klDivergence( targetReal, targetInft, predReal, predInft ): return td.multiply( targetReal, targetInft, *td.log( *td.divide( targetReal, targetInft, predReal, predInft ) ) )
def softplus(real, inft): return td.log(*td.add(*td.exp(real, inft), 1.0, 0.0))