- class sinabs.layers.StatefulLayer(state_names: List[str])[source]#
A base class that instantiates buffers/states which update at every time step and provides helper methods that manage those states.
state_names (List[str]) – the PyTorch buffers to initialise. These are not parameters.
- property does_spike: bool#
Return True if the layer has an activation function.
- forward(*args, **kwargs)[source]#
Not implemented - You need to implement a forward method in child class
- init_state_with_shape(shape, randomize: bool = False) None [source]#
Initialise state/buffers with either zeros or random tensor of specific shape.
randomize (bool) –
- Return type
- is_state_initialised() bool [source]#
Checks if buffers are of shape 0 and returns True only if none of them are.
- Return type
- reset_states(randomize: bool = False, value_ranges: Optional[Dict[str, Tuple[float, float]]] = None)[source]#
Reset the state/buffers in a layer.
randomize (bool) – If true, reset the states between a range provided. Else, the states are reset to zero.
value_ranges (Optional[Dict[str, Tuple[float, float]]]) – A dictionary of key value pairs: buffer_name -> (min, max) for each state that needs to be reset. The states are reset with a uniform distribution between the min and max values specified. Any state with an undefined key in this dictionary will be reset between 0 and 1 This parameter is only used if randomize is set to true.
If you would like to reset the state with a custom distribution, you can do this individually for each parameter as follows:
layer.<state_name>.data = <your desired data>