astromodels.core.parameter module
- class astromodels.core.parameter.IndependentVariable(name, value, unit, min_value=None, max_value=None, desc=None)[source]
Bases:
ParameterBase
An independent variable like time or energy.
- class astromodels.core.parameter.Parameter(name: Optional[str] = None, value: Optional[float] = None, min_value: Optional[float] = None, max_value: Optional[float] = None, delta: Optional[float] = None, desc: Optional[str] = None, free: bool = True, unit='', prior=None, is_normalization: bool = False, transformation: Optional[ParameterTransformation] = None)[source]
Bases:
ParameterBase
Implements a numerical parameter. Optionally the parameter can vary according to an auxiliary law (see below).
- Parameters:
name – Name for the parameter
value – Initial value
min_value – minimum allowed value for the parameter (default: None)
max_value – maximum allowed value for the parameter (default: None)
delta – initial step used by some fitting engines (default: 0.1 * value)
desc – description of parameter (default: ‘’)
free – whether the parameter is free or not (default: True)
unit – the parameter units (default: dimensionless)
prior – the parameter’s prior (default: None)
is_normalization – True or False, wether the parameter is a normalization or not (default: False)
transformation – a transformation to be used between external value (the value the user interacts with) and the value the fitting/sampling engine interacts with (internal value). It is an instance of a class implementing a forward(external_value) and a backward(internal_value) method returning respectively the transformation of the external value in the internal value and viceversa. This is useful because for example the logarithm of a parameter with a large range of possible values (say from 1e-12 to 1e20) is handled much better by fitting engines than the raw value. The log transformation indeed makes the gradient much easier to compute.
- add_auxiliary_variable(variable, law) None [source]
TODO describe function
- Parameters:
variable –
law –
- Returns:
- property auxiliary_variable: Tuple
Returns a tuple with the auxiliary variable and the law
- Returns:
tuple (variable, law)
- property delta
Gets or sets the delta for the parameter
- property fix
‘p.fix = True’ or ‘p.fix = False’.
- Type:
Gets or sets whether the parameter is fixed or not. Use booleans, like
- property free
‘p.free = True’ or ‘p.free = False’.
- Type:
Gets or sets whether the parameter is free or not. Use booleans, like
- property has_auxiliary_variable: bool
Returns whether the parameter is linked to an auxiliary variable
- property is_normalization: bool
- property prior
Gets or sets the current prior for this parameter. The prior must be a callable function accepting the current value of the parameter as input and returning the probability density as output. Set to None to remove prior.
- set_uninformative_prior(prior_class)[source]
Sets the prior for the parameter to a uniform prior between the current minimum and maximum, or a log-uniform prior between the current minimum and maximum.
NOTE: if the current minimum and maximum are not defined, the default bounds for the prior class will be used.
:param prior_class : the class to be used as prior (either Log_uniform_prior or Uniform_prior, or a class which provide a lower_bound and an upper_bound properties) :return: (none)
- class astromodels.core.parameter.ParameterBase(name: str, value: float, min_value: Optional[float] = None, max_value: Optional[float] = None, desc: Optional[str] = None, unit: Unit = Unit(dimensionless), transformation: Optional[ParameterTransformation] = None)[source]
Bases:
Node
- Parameters:
name – name for parameter
value – initial value
min_value – minimum
max_value – maximum
desc – description
unit – units (string or astropy.Unit)
transformation – a class which implements a .forward and a .backward method to transform forth and back from face value (the value exposed to the user) to the internal value (the value exposed to the fitting engine)
- add_callback(callback) None [source]
Add a callback to the list of functions which are called immediately after the value of the parameter is changed. The callback must be a function accepting the current parameter as input. The return value of the callback is ignored. More than one callback can be specified. In that case, the callbacks will be called in the same order they have been entered.
- property as_quantity: Quantity
Return the current value with its units (as an astropy.Quantity instance)
- Returns:
an instance of astropy.Quantity)
- property bounds: Tuple[float]
Gets or sets the boundaries (minimum and maximum) for this parameter
- property description: Optional[str]
Return a description of this parameter
- Returns:
a string cointaining a description of the meaning of this parameter
- property has_auxiliary_variable: bool
- in_unit_of(unit, as_quantity=False) Quantity [source]
Return the current value transformed to the new units
- Parameters:
unit – either an astropy.Unit instance, or a string which can be converted to an astropy.Unit instance, like “1 / (erg cm**2 s)”
as_quantity – if True, the method return an astropy.Quantity, if False just a floating point number. Default is False
- Returns:
either a floating point or a astropy.Quantity depending on the value of “as_quantity”
- internal_to_external_delta(internal_value, internal_delta)[source]
Transform an interval from the internal to the external reference (through the transformation). It is useful if you have for example a confidence interval in internal reference and you want to transform it to the external reference
- Parameters:
interval_value – value in internal reference
internal_delta – delta in internal reference
- Returns:
value and delta in external reference
- property max_value: float
Gets or sets the maximum allowed value for the parameter
- property min_value
Gets or sets the minimum allowed value for the parameter
- remove_maximum() None [source]
Remove the maximum from this parameter (i.e., it becomes boundless in the positive direction)
- remove_minimum() None [source]
Remove the minimum from this parameter (i.e., it becomes boundless in the negative direction)
- remove_transformation() None [source]
remove any transform on the parameter
useful in bayesian fits where we do not care about transformations but want speed
- Returns:
- restore_transformation() None [source]
restore the original transformation if it had been removed
- Returns:
- property static_name: str
Returns a name which will never change, even if the name of the parameter does (for example in composite functions)
:return : the static name :type : str
- property transformation: Optional[ParameterTransformation]
- property unit
Gets or sets the unit for the parameter
- property value: float
Get and sets the current value for the parameter, with or without units
- astromodels.core.parameter.accept_quantity(input_type=<class 'float'>, allow_none=False)[source]
A class-method decorator which allow a given method (typically the set_value method) to receive both a astropy.Quantity or a simple float, but to be coded like it’s always receiving a pure float in the right units. This is to give a way to avoid the huge bottleneck that are astropy.units
- Parameters:
input_type – the expected type for the input (float, int)
:param allow_none : whether to allow or not the passage of None as argument (default: False) :return: a decorator for the particular type