Skip to content

Decoder Class

ChangLiu edited this page May 30, 2025 · 2 revisions

neuraldecoding.decoder

Decoder class for converting offline or online neural data into behavioural data using methods provided.

Classes

Decoder

class Decoder(ABC)

Abstract base class for decoders. This class provides the common interface and functionality for all decoder implementations. It handles model instantiation, model loading, and defines the abstract methods.

Parameters:

  • cfg : dict

    Configuration dictionary with the following structure, typically parsed by config parser:

    decoder_struct = {'model': {'name': str, 
                                 'parameters': DictConfig, 
                                 'input_shape': ListConfig, 
                                 'output_shape': ListConfig}, 
                       'stabilization': {'name': str, 
                                         'parameters': DictConfig, 
                                         'date_0': str, 
                                         'date_k': str},
                       'fpath': str
                    }

Attributes:

  • model : object

    The instantiated model object

  • fpath : str

    File path to saved model

  • input_shape : tuple

    Expected input tensor dimensions

  • output_shape : tuple

    Expected output tensor dimensions

Methods

__init__(cfg)

Initialize the decoder with configuration, instantiates model, sets path to saved model, sets input and output shape, and loads the model.

Parameters:

  • cfg : dict

    Config dictionary as described above

load_model(fpath=None)

Load model parameters from file. Option to override the file path to the saved model.

Parameters:

  • fpath : str, optional

    Path to model parameters. If None, uses the attribute fpath.

get_decoder()

Create a deep copy of the decoder with loaded parameters.

Returns:

  • decoder : Decoder

    Deep-copied decoder instance with parameters loaded from file

predict(neural_data) (abstract)

Predict outputs from neural data.

Parameters:

  • neural_data :

    Input neural data

Returns:

  • predictions :

    Decoded predictions

get_input_shape()

Get the expected input shape.

Returns:

  • shape : numpy.ndarray

    Input dimensions

get_output_shape()

Get the expected output shape.

Returns:

  • shape : numpy.ndarray

    Output dimensions

Clone this wiki locally