Bases: object
Base class for all models.
This is an abstract class and should not be instantiated directly.
This class sets the constraints and other properties for all individual parameters and performs parameter validation.
Parameters: | name : str, optional
fixed : dict, optional
tied : dict, optional
bounds : dict, optional
eqcons : list, optional
ineqcons : list, optional
|
---|
Examples
>>> from astropy.modeling import models
>>> def tie_center(model):
... mean = 50 * model.stddev
... return mean
>>> tied_parameters = {'mean': tie_center}
Specify that 'mean' is a tied parameter in one of two ways:
>>> g1 = models.Gaussian1D(amplitude=10, mean=5, stddev=.3,
... tied=tied_parameters)
or
>>> g1 = models.Gaussian1D(amplitude=10, mean=5, stddev=.3)
>>> g1.mean.tied
False
>>> g1.mean.tied = tie_center
>>> g1.mean.tied
<function tie_center at 0x...>
Fixed parameters:
>>> g1 = models.Gaussian1D(amplitude=10, mean=5, stddev=.3,
... fixed={'stddev': True})
>>> g1.stddev.fixed
True
or
>>> g1 = models.Gaussian1D(amplitude=10, mean=5, stddev=.3)
>>> g1.stddev.fixed
False
>>> g1.stddev.fixed = True
>>> g1.stddev.fixed
True
Attributes Summary
bounds | A dict mapping parameter names to their upper and lower bounds as (min, max) tuples. |
eqcons | List of parameter equality constraints. |
fittable | |
fixed | A dict mapping parameter names to their fixed constraint. |
ineqcons | List of parameter inequality constraints. |
inputs | The name(s) of the input variable(s) on which a model is evaluated. |
inverse | Returns a new Model instance which performs the inverse transform, if an analytic inverse is defined for this model. |
linear | |
model_constraints | Primarily for informational purposes, these are the types of constraints that constrain model evaluation. |
model_set_axis | The index of the model set axis–that is the axis of a parameter array that pertains to which model a parameter value pertains to–as specified when the model was initialized. |
n_inputs | The number of inputs to this model. |
n_outputs | The number of outputs from this model. |
name | User-provided name for this model instance. |
outputs | The name(s) of the output(s) of the model. |
param_dim | Deprecated since version 0.4. |
param_names | Names of the parameters that describe models of this type. |
param_sets | Return parameters as a pset. |
parameter_constraints | Primarily for informational purposes, these are the types of constraints that can be set on a model’s parameters. |
parameters | A flattened array of all parameter values in all parameter sets. |
standard_broadcasting | |
tied | A dict mapping parameter names to their tied constraint. |
Methods Summary
__call__(*inputs, **kwargs) | Evaluate this model using the given input(s) and the parameter values that were specified when the model was instantiated. |
add_model(*args, **kwargs) | Deprecated since version 1.0. |
copy() | Return a copy of this model. |
evaluate(*args, **kwargs) | Evaluate the model on some input variables. |
prepare_inputs(*inputs, **kwargs) | This method is used in __call__ to ensure that all the inputs to the model can be broadcast into compatible shapes (if one or both of them are input as arrays), particularly if there are more than one parameter sets. |
prepare_outputs(format_info, *outputs, **kwargs) | |
rename(name) | Creates a copy of this model class with a new name. |
Attributes Documentation
List of parameter equality constraints.
List of parameter inequality constraints.
The name(s) of the input variable(s) on which a model is evaluated.
Returns a new Model instance which performs the inverse transform, if an analytic inverse is defined for this model.
Even on models that don’t have an inverse defined, this property can be set with a manually-defined inverse, such a pre-computed or experimentally determined inverse (often given as a PolynomialModel, but not by requirement).
Note to authors of Model subclasses: To define an inverse for a model simply override this property to return the appropriate model representing the inverse. The machinery that will make the inverse manually-overridable is added automatically by the base class.
Primarily for informational purposes, these are the types of constraints that constrain model evaluation.
The index of the model set axis–that is the axis of a parameter array that pertains to which model a parameter value pertains to–as specified when the model was initialized.
See the documentation on Model Sets for more details.
The number of inputs to this model.
Equivalent to len(model.inputs).
The number of outputs from this model.
Equivalent to len(model.outputs).
User-provided name for this model instance.
The name(s) of the output(s) of the model.
Deprecated since version 0.4: The param_dim function is deprecated and may be removed in a future version. Use len(model) instead.
Names of the parameters that describe models of this type.
The parameters in this tuple are in the same order they should be passed in when initializing a model of a specific type. Some types of models, such as polynomial models, have a different number of parameters depending on some other property of the model, such as the degree.
When defining a custom model class the value of this attribute is automatically set by the Parameter attributes defined in the class body.
Return parameters as a pset.
This is a list with one item per parameter set, which is an array of that parameter’s values across all parameter sets, with the last axis associated with the parameter set.
Primarily for informational purposes, these are the types of constraints that can be set on a model’s parameters.
A flattened array of all parameter values in all parameter sets.
Fittable parameters maintain this list and fitters modify it.
Methods Documentation
Evaluate this model using the given input(s) and the parameter values that were specified when the model was instantiated.
Deprecated since version 1.0: The add_model function is deprecated and may be removed in a future version. Use Use Model operators (TODO: link to compound model docs instead.
Create a CompositeModel by chaining the current model with the new one using the specified mode.
Parameters: | model : an instance of a subclass of Model mode : string
|
---|---|
Returns: | model : CompositeModel
|
Return a copy of this model.
Uses a deep copy so that all model attributes, including parameter values, are copied as well.
Evaluate the model on some input variables.
This method is used in __call__ to ensure that all the inputs to the model can be broadcast into compatible shapes (if one or both of them are input as arrays), particularly if there are more than one parameter sets.
Creates a copy of this model class with a new name.
The new class is technically a subclass of the original class, so that instance and type checks will still work. For example:
>>> from astropy.modeling.models import Rotation2D
>>> SkyRotation = Rotation2D.rename('SkyRotation')
>>> SkyRotation
<class '__main__.SkyRotation'>
Name: SkyRotation (Rotation2D)
Inputs: ('x', 'y')
Outputs: ('x', 'y')
Fittable parameters: ('angle',)
>>> issubclass(SkyRotation, Rotation2D)
True
>>> r = SkyRotation(90)
>>> isinstance(r, Rotation2D)
True