GaussianPriorPenalty#

class gammapy.stats.GaussianPriorPenalty[source]#

Bases: FitStatisticPenalty

Penalty based on a multivariate Gaussian prior.

This implements a quadratic penalty of the form:

\[\lambda \times (x - \mu)^T C^{-1} (x - \mu)\]

where x are the parameter values, μ is the prior mean vector, and C is the prior covariance matrix.

If C is the identity matrix (default), this is equivalent to the L2 (ridge) regression.

Parameters:
parameterslist of Parameter

Parameters to which the penalty is applied.

meanlist of float, optional

Prior mean values for each parameter. If not provided, defaults to zeros.

covariancearray-like, optional

Prior covariance matrix. If not provided, an identity matrix is used.

lambda_float

Regularization strength (Lagrange multiplier).

Attributes Summary

covariance

Return covariance matrix of the multivariate gaussian.

Methods Summary

L2_penalty(parameters[, mean, lambda_])

Standard ridge (L2) regularization penalty.

SmoothnessPenalty(parameters[, mean, lambda_])

Create a smoothness penalty using finite differences.

from_diagonal(parameters, sigma[, mean, lambda_])

Create a GaussianPriorPenalty with a diagonal covariance matrix.

from_method(parameters, method, **method_kwargs)

Create from a specific method

from_precision(parameters, precision[, ...])

Create a GaussianPriorPenalty from a precision matrix (inverse covariance).

stat_sum()

Compute the Gaussian prior penalty.

Attributes Documentation

covariance#

Return covariance matrix of the multivariate gaussian.

Methods Documentation

classmethod L2_penalty(parameters, mean=None, lambda_=1.0)[source]#

Standard ridge (L2) regularization penalty.

Computes a penalty of the form: lambda * sum ||x_i - mu_i||² which corresponds to applying an identity covariance gaussian prior.

Parameters:
parameterslist of Parameter

Parameters to which the penalty is applied.

meanlist of float, optional

Prior mean values for each parameter. If not provided, defaults to zeros.

lambda_float

Regularization strength (Lagrange multiplier).

classmethod SmoothnessPenalty(parameters, mean=None, lambda_=1.0)[source]#

Create a smoothness penalty using finite differences.

Parameters:
parameters: list of `~gammapy.modeling.Parameter`

Parameters to which the penalty is applied.

lambda_: float, optional

Penalty strength. Default is 1.

classmethod from_diagonal(parameters, sigma, mean=None, lambda_=1.0)[source]#

Create a GaussianPriorPenalty with a diagonal covariance matrix.

Parameters:
parameterslist of Parameter

Parameters to apply the prior to.

sigma~numpy.ndarray` or float

Standard deviation(s) for each parameter.

meanndarray or float, optional

Mean values. If None, uses zero array. Default is None.

lambda_float

Penalty scaling factor.

classmethod from_method(parameters, method, **method_kwargs)[source]#

Create from a specific method

Parameters:
parameters: list of `~gammapy.modeling.Parameter`

Parameters to which the penalty is applied.

method: str

Option are precision, diagonal, smoothness, L2 which call from_precision, from_diagonal, SmoothnessPenalty, L2_penalty methods respectively

method_kwargs: dict

method specific arguments.

classmethod from_precision(parameters, precision, mean=None, lambda_=1.0)[source]#

Create a GaussianPriorPenalty from a precision matrix (inverse covariance).

Internally uses from_precision

Parameters:
parameterslist of Parameter or Parameters

Parameters to which the penalty is applied.

precisionndarray

Inverse covariance matrix (precision matrix).

meanndarray or None

Mean values. If None, uses zero array. Default is None.

lambda_float

Penalty strength (Lagrange multiplier).

stat_sum()[source]#

Compute the Gaussian prior penalty.

__init__(parameters, mean=None, covariance=None, lambda_=1.0)[source]#
classmethod __new__(*args, **kwargs)#