# HG changeset patch # User James Bergstra # Date 1284587066 14400 # Node ID 1eaa015e88c188a2302a93fa39615151744cb84c # Parent e198515bd4d4fee4324d87f78876e07fa7c4e5ec extended hmc to allow for use as a cd1 sampler diff -r e198515bd4d4 -r 1eaa015e88c1 pylearn/sampling/hmc.py --- a/pylearn/sampling/hmc.py Wed Sep 15 17:43:42 2010 -0400 +++ b/pylearn/sampling/hmc.py Wed Sep 15 17:44:26 2010 -0400 @@ -165,7 +165,9 @@ stepsize_max = 0.25, stepsize_inc = 1.02, avg_acceptance_slowness = 0.9, # used in geometric avg. 1.0 would be not moving at all - seed=12345, dtype=theano.config.floatX): + seed=12345, dtype=theano.config.floatX, + shared_positions_shape=None, + compile_simulate=True): """ :param shared_positions: theano ndarray shared var with many particle [initial] positions :param energy_fn: @@ -178,8 +180,9 @@ """ # allocate shared vars - positions_shape = shared_positions.value.shape - batchsize = shared_positions.value.shape[0] + if shared_positions_shape==None: + shared_positions_shape = shared_positions.value.shape + batchsize = shared_positions_shape[0] stepsize = shared(numpy.asarray(initial_stepsize).astype(theano.config.floatX), 'hmc_stepsize') avg_acceptance_rate = shared(target_acceptance_rate, 'avg_acceptance_rate') @@ -191,7 +194,7 @@ energy_fn, stepsize, n_steps, - positions_shape) + shared_positions_shape) simulate_updates = mcmc_updates( shared_positions, stepsize, @@ -204,7 +207,10 @@ stepsize_dec=stepsize_dec, target_acceptance_rate=target_acceptance_rate, avg_acceptance_slowness=avg_acceptance_slowness) - simulate = function([], [], updates=simulate_updates) + if compile_simulate: + simulate = function([], [], updates=simulate_updates) + else: + simulate = None return cls( positions=shared_positions, stepsize=stepsize,