def _HamiltonianShootingCarrying(self, q, p, i0) :
"""
Given initial control points/momentums q0 and p0 given as n-by-d matrices,
and a "template" image i0, outputs the trajectories q_t, p_t, I_t = I0 \circ phi_{t->0}.
"""
# Here, we use the "scan" theano routine, which can be understood as a "for" loop
identity = T.as_tensor_variable(0. * self.dense_grid()) # We encode the identity as a null displacement field.
# Here, we use the "scan" theano routine, which can be understood as a "for" loop
result, updates = theano.scan(fn = lambda x,y,z : self._hamiltonian_step_carrying2(x,y,z),
outputs_info = [q,p, identity],
n_steps = int(np.round(1/self.dt) ))
phi_inv_1 = result[2][-1] # We do not store the intermediate results
I1 = self._image_circ_diffeo(i0, self.dense_grid() + phi_inv_1) # instead of interpolating the images It at all timesteps, we only do it in the end.
return [result[0][-1], result[1][-1], I1] # and only return the final state + momentum + image
评论列表
文章目录