comparison pylearn/algorithms/mcRBM.py @ 1348:c8c30c675a4f

mcRBM - fixed error in normalization of quadratic term
author James Bergstra <bergstrj@iro.umontreal.ca>
date Thu, 21 Oct 2010 11:43:36 -0400
parents cdda4f98c2a2
children 0d55f8f0aedc
comparison
equal deleted inserted replaced
1347:9e898b2b98e0 1348:c8c30c675a4f
545 - a - the visible bias (theano shared variable) 545 - a - the visible bias (theano shared variable)
546 - b - the covariance bias (theano shared variable) 546 - b - the covariance bias (theano shared variable)
547 - c - the mean bias (theano shared variable) 547 - c - the mean bias (theano shared variable)
548 548
549 """ 549 """
550 def __init__(self, U, W, a, b, c, P): 550 # PCA eigenvectors (E) [scaled by 1/sqrt(eigenvals)] has to be passed to model
551 # because v has to be divided by the number original dimensions
552 # not the number of pca dimensions in hidden_cov_units_preactivation_given_v()
553 def __init__(self, U, W, a, b, c, P, norm_doctoring):
551 self.P = P 554 self.P = P
555 self.norm_doctoring = norm_doctoring
552 super(mcRBM_withP, self).__init__(U,W,a,b,c) 556 super(mcRBM_withP, self).__init__(U,W,a,b,c)
553 557
554 def hidden_cov_units_preactivation_given_v(self, v, small=0.5): 558 def hidden_cov_units_preactivation_given_v(self, v):
555 """Return argument to the sigmoid that would give mean of covariance hid units 559 """Return argument to the sigmoid that would give mean of covariance hid units
556 560
557 See the math at the top of this file for what 'adjusted' means. 561 """
558 562 slope, offset = self.norm_doctoring
559 return b - 0.5 * dot(adjusted(v), U)**2 563 norm_sq = TT.sum(v**2, axis=1) * slope + offset
560 """ 564 unit_v = v / TT.sqrt(norm_sq).dimshuffle(0,'x') # adjust row norm
561 unit_v = v / (TT.sqrt(TT.mean(v**2, axis=1)+small)).dimshuffle(0,'x') # adjust row norm
562 return self.b + 0.5 * dot(dot(unit_v, self.U)**2, self.P) 565 return self.b + 0.5 * dot(dot(unit_v, self.U)**2, self.P)
563 566
564 def n_hidden_cov_units(self): 567 def n_hidden_cov_units(self):
565 """Return the number of hidden units for the covariance in this RBM 568 """Return the number of hidden units for the covariance in this RBM
566 569