fc_rmse#
- class braintools.fit.losses.fc_rmse(prediction, target)#
Compute the RMSE between the upper triangles of two functional-connectivity matrices.
\[L = \sqrt{\frac{2}{n(n-1)} \sum_{i<j} (\hat C_{ij} - C_{ij})^2},\]where \(\hat C\) and \(C\) are the Pearson functional-connectivity matrices (
functional_connectivity()) ofnregions.- Parameters:
- 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.
See also
Notes
Only the
n(n-1)/2off-diagonal pairs enter the mean, as the 0.6 specification requires. This differs frombrainmass.objectives.fc_rmse, which averages over the fulln x nmatrix, including the diagonal (always equal, so it adds zeros to the mean). The two are related by\[L_{\mathrm{brainmass}} = L \sqrt{\frac{n - 1}{n}}, \qquad L = L_{\mathrm{brainmass}} \sqrt{\frac{n}{n - 1}},\]so brainmass values are smaller by the factor \(\sqrt{(n-1)/n}\) (0.926 for \(n = 7\), e.g. 0.0869 versus 0.0939). Code ported from brainmass must rescale thresholds or weights by that factor. Works under
jax.jitandjax.vmapand is differentiable (gradient 0 at a perfect fit).Examples
>>> import jax.numpy as jnp >>> from braintools.fit import losses >>> t = jnp.linspace(0., 10., 200) >>> a = jnp.stack([jnp.sin(t), jnp.sin(t), jnp.cos(t)], axis=1) >>> b = jnp.stack([jnp.sin(t), -jnp.sin(t), jnp.cos(t)], axis=1) >>> round(float(losses.fc_rmse(a, b)), 4) 1.1563