HiddenGroupState#
- class brainstate.HiddenGroupState(value, **kwargs)#
A group of multiple hidden states for eligibility trace-based learning.
This class is used to define multiple hidden states within a single instance of
ETraceState. Normally, you should define multiple instances ofETraceStateto represent multiple hidden states. ButHiddenGroupStatelet your define multiple hidden states within a single instance.The following is the way to initialize the hidden states.
import brainunit as u value = np.random.randn(10, 10, 5) * u.mV state = HiddenGroupState(value)
Then, you can retrieve the hidden state value with the following method.
state.get_value(0) # get the first hidden state # or state.get_value('0') # get the hidden state with the name '0'
You can write the hidden state value with the following method.
state.set_value({0: np.random.randn(10, 10) * u.mV}) # set the first hidden state # or state.set_value({'0': np.random.randn(10, 10) * u.mV}) # set the hidden state with the name '0' # or state.value = np.random.randn(10, 10, 5) * u.mV # set all hidden state value
- Parameters:
value (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – The values of the hidden states. It can be a sequence of hidden states, or a single hidden state with the last dimension as the number of hidden states, or a dictionary of hidden states.
- property num_state: int#
Get the number of hidden states.
This property returns the number of hidden states represented by the last dimension of the value array.
- Returns:
The number of hidden states.
- Return type:
- set_value(val)[source]#
Set the value of the hidden state with the specified item.
This method updates the hidden state values based on the provided dictionary or sequence. The values are set according to the indices or names specified in the input.
- Parameters:
str (val (Dict[int |) – A dictionary or sequence containing the new values for the hidden states. - If a dictionary, keys can be integers (indices) or strings (names) of the hidden states. - If a sequence, it is converted to a dictionary with indices as keys.
Sequence[ArrayLike]) (ArrayLike] |) – A dictionary or sequence containing the new values for the hidden states. - If a dictionary, keys can be integers (indices) or strings (names) of the hidden states. - If a sequence, it is converted to a dictionary with indices as keys.
- Returns:
None
- Return type:
- property varshape: Tuple[int, ...]#
Get the shape of each hidden state variable.
This property returns the shape of the hidden state variables, excluding the last dimension which represents the number of hidden states.
- Returns:
A tuple representing the shape of each hidden state variable.
- Return type:
Tuple[int, …]