Threshold Based Representation Algorithm

threshold_based_representation(signal: ndarray, factor: float | int | list[float | int] | ndarray) tuple[ndarray, ndarray][source]

Perform Threshold-Based Representation (TBR) encoding on the input signal.

This function takes a continuous signal and converts it into a spike train using a fixed threshold based on the signal’s variations. A spike is generated when the variation exceeds the computed threshold.

Refer to the Threshold-Based Representation (TBR) Encoding for a detailed explanation of the TBR encoding algorithm.

Code Example:

import numpy as np
from spikify.encoders.temporal.contrast import threshold_based_representation
signal = np.array([0.1, 0.3, 0.4, 0.2, 0.5, 0.6])
factor = 0.5
encoded_signal, threshold = threshold_based_representation(signal, factor)
Parameters:
  • signal (numpy.ndarray) – Input signal to encode (1D or 2D: time × features or channels).

  • factor (float | int | list[float | int] | numpy.ndarray) – The factor value (factor) that controls the noise-reduction threshold. Can be a float, an integer, or a list of floats or integers.

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:

tuple[numpy.ndarray, numpy.ndarray]

Raises:

ValueError – If the input signal is empty or if the factor length does not match the number of features.