BPS#

class ibl_bwb_eval.metrics.BPS(num_outputs=None, degenerate_value=None, eps=1e-09, validate_finite=True, **kwargs)[source]#

Bases: torchmetrics.metric.Metric

Bits Per Spike metric for Poisson spiking data.

Assumes log-rates for the predictions.

The number of units is inferred automatically from the last dimension of the first call to update(), or can be provided explicitly via num_outputs.

\[\frac{N_{null} - N_{pred}}{n_{sp} \cdot \log 2}\]
Parameters:
  • num_outputs (Optional[int]) – Number of units. If provided, states are pre-allocated eagerly; otherwise the size is inferred from the last dim of the first update() call.

  • degenerate_value (Optional[Tensor]) – The value to return when the metric is degenerate.

  • eps (float) – The epsilon value to use for numerical stability.

  • validate_finite (bool) – Whether to check preds for NaN/inf on every update(). Disable only when the caller already trusts preds is finite (e.g. scoring predictions written by a validated pipeline).

References

[Pei et al., 2021]

update(preds, target)[source]#

Accumulate predictions and targets into the metric state.

Parameters:
  • preds (Tensor) – Predicted log-rates of shape (T, N).

  • target (Tensor) – Target spike counts of shape (T, N).

Return type:

None

compute()[source]#

Override this method to compute the final metric value.

This method will automatically synchronize state variables when running in distributed backend.

Return type:

Tensor