Chi2

Description

Calculates the \(\chi^2\) value.

Inputs

  1. Theory \(\mu\) of size \(N\).

  2. Data \(x\) of size \(N\).

  3. Covariance matrix Cholesky decomposition \(L\) of size \(N\times N\).

  4. Optionally \(\mu_2,x_2,L_2,\dots\) of sizes \(N_2,\dots\).

Inputs are added via add(theory, data, cov) method.

Outputs

  1. 'chi2' — chi-squared value \(\chi^2\).

Implementation

For the covariance matrix \(V\) (symmetric, positively defined), decomposed as

\[V = L L^T,\]

where \(L\) is a lower triangular matrix the tranformation returns the \(\chi^2\) value:

\[\chi^2 = (x-\mu)^T V^{-1} (x - \mu).\]

The exact implementation follows:

\[y = L^{-1} (x-\mu),\]
\[\chi^2 = y^T y.\]