# HG changeset patch # User James Bergstra # Date 1283540731 14400 # Node ID d38cb039c6629d5881c3366232fdc7fe286b3319 # Parent c24c98da5615b2c150f4628117ffa2ae66e62534 debugging mcRBM diff -r c24c98da5615 -r d38cb039c662 pylearn/algorithms/mcRBM.py --- 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, diff -r c24c98da5615 -r d38cb039c662 pylearn/sampling/hmc.py --- 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)