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

Method get_pseudo_likelihood_cost

code/rbm.py:293–320  ·  view source on GitHub ↗

Stochastic approximation to the pseudo-likelihood

(self, updates)

Source from the content-addressed store, hash-verified

291 # end-snippet-4
292
293 def get_pseudo_likelihood_cost(self, updates):
294 """Stochastic approximation to the pseudo-likelihood"""
295
296 # index of bit i in expression p(x_i | x_{\i})
297 bit_i_idx = theano.shared(value=0, name='bit_i_idx')
298
299 # binarize the input image by rounding to nearest integer
300 xi = T.round(self.input)
301
302 # calculate free energy for the given bit configuration
303 fe_xi = self.free_energy(xi)
304
305 # flip bit x_i of matrix xi and preserve all other bits x_{\i}
306 # Equivalent to xi[:,bit_i_idx] = 1-xi[:, bit_i_idx], but assigns
307 # the result to xi_flip, instead of working in place on xi.
308 xi_flip = T.set_subtensor(xi[:, bit_i_idx], 1 - xi[:, bit_i_idx])
309
310 # calculate free energy with bit flipped
311 fe_xi_flip = self.free_energy(xi_flip)
312
313 # equivalent to e^(-FE(x_i)) / (e^(-FE(x_i)) + e^(-FE(x_{\i})))
314 cost = T.mean(self.n_visible * T.log(T.nnet.sigmoid(fe_xi_flip -
315 fe_xi)))
316
317 # increment bit_i_idx % number as part of updates
318 updates[bit_i_idx] = (bit_i_idx + 1) % self.n_visible
319
320 return cost
321
322 def get_reconstruction_cost(self, updates, pre_sigmoid_nv):
323 """Approximation to the reconstruction error

Callers 1

get_cost_updatesMethod · 0.95

Calls 1

free_energyMethod · 0.95

Tested by

no test coverage detected