#NEWLINE# def expected_energy( self , V , mf_hidden ) : #NEWLINE# #INDENT# "\n        Compute the energy of current model with the visible samples\n        and variational parameters.\n\n        Parameters\n        ----------\n        V : tensor_like\n            Theano batch of visible unit observations (must be SAMPLES, not\n            mean field parameters: the random variables in the expectation\n            are the hiddens only)\n        mf_hidden : list\n            List, one element per hidden layer, of batches of variational\n            parameters (must be VARIATIONAL PARAMETERS, not samples. Layers\n            with analytically determined variance parameters for their mean\n            field parameters will use those to integrate over the variational\n            distribution, so it's not generally the same thing as measuring\n            the energy at a point.)\n\n        Returns\n        -------\n        rval : tensor_like\n            Vector containing the expected energy of each example under the\n            corresponding variational distribution.\n        " #NEWLINE# self . visible_layer . space . validate ( V ) #NEWLINE# assert isinstance ( mf_hidden , ( list , tuple ) ) #NEWLINE# assert ( len ( mf_hidden ) == len ( self . hidden_layers ) ) #NEWLINE# terms = [ ] #NEWLINE# terms . append ( self . visible_layer . expected_energy_term ( state = V , average = False ) ) #NEWLINE# assert ( len ( self . hidden_layers ) > 0 ) #NEWLINE# terms . append ( self . hidden_layers [ 0 ] . expected_energy_term ( state_below = self . visible_layer . upward_state ( V ) , average_below = False , state = mf_hidden [ 0 ] , average = True ) ) #NEWLINE# for i in xrange ( 1 , len ( self . hidden_layers ) ) : #NEWLINE# #INDENT# layer = self . hidden_layers [ i ] #NEWLINE# layer_below = self . hidden_layers [ ( i - 1 ) ] #NEWLINE# mf_below = mf_hidden [ ( i - 1 ) ] #NEWLINE# mf_below = layer_below . upward_state ( rval ) #NEWLINE# mf = mf_hidden [ i ] #NEWLINE# terms . append ( layer . expected_energy_term ( state_below = mf_below , state = mf , average_below = True , average = True ) ) #NEWLINE# #UNINDENT# assert ( len ( terms ) > 0 ) #NEWLINE# rval = reduce ( operator . add , terms ) #NEWLINE# assert ( rval . ndim == 1 ) #NEWLINE# return rval