rxmc.likelihood_model.LikelihoodModel#
- class rxmc.likelihood_model.LikelihoodModel[source]#
Bases:
objectA class to represent a likelihood model for comparing an Observation to a PhysicalModel.
The default behavior uses the following covariance matrix:
\[\Sigma_{ij} = \sigma^2_{i}^{stat} \delta_{ij} + \Sigma_{ij}^{sys} + \gamma^2 y_m^2(x_i, \alpha)\]where $sigma^2_{i}^{stat}$ is the statistical variance of the i-th observation, (observation.statistical_covariance) and $gamma$ is the fractional uncorrelated error (self.frac_err).
Here, $Sigma_{ij}^{sys}$ is the systematic covariance matrix:
\[\Sigma_{ij}^{sys} = \eta**2 y_m(x_i, \alpha) y_m(x_j, \alpha) + \omega,\]where $eta$ is the uncertainty in the overall normalization of the observation (observation.y_sys_err_normalization) and $omega$ is the uncertainty in the additive normalization to the observation (observation.y_sys_err_offset).
Here, also, $y_m(x_i, alpha)$ is the model prediction for the i-th observation. Thus the covariance matrix is dependent on the values of the PhysicalModel and its parameters, as is the case when systematic errors are present in the observation, following D’Agostini, G. (1993) ‘On the use of the covariance matrix to fit correlated data’
Note that if there is no systematic uncertainty encoded in the observation and self.frac_err takes the default value of 0, the covariance matrix becomes diaginal, and the chi2 function reduces to the simple and familiar $chi^2$ form.
Note also that this is equivalent to the alternative method to handle systematic errors described by Barlow, R (2021) ‘Combining experiments with systematic errors’, in which nuisance parameters are introduced corresponding to the normalization and additive offset bias of the observation.
The advantage of this approach is that it does not require introducing nuisance parameters, but instead encodes the correlation between the data points in the observation in the covariance matrix directly.
- __init__()[source]#
Initializes the LikelihoodModel, optionally with a fractional uncorrelated error.
Methods
__init__()Initializes the LikelihoodModel, optionally with a fractional uncorrelated error.
chi2(observation, ym)Calculate the generalised chi-squared statistic.
covariance(observation, ym)Default covariance model.
log_likelihood(observation, ym)Returns the log_likelihood that ym reproduces y, given the covariance
residual(observation, ym)Return the residual
observation.y - ym.- covariance(observation: Observation, ym: ndarray)[source]#
Default covariance model. Derived classes of LikelihoodModel will override this.
Returns the following covariance matrix:
\[\Sigma_{ij} = \sigma^2_{i}^{stat} \delta_{ij} + \Sigma_{ij}^{sys} + \gamma^2 y_m^2(x_i, \alpha)\]where $sigma^2_{i}^{stat}$ is the statistical variance of the i-th observation, (observation.statistical_covariance) and $gamma$ is the fractional uncorrelated error (self.frac_err).
Here, $Sigma_{ij}^{sys}$ is the systematic covariance matrix:
\[\Sigma_{ij}^{sys} = \eta**2 y_m(x_i, \alpha) y_m(x_j, \alpha) + \omega,\]where $eta$ is the uncertainty in the overall normalization of the observation (observation.y_sys_err_normalization) and $omega$ is the uncertainty in the additive normalization to the observation (observation.y_sys_err_offset).
Here, also, $y_m(x_i, alpha)$ is the model prediction for the i-th observation.
- Parameters:
ym (np.ndarray) – Model prediction for the observation.
observation (Observation) – The observation object containing the observed data.
- Returns:
np.ndarray – Covariance matrix of the observation.
- residual(observation: Observation, ym: ndarray)[source]#
Return the residual
observation.y - ym.- Parameters:
observation (Observation) – Observation containing the measured data.
ym (np.ndarray) – Model prediction for the observation.
- Returns:
np.ndarray – Residual vector.
- chi2(observation: Observation, ym: ndarray)[source]#
Calculate the generalised chi-squared statistic. This is the square of the Mahalanobis distance between y and ym
- Parameters:
observation (Observation) – The observation object containing the observed data.
ym (np.ndarray) – Model prediction for the observation.
- Returns:
float – Chi-squared statistic.
- log_likelihood(observation: Observation, ym: ndarray)[source]#
Returns the log_likelihood that ym reproduces y, given the covariance
- Parameters:
ym (np.ndarray) – Model prediction for the observation.
observation (Observation) – The observation object containing the observed data.
- Returns:
float