elman_linear¶
- class mrnntorch.analysis.linear.elman_linear.emLinearization(rnn: ElmanmRNN, *args)[source]¶
Bases:
objectLocal linear analysis utilities for
ElmanmRNNmodels.- eigendecomposition(input: Tensor, h: Tensor) tuple[Tensor, Tensor, Tensor][source]¶
Compute the eigendecomposition of the local hidden-state Jacobian.
- Args:
input (torch.Tensor): Input vector at which to linearize. h (torch.Tensor): Hidden state at which to linearize.
- Returns:
torch.Tensor: Real parts of eigenvalues. torch.Tensor: Imag parts of eigenvalues. torch.Tensor: Eigenvectors stacked column-wise.
- forward(input: Tensor, h: Tensor, delta_input: Tensor, delta_h: Tensor, delta_h_static: Tensor | None = None) Tensor[source]¶
Evaluate the first-order Taylor approximation of the Elman dynamics.
- Args:
input (torch.Tensor): External input at the operating point. h (torch.Tensor): Hidden state about which to linearize. delta_input (torch.Tensor): Input perturbation. delta_h (torch.Tensor): Hidden-state perturbation for included regions. delta_h_static (torch.Tensor | None): Perturbation applied to excluded
regions when only a subset of regions is linearized.
- Returns:
torch.Tensor: Linearized next hidden state.
- jacobian(input: Tensor, h: Tensor, excluded_regions: bool = False) Tuple[Tensor, Tensor][source]¶
Return Jacobians of the Elman update with respect to state and input.
- Args:
input (torch.Tensor): Input vector at which to linearize. h (torch.Tensor): Hidden state at which to linearize. excluded_regions (bool): If
True, return the projection fromexcluded recurrent regions into the included region subset.
- Returns:
Tuple[torch.Tensor, torch.Tensor]: Jacobian with respect to hidden state followed by Jacobian with respect to input.
leaky_linear¶
- class mrnntorch.analysis.linear.leaky_linear.mLinearization(rnn: mRNN, *args)[source]¶
Bases:
objectLocal linear analysis utilities for leaky
mRNNmodels.- eigendecomposition(input: Tensor, x: Tensor, h: Tensor | None = None, dh: bool = False) tuple[Tensor, Tensor, Tensor][source]¶
Compute the eigendecomposition of the local Jacobian.
- Args:
input (torch.Tensor): Input vector at which to linearize. x (torch.Tensor): Pre-activation state at which to linearize. h (torch.Tensor | None): Hidden activation used when
dhisTrue. dh (bool): IfTrue, eigendecompose the hidden-state Jacobian.- Returns:
torch.Tensor: Real parts of eigenvalues. torch.Tensor: Imag parts of eigenvalues. torch.Tensor: Eigenvectors stacked column-wise.
- forward(input: Tensor, x: Tensor, delta_input: Tensor, delta_state: Tensor, delta_state_static: Tensor | None = None, h: Tensor | None = None, dh: bool = False) Tensor[source]¶
Evaluate the first-order Taylor approximation of the leaky dynamics.
- Args:
input (torch.Tensor): External input at the operating point. x (torch.Tensor): Pre-activation state about which to linearize. delta_input (torch.Tensor): Input perturbation. delta_state (torch.Tensor): Perturbation for the state of the included region subset. Should be x perturbations or h perturbations if dh=True h (torch.Tensor | None): Activation corresponding to
xwhen linearizing hidden activations directly. delta_h_static (torch.Tensor | None): Perturbation applied to excluded regions when only a subset of regions is linearized. dh (bool): IfTrue, linearize the hidden activation update instead of the pre-activation update.- Returns:
torch.Tensor: Linearized next state in the requested coordinates.
- jacobian(input: Tensor, x: Tensor, excluded_regions: bool = False, h: Tensor | None = None, dh: bool = False) Tuple[Tensor, Tensor][source]¶
Return Jacobians of the leaky update with respect to state and input.
- Args:
input (torch.Tensor): Input vector at which to linearize. x (torch.Tensor): Pre-activation state at which to linearize. h (torch.Tensor | None): Hidden activation used when
dhisTrue. excluded_regions (bool): IfTrue, return the projection fromexcluded recurrent regions into the included region subset.
- dh (bool): If
True, differentiate the hidden activation output rather than the pre-activation state output.
- dh (bool): If
- Returns:
Tuple[torch.Tensor, torch.Tensor]: Jacobian with respect to state followed by Jacobian with respect to input.