Mercurial > pylearn
comparison pylearn/algorithms/mcRBM.py @ 1270:d38cb039c662
debugging mcRBM
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Fri, 03 Sep 2010 15:05:31 -0400 |
parents | 075c193afd1b |
children | ba25c6e4f55d |
comparison
equal
deleted
inserted
replaced
1269:c24c98da5615 | 1270:d38cb039c662 |
---|---|
326 """ | 326 """ |
327 if not hasattr(rng, 'randn'): | 327 if not hasattr(rng, 'randn'): |
328 rng = np.random.RandomState(rng) | 328 rng = np.random.RandomState(rng) |
329 if n_visible is None: | 329 if n_visible is None: |
330 n_visible = self.n_visible_units() | 330 n_visible = self.n_visible_units() |
331 rval = HMC_sampler( | 331 rval = HMC_sampler.new_from_shared_positions( |
332 positions = [shared( | 332 shared_positions = shared( |
333 rng.randn( | 333 rng.randn( |
334 n_particles, | 334 n_particles, |
335 n_visible).astype(floatX), | 335 n_visible).astype(floatX), |
336 name='particles')], | 336 name='particles'), |
337 energy_fn=self.free_energy_given_v, | 337 energy_fn=self.free_energy_given_v, |
338 seed=int(rng.randint(2**30))) | 338 seed=int(rng.randint(2**30))) |
339 return rval | 339 return rval |
340 | |
341 def as_feedforward_layer(self, v): | |
342 return dict( | |
343 outputs = self.expected_h_g_given_v(v), | |
344 params = [self.U, self.W, self.b, self.c], | |
345 ) | |
340 | 346 |
341 @classmethod | 347 @classmethod |
342 def alloc(cls, n_I, n_K, n_J, rng = 8923402190): | 348 def alloc(cls, n_I, n_K, n_J, rng = 8923402190): |
343 """ | 349 """ |
344 Return a MeanCovRBM instance with randomly-initialized parameters. | 350 Return a MeanCovRBM instance with randomly-initialized parameters. |
381 | 387 |
382 def normalize_U(self, new_U): | 388 def normalize_U(self, new_U): |
383 #TODO: write the docstring | 389 #TODO: write the docstring |
384 U_norms = TT.sqrt((new_U**2).sum(axis=0)) | 390 U_norms = TT.sqrt((new_U**2).sum(axis=0)) |
385 new_normVF = .95 * self.normVF + .05 * TT.mean(U_norms) | 391 new_normVF = .95 * self.normVF + .05 * TT.mean(U_norms) |
386 return new_U * this_normVF / U_norms), new_normVF | 392 return (new_U * this_normVF / U_norms), new_normVF |
387 | 393 |
388 def contrastive_grads(self, visible_batch, params=None): | 394 def contrastive_grads(self, visible_batch, params=None): |
389 if params is not None: | 395 if params is not None: |
390 params = self.rbm.params | 396 params = self.rbm.params |
391 return contrastive_grad( | 397 return contrastive_grad( |
392 free_energy_fn=rbm.free_energy_given_v, | 398 free_energy_fn=self.rbm.free_energy_given_v, |
393 pos_v=visible_batch, | 399 pos_v=visible_batch, |
394 neg_v=self.sampler.positions, | 400 neg_v=self.sampler.positions, |
395 params=params, | 401 params=params, |
396 other_cost=(l1(self.rbm.U)+l1(self.rbm.W)) * self.l1_penalty) | 402 other_cost=(l1(self.rbm.U)+l1(self.rbm.W)) * self.l1_penalty) |
397 | 403 |