flow_field

class rnntoolkit.flow_fields.flow_field.FlowField(x_vels: Tensor, y_vels: Tensor, grid: Tensor, speeds: Tensor)[source]

Bases: object

flow_field_finder_base

class rnntoolkit.flow_fields.flow_field_finder_base.FlowFieldFinderBase(rnn: RNN, fit_states: Tensor, num_points: int, x_offset: int, y_offset: int, x_center: int = 0, y_center: int = 0, **kwargs)[source]

Bases: Generic[RNN]

find_linear_flow(*args, **kwargs) list[source]

Compute linearized flow fields in a 2D subspace.

find_nonlinear_flow(*args, **kwargs) list[source]

Compute 2D flow fields in a region subspace along a trajectory.

flow_field_finder

class rnntoolkit.flow_fields.flow_field_finder.FlowFieldFinder(rnn: RNN, fit_states: Tensor, num_points: int, x_offset: int, y_offset: int, x_center: int = 0, y_center: int = 0, follow_traj: bool = False)[source]

Bases: FlowFieldFinderBase

find_linear_flow(states: Tensor, inp: Tensor, delta_inp: Tensor) list[source]

Compute linearized flow fields in a 2D subspace.

Similar to flow_field(), but uses a local linear approximation (Jacobian) of the dynamics around points on the trajectory instead of a full forward step.

Args:
states (torch.Tensor): Hidden activations over time for selected regions,

can be 1D or batched

inp (torch.Tensor): External input sequence, can be batched or 1D, but

the total number of inputs (batch elements) must match that of states

delta_inp (torch.Tensor): External input sequence of input perturbations,

can be batched or 1D, but the total number of inputs (batch elements) must match that of states, and the overall shape must match inp

Returns:

list: FlowField objects per sampled time.

find_nonlinear_flow(states: Tensor, inp: Tensor) list[source]

Compute 2D flow fields at each given state

Projects selected region activity onto a 2D PCA subspace, constructs a grid around the current point, and advances the system by one step to estimate the local flow (velocity vectors).

Args:

states (torch.Tensor): Hidden activations over time, can be batched or 1D inp (torch.Tensor): External input sequence, can be batched or 1D, but

the total number of inputs (batch elements) must match that of states

Returns:

list: FlowField object per sampled state