-
Notifications
You must be signed in to change notification settings - Fork 0
REINFORCE
The implementation follows ordinary episodic REINFORCE. This page only describes the details that matter when a spiking policy preserves neuron state between environment steps. The agent is implemented in src/spiking_rl_lab/agents/reinforce.py.
A spiking policy depends on both the current observation and the neuron state:
Here
Each environment step advances the network by exactly one LIF or LI update. The agent does not create an inner spike-time window and does not perform rate or population decoding. LIF nodes expose spikes, while LI or linear nodes can provide a continuous readout after a spiking hidden layer.
Interaction with the environment runs under torch.no_grad(). At the start of a rollout, the agent saves the network state. During optimization it restores that state and sequentially replays the stored observations and actions with gradients enabled. The usual REINFORCE loss is then evaluated on the reconstructed temporal graph:
Here
Replay is important for spiking networks because the action probability at step method and alpha parameters make backpropagation through spike generation possible.
State is stored separately for every parallel environment. When an environment terminates or is truncated, only its batch row is reset to the node's resting state:
Here
The same reset is applied during collection and replay, preventing membrane voltage and synaptic current from crossing episode boundaries. Clearing rollout memory does not reset the live state, so an unfinished episode can continue across rollouts.
During replay, node states are detached every sequence_length transitions:
Here
Increasing sequence_length allows longer temporal credit assignment at a higher memory cost.
- The final network width must match
flatdim(action_space). - A final LIF node uses binary spikes directly as categorical logits or Gaussian means. An LI or linear readout is usually less restrictive.
- The categorical and Gaussian policies provide trainable log-probabilities. The deterministic policy produces zero log-probability and therefore cannot train through REINFORCE alone.
- Returns stop at episode boundaries and at the end of the collected rollout. There is no value-function bootstrap.
The main SNN-specific parameter is agent.params.sequence_length. Node dynamics and surrogate gradients are configured in the lif and li node definitions. See Configuration and experiments for composition and override syntax.