Parameters¶
-
class
gammapy.modeling.
Parameters
(parameters=None, covariance=None)[source]¶ Bases:
collections.abc.Sequence
Parameters container.
List of
Parameter
objects.Covariance matrix.
- Parameters
Attributes Summary
Correlation matrix (
numpy.ndarray
).Covariance matrix (
numpy.ndarray
).List of free parameters
List of parameter names
Context manager to restore values.
Unique parameters (
Parameters
).Parameter values (
numpy.ndarray
).Methods Summary
autoscale
(self[, method])Autoscale all parameters.
copy
(self)A deep copy
count
(self, value)error
(self, parname)Get parameter error.
freeze_all
(self)Freeze all parameters
from_dict
(data)from_stack
(parameters_list)Create
Parameters
by stacking a list of otherParameters
objects.from_values
([values, covariance])Create
Parameters
from values.get_subcovariance
(self, parameters)Get sub-covariance matrix
index
(self, value[, start, stop])Raises ValueError if the value is not present.
link
(self, par, other_par)Create link to other parameter
set_covariance_factors
(self, matrix)Set covariance from factor covariance matrix.
set_error
(self, \*\*kwargs)Set errors on parameters.
set_parameter_factors
(self, factors)Set factor of all parameters.
set_subcovariance
(self, parameters)Set sub-covariance matrix
to_dict
(self)to_table
(self)Convert parameter attributes to
Table
.update_from_dict
(self, data)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}} }\]
-
covariance
¶ Covariance matrix (
numpy.ndarray
).
-
free_parameters
¶ List of free parameters
-
names
¶ List of parameter names
-
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.modeling.models import PowerLawSpectralModel pwl = PowerLawSpectralModel(index=2) with pwl.parameters.restore_values: pwl.parameters["index"].value = 3 print(pwl.parameters["index"].value)
-
scipy_mvn
¶
-
unique_parameters
¶ Unique parameters (
Parameters
).
-
values
¶ Parameter values (
numpy.ndarray
).
Methods Documentation
-
autoscale
(self, method='scale10')[source]¶ Autoscale all parameters.
See
autoscale()
- Parameters
- method{‘factor1’, ‘scale10’}
Method to apply
-
count
(self, value)¶
-
error
(self, parname)[source]¶ Get parameter error.
- Parameters
- parnamestr, int
Parameter name or index
-
classmethod
from_stack
(parameters_list)[source]¶ Create
Parameters
by stacking a list of otherParameters
objects.- Parameters
- parameters_listlist of
Parameters
List of
Parameters
objects
- parameters_listlist of
-
classmethod
from_values
(values=None, covariance=None)[source]¶ Create
Parameters
from values.TODO: document.
-
get_subcovariance
(self, parameters)[source]¶ Get sub-covariance matrix
- Parameters
- parameters
Parameters
Sub list of parameters.
- parameters
- Returns
- covariance
ndarray
Sub-covariance.
- covariance
-
index
(self, value, start=0, stop=None)¶ Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
-
set_covariance_factors
(self, matrix)[source]¶ Set covariance from factor covariance matrix.
Used in the optimizer interface.
-
set_error
(self, **kwargs)[source]¶ Set errors on parameters.
Pass parameter errors as keyword arguments, similar to how parameter values are passed in other places.
Usually parameter errors come via a fit and a covariance matrix. This method is only used to make models from previously published results, e.g. in
gammapy.catalog
.Examples
>>> from gammapy.modeling.models import PowerLawSpectralModel >>> model = PowerLawSpectralModel(amplitude="4.2e-11 cm-2 s-1 TeV-1", index=2.7) >>> model.parameters.set_error(amplitude="0.6-11 cm-2 s-1 TeV-1", index=0.2)
-
set_parameter_factors
(self, factors)[source]¶ Set factor of all parameters.
Used in the optimizer interface.
-
set_subcovariance
(self, parameters)[source]¶ Set sub-covariance matrix
- Parameters
- parameters
Parameters
Sub list of parameters.
- parameters