def theano_parzen(mu, sigma):
 x = T.matrix()
 mu = theano.shared(mu)
 a = ((x.dimshuffle(0, 'x', 1) - mu.dimshuffle('x', 0, 1)) / sigma)
 E = log_mean_exp(((-0.5) * (a ** 2).sum(2)))
 Z = (mu.shape[1] * T.log((sigma * numpy.sqrt((numpy.pi * 2)))))
 return theano.function([x], (E - Z))

def theano_parzen ( mu , sigma ) : x = T . matrix ( ) mu = theano . shared ( mu ) a = ( ( x . dimshuffle ( 0 , 'x' , 1 ) - mu . dimshuffle ( 'x' , 0 , 1 ) ) / sigma ) E = log_mean_exp ( ( ( - 0.5 ) * ( a ** 2 ) . sum ( 2 ) ) ) Z = ( mu . shape [ 1 ] * T . log ( ( sigma * numpy . sqrt ( ( numpy . pi * 2 ) ) ) ) ) return theano . function ( [ x ] , ( E - Z ) )
credit: yann n .