CompositeParameter
- class sherpa.models.parameter.CompositeParameter(name: str, parts: Sequence[Parameter])[source] [edit on github]
Bases:
ParameterRepresent a parameter with composite parts.
This is the base class for representing expressions that combine multiple parameters and values.
- Parameters:
- Attributes:
alwaysfrozenIs the parameter always frozen?
- default_max
- default_min
default_valThe default value of the parameter.
frozenIs the parameter currently frozen?
hard_maxThe hard maximum of the parameter.
hard_minThe hard minimum of the parameter.
linkThe link expression to other parameters, if set.
maxThe maximum value of the parameter.
minThe minimum value of the parameter.
valThe current value of the parameter.
Methods
eval()Evaluate the composite expression.
freeze()Set the
frozenattribute for the parameter.reset()Reset the parameter value and limits to their default values.
set([val, min, max, frozen, default_val, ...])Change a parameter setting.
thaw()Unset the
frozenattribute for the parameter.unlink()Remove any link to other parameters.
Notes
Composite parameters can be iterated through to find their components:
>>> p = Parameter('m', 'p', 2) >>> q = Parameter('m', 'q', 4) >>> c = (p + q) / 2 >>> c <BinaryOpParameter '(m.p + m.q) / 2'> >>> for cpt in c: ... print(type(cpt)) ... <class 'sherpa.models.parameter.BinaryOpParameter'> <class 'sherpa.models.parameter.Parameter'> <class 'sherpa.models.parameter.Parameter'> <class 'sherpa.models.parameter.ConstantParameter'>
Attributes Summary
Is the parameter always frozen?
The default value of the parameter.
Is the parameter currently frozen?
The hard maximum of the parameter.
The hard minimum of the parameter.
The link expression to other parameters, if set.
The maximum value of the parameter.
The minimum value of the parameter.
The current value of the parameter.
Methods Summary
eval()Evaluate the composite expression.
freeze()Set the
frozenattribute for the parameter.reset()Reset the parameter value and limits to their default values.
set([val, min, max, frozen, default_val, ...])Change a parameter setting.
thaw()Unset the
frozenattribute for the parameter.unlink()Remove any link to other parameters.
Attributes Documentation
- alwaysfrozen
Is the parameter always frozen?
- default_max
- default_min
- frozen
Is the parameter currently frozen?
Those parameters created with
alwaysfrozenset can not be changed.See also
- link
The link expression to other parameters, if set.
The link expression defines if the parameter is not a free parameter but is actually defined in terms of other parameters.
See also
Examples
>>> a = Parameter("mdl", "a", 2) >>> b = Parameter("mdl", "b", 1) >>> b.link = 10 - a >>> print(a.val) 2.0 >>> print(b.val) 8.0
- max
The maximum value of the parameter.
The maximum must lie between the hard_min and hard_max limits.
- min
The minimum value of the parameter.
The minimum must lie between the hard_min and hard_max limits.
- numpy_binop_with_symbols = {<ufunc 'add'>: '+', <ufunc 'divide'>: '/', <ufunc 'floor_divide'>: '//', <ufunc 'multiply'>: '*', <ufunc 'power'>: '**', <ufunc 'remainder'>: '%', <ufunc 'subtract'>: '-'}
- val
The current value of the parameter.
If the parameter is a link then it is possible that accessing the value will raise a ParameterErr in cases where the link expression falls outside the soft limits of the parameter.
See also
default_val,link,max,min
Methods Documentation
- eval() SupportsFloat[source] [edit on github]
Evaluate the composite expression.
- freeze() None [edit on github]
Set the
frozenattribute for the parameter.
- reset() None [edit on github]
Reset the parameter value and limits to their default values.
- set(val: SupportsFloat | None = None, min: SupportsFloat | None = None, max: SupportsFloat | None = None, frozen: bool | None = None, default_val: SupportsFloat | None = None, default_min: SupportsFloat | None = None, default_max: SupportsFloat | None = None) None [edit on github]
Change a parameter setting.
- Parameters:
- val
numberorNone,optional The new parameter value.
- min, max
numberorNone,optional The new parameter range.
- frozenbool or
None,optional Should the frozen flag be set?
- default_val
numberorNone,optional The new default parameter value.
- default_min, default_max
numberorNone,optional The new default parameter limits.
- val
- thaw() None [edit on github]
Unset the
frozenattribute for the parameter.- Raises:
ParameterErrThe parameter is marked as always frozen.
- unlink() None [edit on github]
Remove any link to other parameters.