def triangle_code(X, centroids):
 X_sqr = T.sqr(X).sum(axis=1).dimshuffle(0, 'x')
 c_sqr = T.sqr(centroids).sum(axis=1).dimshuffle('x', 0)
 c_sqr.name = 'c_sqr'
 Xc = T.dot(X, centroids.T)
 Xc.name = 'Xc'
 sq_dists = ((c_sqr + X_sqr) - (2.0 * Xc))
 sq_dists_safe = T.clip(sq_dists, 0.0, 1e+30)
 Z = T.sqrt(sq_dists_safe)
 Z.name = 'Z'
 mu = Z.mean(axis=1)
 mu.name = 'mu'
 mu = mu.dimshuffle(0, 'x')
 mu.name = 'mu_broadcasted'
 rval = T.clip((mu - Z), 0.0, 1e+30)
 rval.name = 'triangle_code'
 return rval

def triangle_code ( X , centroids ) : X_sqr = T . sqr ( X ) . sum ( axis = 1 ) . dimshuffle ( 0 , 'x' ) c_sqr = T . sqr ( centroids ) . sum ( axis = 1 ) . dimshuffle ( 'x' , 0 ) c_sqr . name = 'c_sqr' Xc = T . dot ( X , centroids . T ) Xc . name = 'Xc' sq_dists = ( ( c_sqr + X_sqr ) - ( 2.0 * Xc ) ) sq_dists_safe = T . clip ( sq_dists , 0.0 , 1e+30 ) Z = T . sqrt ( sq_dists_safe ) Z . name = 'Z' mu = Z . mean ( axis = 1 ) mu . name = 'mu' mu = mu . dimshuffle ( 0 , 'x' ) mu . name = 'mu_broadcasted' rval = T . clip ( ( mu - Z ) , 0.0 , 1e+30 ) rval . name = 'triangle_code' return rval
compute the triangle activation function used in adam coates aistats 2011 paper .