GaussianPriorPenalty#
- class gammapy.stats.GaussianPriorPenalty[source]#
Bases:
FitStatisticPenaltyPenalty 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).
- parameterslist of
Attributes Summary
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).
- parameterslist of
- 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.
- mean
ndarrayor 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_penaltymethods 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
ParameterorParameters Parameters to which the penalty is applied.
- precision
ndarray Inverse covariance matrix (precision matrix).
- mean
ndarrayor None Mean values. If None, uses zero array. Default is None.
- lambda_float
Penalty strength (Lagrange multiplier).
- parameterslist of
- classmethod __new__(*args, **kwargs)#