HiddenState#

class brainstate.HiddenState(value, name=None, **kwargs)#

Represents hidden state variables in neurons or synapses.

This class extends ShortTermState and is specifically designed to represent and manage hidden states within dynamic models, such as recurrent neural networks. It provides a way to encapsulate hidden state values and associated metadata, facilitating operations like state updates during model execution.

Note

HiddenState and ParamState are two most important state types in brainstate. The former is used to store the hidden states in neurons, synapses, or networks. The latter is used to store the trainable parameters in the model, such as synaptic weights.

Note

From version 0.2.2, HiddenState only supports value of numpy.ndarray, jax.Array or brainunit.Quantity. Moreover, it is equivalent to brainstate.HiddenState. Dynamics models defined with HiddenState can be seamlessly integrated with BrainScale online learning.

Example

>>> lstm_hidden = HiddenState(np.zeros(128), name="lstm_hidden_state")
>>> gru_hidden = HiddenState(np.zeros(64), name="gru_hidden_state")
property num_state: int#

Get the number of hidden states.

This property returns the number of hidden states represented by the instance. For the ETraceState class, this is always 1, as it represents a single hidden state.

Returns:

The number of hidden states, which is 1 for this class.

Return type:

int

property varshape: Tuple[int, ...]#

Get the shape of the hidden state variable.

This property returns the shape of the hidden state variable stored in the instance. It provides the dimensions of the array representing the hidden state.

Returns:

A tuple representing the shape of the hidden state variable.

Return type:

Tuple[int, …]