neuraltrain.metrics.metrics.OnlinePearsonCorr

class neuraltrain.metrics.metrics.OnlinePearsonCorr(dim: int, reduction: Literal['mean', 'sum', 'none'] | None = 'mean', torchmetrics_kwargs: dict[str, Any] | None = None)[source][source]

Online Pearson correlation coefficient.

This class computes the Pearson correlation coefficient in an online fashion, updating the metric with each new batch of predictions and targets.

Parameters:
  • dim (int) –

    The dimension along which to compute the correlation coefficient. - dim=0: correlate across samples (each column is a separate output).

    Uses Welford online accumulation, so batch sizes may vary.

    • dim=1: correlate across features/time within each sample, then reduce across samples. Computes per-sample correlations per batch and accumulates them, so it is correct across multiple batches.

  • reduction ({"mean", "sum", "none"}, optional) – Specifies how to reduce the computed correlation coefficients. Defaults to “mean”.

  • torchmetrics_kwargs (dict or None) – Extra keyword arguments forwarded to the torchmetrics.Metric constructor (e.g. dist_sync_on_step).

compute()[source][source]

Compute pearson correlation coefficient over state.

reset() None[source][source]

Reset metric state variables to their default value.

update(preds: Tensor, target: Tensor) None[source][source]

Update state with predictions and targets.