MCPcopy Index your code
hub / github.com/lisa-lab/DeepLearningTutorials / get_cost_updates

Method get_cost_updates

code/rbm.py:209–291  ·  view source on GitHub ↗

This functions implements one step of CD-k or PCD-k :param lr: learning rate used to train the RBM :param persistent: None for CD. For PCD, shared variable containing old state of Gibbs chain. This must be a shared variable of size (batch size, number of hid

(self, lr=0.1, persistent=None, k=1)

Source from the content-addressed store, hash-verified

207
208 # start-snippet-2
209 def get_cost_updates(self, lr=0.1, persistent=None, k=1):
210 """This functions implements one step of CD-k or PCD-k
211
212 :param lr: learning rate used to train the RBM
213
214 :param persistent: None for CD. For PCD, shared variable
215 containing old state of Gibbs chain. This must be a shared
216 variable of size (batch size, number of hidden units).
217
218 :param k: number of Gibbs steps to do in CD-k/PCD-k
219
220 Returns a proxy for the cost and the updates dictionary. The
221 dictionary contains the update rules for weights and biases but
222 also an update of the shared variable used to store the persistent
223 chain, if one is used.
224
225 """
226
227 # compute positive phase
228 pre_sigmoid_ph, ph_mean, ph_sample = self.sample_h_given_v(self.input)
229
230 # decide how to initialize persistent chain:
231 # for CD, we use the newly generate hidden sample
232 # for PCD, we initialize from the old state of the chain
233 if persistent is None:
234 chain_start = ph_sample
235 else:
236 chain_start = persistent
237 # end-snippet-2
238 # perform actual negative phase
239 # in order to implement CD-k/PCD-k we need to scan over the
240 # function that implements one gibbs step k times.
241 # Read Theano tutorial on scan for more information :
242 # http://deeplearning.net/software/theano/library/scan.html
243 # the scan will return the entire Gibbs chain
244 (
245 [
246 pre_sigmoid_nvs,
247 nv_means,
248 nv_samples,
249 pre_sigmoid_nhs,
250 nh_means,
251 nh_samples
252 ],
253 updates
254 ) = theano.scan(
255 self.gibbs_hvh,
256 # the None are place holders, saying that
257 # chain_start is the initial state corresponding to the
258 # 6th output
259 outputs_info=[None, None, None, None, None, chain_start],
260 n_steps=k,
261 name="gibbs_hvh"
262 )
263 # start-snippet-3
264 # determine gradients on RBM parameters
265 # note that we only need the sample at the end of the chain
266 chain_end = nv_samples[-1]

Callers 1

test_rbmFunction · 0.95

Calls 4

sample_h_given_vMethod · 0.95
free_energyMethod · 0.95

Tested by 1

test_rbmFunction · 0.76