neural_data_simulator.decoder

This package contains an example implementation of a neural decoder.

The decoder is a software component that takes neural raw data as input and outputs behavioral data.

The decoder entry point is the decoder.run_decoder.run() method. Upon start, the configuration is parsed, the decoder connects to the LSL input raw data stream and creates an LSL outlet to write the decoded data to. Decoding is an iterative process that runs in a loop. On each iteration, a chunk of raw data is read from the LSL input stream and added to a buffer. The buffer is used to accumulate raw data so that the decoded chunk size can be constant. Once the buffer contains enough data according to the predetermined decoding window size, the decoder will count the number of spikes in each channel and estimate the spike rates. The spike rates are then used to predict the behavioral data using a pre-trained model. The predicted data is then written to the LSL output stream.

neural_data_simulator.decoder.decoders

This module contains the included decoder implementation – the Decoder.

class neural_data_simulator.decoder.decoders.DecoderModel(*args, **kwargs)[source]

Bases: Protocol

Protocol for a Decoder model.

A Decoder model predicts behavior data from spike rate data.

The Decoder processes data in chunks represented as neural_data_simulator.core.samples.Samples. One chunk may contain several spike rate data points (n_samples) across multiple units (n_units). The predict() method is called for each chunk in order to transform the spike rate data into behavior data (n_samples) across multiple axes (n_axes).

A python protocol (PEP-544) works in a similar way to an abstract class. The __init__() method of this protocol should never be called as protocols are not meant to be instantiated. An __init__() method may be defined in a concrete implementation of this protocol if needed.

predict(data: ndarray) ndarray[source]

Predict behavior from spike rate input.

Parameters

data – Spike rate data as neural_data_simulator.core.samples.Samples with shape (n_samples, n_units).

Returns

Behavior data as neural_data_simulator.core.samples.Samples with shape (n_samples, n_axes). For example, in case of modeling velocities in a horizontal and vertical direction (2 axes), the returned data is a 2D array with shape (n_samples, 2).

__init__(*args, **kwargs)
class neural_data_simulator.decoder.decoders.PersistedFileDecoderModel(model_file_path: str)[source]

Bases: DecoderModel

Decoder pre-trained model that can be loaded from a file.

__init__(model_file_path: str) None[source]

Initialize the model from a file path.

Parameters

model_file_path – The path to the model file.

predict(data: ndarray) ndarray[source]

Predict behavior from spike rate input.

Parameters

data – A spike rate vector.

Returns

A behavior vector.

class neural_data_simulator.decoder.decoders.Decoder(model: DecoderModel, input_sample_rate: float, output_sample_rate: float, n_channels: int, threshold: float)[source]

Bases: object

Decoder implementation that decodes spiking raw data into velocities.

__init__(model: DecoderModel, input_sample_rate: float, output_sample_rate: float, n_channels: int, threshold: float)[source]

Initialize the decoder.

Parameters
  • model – The decoder model.

  • input_sample_rate – The input sample rate in Hz.

  • output_sample_rate – The output sample rate in Hz.

  • n_channels – The number of input channels.

  • threshold – The spike detection threshold.

decode(samples: Samples) Samples[source]

Decode spiking raw data into velocities.

Parameters

samples – The raw data samples to decode.

Returns

The decoded velocities.

neural_data_simulator.decoder.run_decoder

Script that configures and starts the example Decoder.

neural_data_simulator.decoder.run_decoder.run()[source]

Run the decoder loop.

neural_data_simulator.decoder.settings

Schema for Decoder settings.

class neural_data_simulator.decoder.settings.DecoderSettings(*, input: Input, output: Output, model_file: str, spike_threshold: float)[source]

Bases: BaseModel

Decoder settings.

class Input(*, lsl: LSLInputModel)[source]

Bases: BaseModel

Decoder input settings.

lsl: LSLInputModel
class Output(*, sampling_rate: float, n_channels: int, lsl: LSLOutputModel)[source]

Bases: BaseModel

Decoder output settings.

sampling_rate: float
n_channels: int
lsl: LSLOutputModel
input: Input
output: Output
model_file: str
spike_threshold: float