def hmc_updates(positions, stepsize, avg_acceptance_rate, final_pos, accept, target_acceptance_rate, stepsize_inc, stepsize_dec, stepsize_min, stepsize_max, avg_acceptance_slowness):
 accept_matrix = accept.dimshuffle(0, *(('x',) * (final_pos.ndim - 1)))
 new_positions = TT.switch(accept_matrix, final_pos, positions)
 _new_stepsize = TT.switch((avg_acceptance_rate > target_acceptance_rate), (stepsize * stepsize_inc), (stepsize * stepsize_dec))
 new_stepsize = TT.clip(_new_stepsize, stepsize_min, stepsize_max)
 mean_dtype = theano.scalar.upcast(accept.dtype, avg_acceptance_rate.dtype)
 new_acceptance_rate = TT.add((avg_acceptance_slowness * avg_acceptance_rate), ((1.0 - avg_acceptance_slowness) * accept.mean(dtype=mean_dtype)))
 return [(positions, new_positions), (stepsize, new_stepsize), (avg_acceptance_rate, new_acceptance_rate)]

def hmc_updates ( positions , stepsize , avg_acceptance_rate , final_pos , accept , target_acceptance_rate , stepsize_inc , stepsize_dec , stepsize_min , stepsize_max , avg_acceptance_slowness ) : accept_matrix = accept . dimshuffle ( 0 , * ( ( 'x' , ) * ( final_pos . ndim - 1 ) ) ) new_positions = TT . switch ( accept_matrix , final_pos , positions ) _new_stepsize = TT . switch ( ( avg_acceptance_rate > target_acceptance_rate ) , ( stepsize * stepsize_inc ) , ( stepsize * stepsize_dec ) ) new_stepsize = TT . clip ( _new_stepsize , stepsize_min , stepsize_max ) mean_dtype = theano . scalar . upcast ( accept . dtype , avg_acceptance_rate . dtype ) new_acceptance_rate = TT . add ( ( avg_acceptance_slowness * avg_acceptance_rate ) , ( ( 1.0 - avg_acceptance_slowness ) * accept . mean ( dtype = mean_dtype ) ) ) return [ ( positions , new_positions ) , ( stepsize , new_stepsize ) , ( avg_acceptance_rate , new_acceptance_rate ) ]
this function is executed after n_steps of hmc sampling .