comparison pylearn/algorithms/mcRBM.py @ 989:9e753ddcc320

mcRBM - cleaned up the preactivation function
author James Bergstra <bergstrj@iro.umontreal.ca>
date Tue, 24 Aug 2010 14:03:07 -0400
parents fd243cb2bf0b
children e70e74464170
comparison
equal deleted inserted replaced
988:fd243cb2bf0b 989:9e753ddcc320
243 if 'float' in str(x.dtype): 243 if 'float' in str(x.dtype):
244 return shared(x.astype(floatX), name=name) 244 return shared(x.astype(floatX), name=name)
245 else: 245 else:
246 return shared(x, name=name) 246 return shared(x, name=name)
247 247
248 def hidden_cov_units_preactivation_given_v(rbm, v, small=1e-8): 248 def hidden_cov_units_preactivation_given_v(rbm, v, small=0.5):
249 """Return argument to the sigmoid that would give mean of covariance hid units
250
251 See the math at the top of this file for what 'adjusted' means.
252
253 return b - 0.5 * dot(adjusted(v), U)**2
254 """
249 (U,W,a,b,c) = rbm 255 (U,W,a,b,c) = rbm
250 unit_v = v / (TT.sqrt(TT.sum(v**2, axis=1))+small).dimshuffle(0,'x') # unit rows 256 unit_v = v / (TT.sqrt(TT.mean(v**2, axis=1)+small)).dimshuffle(0,'x') # adjust row norm
251 unit_U = U # assuming unit cols! 257 return b - 0.5 * dot(unit_v, U)**2
252 #unit_U = U / (TT.sqrt(TT.sum(U**2, axis=0))+small) #unit cols
253 return b - 0.5 * dot(unit_v, unit_U)**2
254 258
255 def free_energy_given_v(rbm, v): 259 def free_energy_given_v(rbm, v):
256 """Returns theano expression for free energy of visible vector `v` in an mcRBM 260 """Returns theano expression for free energy of visible vector `v` in an mcRBM
257 261
258 An mcRBM is parametrized 262 An mcRBM is parametrized