Function¶
- class gdt.core.spectra.functions.Function[source]¶
Bases:
ABCAbstract class for a 1-D function (e.g. photon model).
Sub-classes should be designed with the following requirements:
Attribute
nparamscontaining the total number of parameters of the function (even parameters that are fixed to a particular value during fitting)Method
eval()that accepts two arguments: an array of parameter values of lengthnparams; and the array of abscissa values.
Subclasses can optionally add the following for complete and enhanced functionality:
Attribute
param_listthat is a list of parameter names in the order they are accepted in theeval()method. Each entry inparam_listis a tuple of the form (<param_name>, <units>, <description>). If no units or description are needed, those fields should be a null string ‘’. If omitted, these will be filled to default values (‘param0’, ‘’, ‘’), etc.Attribute
default_valuesthat is a list of default parameter values. This is primarily used for parameter estimation. Default is 1.0 for each parameterAttribute
delta_absthat is a list of max absolute fitting step for each parameter. This is used for parameter estimation. Default is 0.1 for each parameter.Attribute
delta_relthat is a list of max relative fitting step for each parameter. This is used for paramter estimation. Default is 0.01 for each parameter.Attribute
min_valuesthat is a list of minimum values each parameter can take. This is used primarily for parameter estimation. Default is -np.inf for each parameter.Attribute
max_valuesthat is a list of maximum values each parameter can take. This is used primarily for parameter estimation. Default is np.inf for each parameter.Attribute
freethat is a boolean list indicating if each parameter is allowed to be free for fitting. False indicates that the parameter will be fixed at its default value. This is used for parameter estimation. Default is True for each parameter.
Attributes Summary
The default parameter values.
The maximum absolute fitting step size for each parameter.
The maximum relative fitting step size for each parameter.
For each parameter, mark True if left free for fitting, otherwise mark False to fix at the default value.
The maximum possible value for each parameter.
The minimum possible value for each parameter.
The name of the function.
Number of parameters in the function.
Number of function components.
The list of parameters.
Methods Summary
add(func1, func2)Add two Functions.
eval(params, x)Evaluate the function.
fit_eval(params, x, **kwargs)Evaluate the function for a fit.
integrate(params, erange[, num_points, log, ...])Integrate the function over energy to produce a flux.
multiply(func1, func2)Multiply two Functions.
parameter_bounds([apply_state])The valid parameter bounds in the form [(min, max), ...]
Attributes Documentation
- default_values: List[float] = None¶
The default parameter values. If not defined, each defaults to 1.0
- delta_abs: List[float] = None¶
The maximum absolute fitting step size for each parameter. If not defined, each default to 0.1
- delta_rel: List[float] = None¶
The maximum relative fitting step size for each parameter. If not defined, each default to 0.01
- free: List[bool] = None¶
For each parameter, mark True if left free for fitting, otherwise mark False to fix at the default value. If not defined, each default to True.”””
- max_values: List[float] = None¶
The maximum possible value for each parameter. If not defined, each default to np.inf
- min_values: List[float] = None¶
The minimum possible value for each parameter. If not defined, each default to -np.inf
- name: str = None¶
The name of the function.
- nparams: int = None¶
Number of parameters in the function.
- num_components¶
Number of function components. For a normal function this is one, for a
SuperFunction, this can be > 1.- Type:
(int)
- param_list: List[Tuple[str, str, str]] = None¶
The list of parameters. Each element is of form (parameter name, units, short description)
Methods Documentation
- classmethod add(func1, func2)[source]¶
Add two Functions. Can also use the
+operator.- Parameters:
- Returns:
- abstract eval(params, x)[source]¶
Evaluate the function.
- Parameters:
params (iterable) – The parameter vector of the free parameters
x (np.array) – The values at which to evaluate the function
- Returns:
(np.array)
- fit_eval(params, x, **kwargs)[source]¶
Evaluate the function for a fit. This differs from
eval()because theparamsvector should only contain the free fit parameters. The parameters that are set to fixed will automatically be passed toeval()at their fixed value. This enables a fit to be performed with fixed parameters and the associated jacobian and covariance matrices will have the appropriate shape.- Parameters:
params (iterable) – The parameter vector of the free parameters
x (np.array) – The values at which to evaluate the function
- Returns:
(np.array)
- integrate(params, erange, num_points=1000, log=True, energy=False)[source]¶
Integrate the function over energy to produce a flux.
- Parameters:
params (iterable) – The parameter vector, which can be of length
nparamsor equal to the length of the non-fixed (free) parameters.erange (float, float) – The energy range over which to integrate
num_points (int, optional) – The number of points used for integration. Default is 1000.
log (bool, optional) – If True, the integration grid is made in log-space, otherwise it is linear. Default is True.
energy (bool, optional) – If True, perform integration of E*F(E) to produce an energy flux, otherwise integration is over F(E) to produce a photon flux. Default is False.
- Returns:
(float)