Parameters

class gammapy.utils.fitting.Parameters(parameters, covariance=None, apply_autoscale=True)[source]

Bases: object

List of Parameter.

Holds covariance matrix

Parameters:
parameters : list of Parameter

List of parameters

covariance : ndarray, optional

Parameters covariance matrix. Order of values as specified by parameters.

apply_autoscale : bool, optional

Flag for optimizers, if True parameters are autoscaled before the fit, see autoscale

Attributes Summary

correlation Correlation matrix (numpy.ndarray).
names List of parameter names
parameters List of Parameter.
restore_values Context manager to restore values.

Methods Summary

autoscale([method]) Autoscale all parameters.
copy() A deep copy
covariance_to_table() Convert covariance matrix to Table.
error(parname) Get parameter error.
from_dict(val)
set_covariance_factors(matrix) Set covariance from factor covariance matrix.
set_error(parname, err) Set parameter error.
set_parameter_errors(errors) Set uncorrelated parameters errors.
set_parameter_factors(factors) Set factor of all parameters.
to_dict()
to_table() Convert parameter attributes to Table.

Attributes Documentation

correlation

Correlation matrix (numpy.ndarray).

Correlation \(C\) is related to covariance \(\Sigma\) via:

\[C_{ij} = \frac{ \Sigma_{ij} }{ \sqrt{\Sigma_{ii} \Sigma_{jj}} }\]
names

List of parameter names

parameters

List of Parameter.

restore_values

Context manager to restore values.

A copy of the values is made on enter, and those values are restored on exit.

Examples

from gammapy.spectrum.models import PowerLaw

pwl = PowerLaw(index=2)
with pwl.parameters.restore_values:
    pwl.parameters["index"].value = 3

print(pwl.parameters["index"].value)

Methods Documentation

autoscale(method='scale10')[source]

Autoscale all parameters.

See autoscale()

Parameters:
method : {‘factor1’, ‘scale10’}

Method to apply

copy()[source]

A deep copy

covariance_to_table()[source]

Convert covariance matrix to Table.

error(parname)[source]

Get parameter error.

Parameters:
parname : str, int

Parameter name or index

classmethod from_dict(val)[source]
set_covariance_factors(matrix)[source]

Set covariance from factor covariance matrix.

Used in the optimizer interface.

set_error(parname, err)[source]

Set parameter error.

Parameters:
parname : str, int

Parameter name or index

err : float or Quantity

Parameter error

set_parameter_errors(errors)[source]

Set uncorrelated parameters errors.

Parameters:
errors : dict of Quantity

Dict of parameter errors.

set_parameter_factors(factors)[source]

Set factor of all parameters.

Used in the optimizer interface.

to_dict()[source]
to_table()[source]

Convert parameter attributes to Table.