Decoder

class behavenet.models.decoders.Decoder(hparams)[source]

Bases: BaseModel

General wrapper class for encoding/decoding models.

Methods Summary

build_model()

Construct the model using hparams.

forward(x)

Process input data.

loss(data[, accumulate_grad, chunk_size])

Calculate negative log-likelihood loss for supervised models.

Methods Documentation

build_model()[source]

Construct the model using hparams.

forward(x)[source]

Process input data.

loss(data, accumulate_grad=True, chunk_size=200, **kwargs)[source]

Calculate negative log-likelihood loss for supervised models.

The batch is split into chunks if larger than a hard-coded chunk_size to keep memory requirements low; gradients are accumulated across all chunks before a gradient step is taken.

Parameters:
  • data (dict) – signals are of shape (1, time, n_channels)

  • accumulate_grad (bool, optional) – accumulate gradient for training step

  • chunk_size (int, optional) – batch is split into chunks of this size to keep memory requirements low

Returns:

  • ‘loss’ (float): total loss (negative log-like under specified noise dist)

  • ’r2’ (float): variance-weighted $R^2$ when noise dist is Gaussian

  • ’fc’ (float): fraction correct when noise dist is Categorical

Return type:

dict