Mercurial > pylearn
changeset 1270:d38cb039c662
debugging mcRBM
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Fri, 03 Sep 2010 15:05:31 -0400 |
parents | c24c98da5615 |
children | cc6c6d7234a7 |
files | pylearn/algorithms/mcRBM.py pylearn/sampling/hmc.py |
diffstat | 2 files changed, 13 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/pylearn/algorithms/mcRBM.py Fri Sep 03 12:36:53 2010 -0400 +++ b/pylearn/algorithms/mcRBM.py Fri Sep 03 15:05:31 2010 -0400 @@ -328,16 +328,22 @@ rng = np.random.RandomState(rng) if n_visible is None: n_visible = self.n_visible_units() - rval = HMC_sampler( - positions = [shared( + rval = HMC_sampler.new_from_shared_positions( + shared_positions = shared( rng.randn( n_particles, n_visible).astype(floatX), - name='particles')], + name='particles'), energy_fn=self.free_energy_given_v, seed=int(rng.randint(2**30))) return rval + def as_feedforward_layer(self, v): + return dict( + outputs = self.expected_h_g_given_v(v), + params = [self.U, self.W, self.b, self.c], + ) + @classmethod def alloc(cls, n_I, n_K, n_J, rng = 8923402190): """ @@ -383,13 +389,13 @@ #TODO: write the docstring U_norms = TT.sqrt((new_U**2).sum(axis=0)) new_normVF = .95 * self.normVF + .05 * TT.mean(U_norms) - return new_U * this_normVF / U_norms), new_normVF + return (new_U * this_normVF / U_norms), new_normVF def contrastive_grads(self, visible_batch, params=None): if params is not None: params = self.rbm.params return contrastive_grad( - free_energy_fn=rbm.free_energy_given_v, + free_energy_fn=self.rbm.free_energy_given_v, pos_v=visible_batch, neg_v=self.sampler.positions, params=params,
--- a/pylearn/sampling/hmc.py Fri Sep 03 12:36:53 2010 -0400 +++ b/pylearn/sampling/hmc.py Fri Sep 03 15:05:31 2010 -0400 @@ -30,6 +30,7 @@ """ import sys import logging +import numpy import numpy as np from theano import function, shared from theano import tensor as TT @@ -183,7 +184,7 @@ positions_shape = shared_positions.value.shape batchsize = shared_positions.value.shape[0] - stepsize = shared(initial_stepsize, 'hmc_stepsize') + stepsize = shared(numpy.asarray(initial_stepsize).astype(theano.config.floatX), 'hmc_stepsize') avg_acceptance_rate = shared(target_acceptance_rate, 'avg_acceptance_rate') s_rng = TT.shared_randomstreams.RandomStreams(seed)