fc_correlation_loss

fc_correlation_loss#

class braintools.fit.losses.fc_correlation_loss(prediction, target)#

Compute one minus the correlation between two functional-connectivity matrices.

Both inputs are turned into Pearson functional-connectivity (FC) matrices with functional_connectivity(); the loss is 1 - r where r is the Pearson correlation of their upper triangles (diagonal excluded), computed by matrix_correlation().

Parameters:
  • prediction (Any) – Model output of shape (n_time, n_regions), n_regions >= 2.

  • target (Any) – Data of shape (n_time', n_regions); the number of time points may differ. FC is scale-invariant, so units are not compared.

Returns:

Scalar loss in [0, 2].

Return type:

Array

Raises:

ValueError – If an input is not 2-D, has fewer than 2 regions, or the region counts differ.

Notes

Identical to brainmass.objectives.fc_corr(as_loss=True). With 2 regions the upper triangle has one element and its correlation is undefined; it is taken to be 0 (loss 1). Works under jax.jit and jax.vmap and is differentiable.

Examples

>>> import numpy as np
>>> import jax.numpy as jnp
>>> from braintools.fit import losses
>>> x = jnp.asarray(np.random.default_rng(0).standard_normal((200, 5)))
>>> round(float(losses.fc_correlation_loss(x, x)), 6)
0.0