#NEWLINE# def energy( self , V , hidden ) : #NEWLINE# #INDENT# "\n        Compute the energy of current model with visible and hidden samples.\n\n        Parameters\n        ----------\n        V : tensor_like\n            Theano batch of visible unit observations (must be SAMPLES, not\n            mean field parameters)\n        hidden : list\n            List, one element per hidden layer, of batches of samples (must\n            be SAMPLES, not mean field parameters)\n\n        Returns\n        -------\n        rval : tensor_like\n            Vector containing the energy of each sample\n\n        Notes\n        -----\n        Applying this function to non-sample theano variables is not guaranteed\n        to give you an expected energy in general, so don't use this that way.\n        " #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 ) , state = hidden [ 0 ] , average_below = False , average = False ) ) #NEWLINE# for i in xrange ( 1 , len ( self . hidden_layers ) ) : #NEWLINE# #INDENT# layer = self . hidden_layers [ i ] #NEWLINE# samples_below = hidden [ ( i - 1 ) ] #NEWLINE# layer_below = self . hidden_layers [ ( i - 1 ) ] #NEWLINE# samples_below = layer_below . upward_state ( samples_below ) #NEWLINE# samples = hidden [ i ] #NEWLINE# terms . append ( layer . expected_energy_term ( state_below = samples_below , state = samples , average_below = False , average = False ) ) #NEWLINE# #UNINDENT# assert ( len ( terms ) > 0 ) #NEWLINE# rval = reduce ( operator . add , terms ) #NEWLINE# assert ( rval . ndim == 1 ) #NEWLINE# return rval