#NEWLINE# def get_cost_updates( self , lr = 0.1 , persistent = None , k = 1 ) : #NEWLINE# #INDENT# 'This functions implements one step of CD-k or PCD-k\n\n        :param lr: learning rate used to train the RBM\n\n        :param persistent: None for CD. For PCD, shared variable\n            containing old state of Gibbs chain. This must be a shared\n            variable of size (batch size, number of hidden units).\n\n        :param k: number of Gibbs steps to do in CD-k/PCD-k\n\n        Returns a proxy for the cost and the updates dictionary. The\n        dictionary contains the update rules for weights and biases but\n        also an update of the shared variable used to store the persistent\n        chain, if one is used.\n\n        ' #NEWLINE# ( pre_sigmoid_ph , ph_mean , ph_sample ) = self . sample_h_given_v ( self . input ) #NEWLINE# if ( persistent is None ) : #NEWLINE# #INDENT# chain_start = ph_sample #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# chain_start = persistent #NEWLINE# #UNINDENT# ( [ pre_sigmoid_nvs , nv_means , nv_samples , pre_sigmoid_nhs , nh_means , nh_samples ] , updates ) = theano . scan ( self . gibbs_hvh , outputs_info = [ None , None , None , None , None , chain_start ] , n_steps = k , name = 'gibbs_hvh' ) #NEWLINE# chain_end = nv_samples [ ( - 1 ) ] #NEWLINE# cost = ( T . mean ( self . free_energy ( self . input ) ) - T . mean ( self . free_energy ( chain_end ) ) ) #NEWLINE# gparams = T . grad ( cost , self . params , consider_constant = [ chain_end ] ) #NEWLINE# for ( gparam , param ) in zip ( gparams , self . params ) : #NEWLINE# #INDENT# updates [ param ] = ( param - ( gparam * T . cast ( lr , dtype = theano . config . floatX ) ) ) #NEWLINE# #UNINDENT# if persistent : #NEWLINE# #INDENT# updates [ persistent ] = nh_samples [ ( - 1 ) ] #NEWLINE# monitoring_cost = self . get_pseudo_likelihood_cost ( updates ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# monitoring_cost = self . get_reconstruction_cost ( updates , pre_sigmoid_nvs [ ( - 1 ) ] ) #NEWLINE# #UNINDENT# return ( monitoring_cost , updates )