comparison pylearn/sampling/hmc.py @ 1501:55534951dd91

Clean up import and remove deprecation warning.
author Frederic Bastien <nouiz@nouiz.org>
date Fri, 09 Sep 2011 10:53:46 -0400
parents fbe470217937
children 4fa5ebe8a7ad
comparison
equal deleted inserted replaced
1500:517f4c02dde9 1501:55534951dd91
26 Metropolis-Hastings accept/reject for each particle in the simulation by consulting the 26 Metropolis-Hastings accept/reject for each particle in the simulation by consulting the
27 self.initial_hamiltonian storing the result to self. 27 self.initial_hamiltonian storing the result to self.
28 28
29 29
30 """ 30 """
31 import sys
32 import logging
33 import numpy 31 import numpy
34 import numpy as np
35 from theano import function, shared 32 from theano import function, shared
36 from theano import tensor as TT 33 from theano import tensor as TT
37 import theano 34 import theano
38 from theano.printing import Print 35 from theano.printing import Print
39 36
122 119
123 p_full_step = initial_p + stepsize * v_half_step 120 p_full_step = initial_p + stepsize * v_half_step
124 121
125 # perform leapfrog updates: the scan op is used to repeatedly compute pos(t_1 + n*sigma) and 122 # perform leapfrog updates: the scan op is used to repeatedly compute pos(t_1 + n*sigma) and
126 # vel(t_1 + n*sigma + 1/2) for n in [0,n_steps-2]. 123 # vel(t_1 + n*sigma + 1/2) for n in [0,n_steps-2].
127 (final_p, final_v), scan_updates = theano.scan(leapfrog, 124 (all_p, all_v), scan_updates = theano.scan(leapfrog,
128 outputs_info=[ 125 outputs_info=[
129 dict(initial=p_full_step, return_steps=1), 126 dict(initial=p_full_step),
130 dict(initial=v_half_step, return_steps=1), 127 dict(initial=v_half_step),
131 ], 128 ],
132 non_sequences=[stepsize], 129 non_sequences=[stepsize],
133 n_steps=n_steps-1) 130 n_steps=n_steps-1)
131
132 final_p = all_p[-1]
133 final_v = all_v[-1]
134 134
135 # NOTE: Scan always returns an updates dictionary, in case the scanned function draws 135 # NOTE: Scan always returns an updates dictionary, in case the scanned function draws
136 # samples from a RandomStream. These updates must then be used when compiling the Theano 136 # samples from a RandomStream. These updates must then be used when compiling the Theano
137 # function, to avoid drawing the same random numbers each time the function is called. In 137 # function, to avoid drawing the same random numbers each time the function is called. In
138 # this case however, we consciously ignore "scan_updates" because we know it is empty. 138 # this case however, we consciously ignore "scan_updates" because we know it is empty.