linearization¶
- class rnntoolkit.linear.Linearization(rnn: RNN)[source]¶
Bases:
object- eigendecomposition(input: Tensor, h: Tensor) tuple[Tensor, Tensor, Tensor][source]¶
Linearize the network and compute eigen decomposition.
- Args:
input (torch.Tensor): 1D tensor representing the input for the network at state h h (torch.Tensor): 1D tensor representing the desired state h for taylor expansion
- 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) Tensor[source]¶
First order taylor exansion of RNN at a given point and input
- Args:
input (Tensor): 1D tensor of input for network at a given state h (Tensor): 1D tensor of network state to linearize about delta_inp (Tensor): 1D tensor for perturbation of input to apply to input jacobian delta_h (Tensor): batched perturbations of state
- jacobian(input: Tensor, h: Tensor) tuple[Tensor, Tensor][source]¶
Linearize the dynamics around a state and return the Jacobian.
Computes the Jacobian of the RNN update with respect to the hidden state evaluated at the provided state
hand inputinput.- Args:
input (torch.Tensor): 1D tensor representing the input for the network at state h h (torch.Tensor): 1D tensor representing the desired state h for taylor expansion
- Returns:
_jacobian_h (torch.Tensor): jacobian of h_t+1 w respect to h_t _jacobian_inp (torch.Tensor): jacobian of h_t+1 w respect to input_t