elman_flow_field_finder

class mrnntorch.analysis.flow_fields.elman_flow_field_finder.emFlowFieldFinder(rnn: ElmanmRNN, fit_states: Tensor, num_points: int, x_offset: int, y_offset: int, x_center: int = 0, y_center: int = 0, follow_traj: bool = False, region_list: list = [], cancel_other_regions: bool = False)[source]

Bases: FlowFieldFinderBase[ElmanmRNN]

Flow-field estimator for Elman mRNN trajectories and local linearizations.

find_linear_flow(states: Tensor, input: Tensor, delta_input: Tensor, delta_h_static: Tensor | None = None) list[source]

Compute linearized 2D flow fields around sampled trajectory states.

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. Assumes no external input to the selected regions.

Args:

states (torch.Tensor): Hidden activations over time. inp (torch.Tensor): External input sequence aligned with states. delta_inp (torch.Tensor): Input perturbations for the local linear model. delta_h_static (torch.Tensor | None): Perturbations for recurrent regions

excluded from the reduced plane.

Returns:

list: FlowField objects per sampled time.

find_nonlinear_flow(states: Tensor, input: Tensor, stim_input: Tensor | None = None, W: Tensor | None = None) list[source]

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

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). Can zero out non-selected regions or keep their control values.

Args:

states (torch.Tensor): Hidden activations over time [batch_size, T, N]. inp (torch.Tensor): External input sequence. stim_input (torch.Tensor | None): Optional additive stimulus input. W (torch.Tensor | None): Optional weight matrix to use.

Kwargs:

stim_input (torch.Tensor): tensor input to network without weights, acts as manipulation W (torch.Tensor): replace the weight matrix of mRNN with W traj_to_reduce (torch.Tensor): tensor similar to states that will be used for PCA instead of states

Returns:

list: FlowField object per sampled time.

leaky_flow_field_finder

class mrnntorch.analysis.flow_fields.leaky_flow_field_finder.mFlowFieldFinder(rnn: mRNN, fit_states: Tensor, num_points: int, x_offset: int, y_offset: int, x_center: int = 0, y_center: int = 0, follow_traj: bool = False, region_list: list = [], cancel_other_regions: bool = False)[source]

Bases: FlowFieldFinderBase[mRNN]

Flow-field estimator for leaky mRNN trajectories and local linearizations.

find_linear_flow(xs: Tensor, input: Tensor, delta_input: Tensor, delta_state_static: Tensor | None = None) list[source]

Compute linearized 2D flow fields around sampled trajectory states.

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. Assumes no external input to the selected regions.

Args:

states (torch.Tensor): Network states over time. inp (torch.Tensor): External input sequence aligned with states. delta_inp (torch.Tensor): Input perturbations for the local linear model. delta_state_static (torch.Tensor | None): Perturbations for recurrent regions excluded from the reduced plane. Should be for x or h depending on dh dh (bool): If True, linearize hidden activations instead of

pre-activations.

Returns:

list: FlowField objects per sampled time.

find_nonlinear_flow(xs: Tensor, input: Tensor, stim_input: Tensor | None = None, W: Tensor | None = None, x_is_h: bool = False) list[source]

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

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). Can zero out non-selected regions or keep their control values.

Args:

states (torch.Tensor): Hidden activations over time [batch_size, T, N]. input (torch.Tensor): External input sequence.

Kwargs:

stim_input (torch.Tensor): tensor input to network without weights, acts as manipulation W (torch.Tensor): replace the weight matrix of mRNN with W x_is_h (bool): whether to assume x=h, this will give an approximation of the flow field in h by assuming they are equal

Returns:

list: FlowField object per sampled time.