Step Forward Algorithm
- step_forward(signal: ndarray, threshold: float | int | list[float | int] | ndarray) tuple[ndarray, ndarray][source]¶
Perform Step-Forward (SF) encoding on the input signal.
This function takes a continuous signal and converts it into a spike train using a dynamically updated baseline signal and threshold-based approach. A spike is generated when the signal exceeds or drops below the dynamically adjusted baseline (base) by the specified threshold.
Refer to the Step Forward (SF) Encoding for a detailed explanation of the SF encoding algorithm.
Code Example:
import numpy as np from spikify.encoders.temporal.contrast import step_forward signal = np.array([0.1, 0.3, 0.4, 0.2, 0.5, 0.6]) threshold = 0.2 encoded_signal, thresholds = step_forward(signal, threshold)
- Parameters:
signal (numpy.ndarray) – Input signal to encode (1D or 2D: time × features or channels).
threshold (float | int | list[float | int] | numpy.ndarray) – Threshold(s) for spike generation; scalar or 1D sequence matching features.
- Returns:
spikes: A numpy array representing the encoded spike train. (values in {-1, 0, +1})
thresholds: Per-feature or channel thresholds used for encoding, returned for use in decoding, shape (features or channels,).
- Return type:
- Raises:
ValueError – If the input signal is empty or if the threshold dimensions do not match the signal features dimensions.