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) – The input signal to be encoded. This should be a numpy ndarray.

  • 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:

A tuple containing the encoded spike train and the computed threshold for each feature.

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.

  • TypeError – If the factor parameter is of invalid dimension.