TaylorTrajectoryN#
- class TaylorTrajectoryN(order, time_grid, particle_trajectories, batch_size=None, fit_on_init=True)[source]#
Fits a taylor Polynomial of specified order to the given 3D particle trajectories and stores the resulting coefficients per particle. When called, evaluates the Taylor-expansion at given timing in a tf.function compatible definition.
Incrementing particle positions is done by keeping track of the current timing. Batching the particles for all evaluations is done by setting the attributes self.batch_size and self.current_batch_idx. This results in the indexing: [self.batch_size*self.current_batch_idx : self.batch_size*self.current_batch_idx+1]
Example Usage
Instantiation#ref_timing = ... # shape (T, ) ref_trajectory = ... # shape (N, T, dims) module = TaylorTrajectoryN(order=3, time_grid=ref_timing, particle_trajectories=ref_trajectory)
- Parameters:
order (
int
) – Order of the fitted TaylorPolynomialtime_grid (
ndarray
) – (#timesteps, )particle_trajectories (
ndarray
) – (#particles, #timesteps, 3)batch_size (
Optional
[int
]) – used for evaluating the particle trajectories in batchesfit_on_init (
bool
) – If True, the Polynomial is fitted on instantiation of the module.
Methods:
__call__
(timing, **kwargs)Evaluates the taylor expansion for the current batch of particles at the specified times t.
fit
(t_grid, particle_trajectories)Fits a Taylor polynomial of order self.order to each particle trajectory.
increment_particles
(r, dt, **kwargs)Evaluates the particle position for the time self.current_time_ms + dt and adds the delta t to the current_time_ms variable
Attributes:
Together with self.current_batch_size determines the subset of particle trajectories that is evaluated on call and increment_particles
Allows to only evaluate the position for a batch of stored particle trajectories
Keeps track of the current timing when increment_particles is called.
Stores the result of fitting the TaylorPolynomial for all particle trajectories
Stores the order of the TaylorPolynomial, defined on instantiation
- __call__(timing, **kwargs)[source]#
Evaluates the taylor expansion for the current batch of particles at the specified times t.
- Parameters:
timing (
Tensor
) – (#timesteps) in milliseconds- Return type:
(
Tensor
,dict
)- Returns:
(#particles, #timesteps, 3) in meter
- fit(t_grid, particle_trajectories)[source]#
Fits a Taylor polynomial of order self.order to each particle trajectory.
- increment_particles(r: ~tensorflow.python.framework.ops.Tensor, dt: ~tensorflow.python.framework.ops.Tensor, **kwargs) -> (<class 'tensorflow.python.framework.ops.Tensor'>, <class 'dict'>)[source]#
Evaluates the particle position for the time self.current_time_ms + dt and adds the delta t to the current_time_ms variable
- Parameters:
r (
Tensor
) – unused parameter (to adhere to calling signature of trajectory modules)dt (
Tensor
) – temporal step lengthskwargs – unused parameter (to adhere to calling signature of trajectory modules)
- Return type:
(
Tensor
,dict
)- Returns:
(#batch, 3)
- batch_size: Variable#
Together with self.current_batch_size determines the subset of particle trajectories that is evaluated on call and increment_particles
- current_batch_idx: Variable#
Allows to only evaluate the position for a batch of stored particle trajectories
- current_time_ms: Variable#
Keeps track of the current timing when increment_particles is called.
- optimal_parameters: Variable#
Stores the result of fitting the TaylorPolynomial for all particle trajectories
- order: Variable#
Stores the order of the TaylorPolynomial, defined on instantiation