astropy:docs

Model

class astropy.modeling.Model(*args, **kwargs)[source] [edit on github]

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:

param_dim : int

Number of parameter sets

fixed : dict

Dictionary {parameter_name: bool} setting the fixed constraint for one or more parameters. True means the parameter is held fixed during fitting and is prevented from updates once an instance of the model has been created.

Alternatively the fixed property of a parameter may be used to lock or unlock individual parameters.

tied : dict

Dictionary {parameter_name: callable} of parameters which are linked to some other parameter. The dictionary values are callables providing the linking relationship.

Alternatively the tied property of a parameter may be used to set the tied constraint on individual parameters.

bounds : dict

Dictionary {parameter_name: value} of lower and upper bounds of parameters. Keys are parameter names. Values are a list of length 2 giving the desired range for the parameter.

Alternatively the min and max or ~astropy.modeling.Parameter.bounds` properties of a parameter may be used to set bounds on individual parameters.

eqcons : list

List of functions of length n such that eqcons[j](x0, *args) == 0.0 in a successfully optimized problem.

ineqcons : list

List of functions of length n such that ieqcons[j](x0, *args) >= 0.0 is a successfully optimized problem.

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 bool(x) -> bool
fixed A dict mapping parameter names to their fixed constraint.
ineqcons List of parameter inequality constraints.
linear bool(x) -> bool
model_constraints list() -> new empty list
model_set_axis
n_inputs int(x[, base]) -> integer
n_outputs int(x[, base]) -> integer
param_dim

Deprecated since version 0.4.

param_names list() -> new empty list
param_sets Return parameters as a pset.
parameter_constraints list() -> new empty list
parameters A flattened array of all parameter values in all parameter sets.
standard_broadcasting bool(x) -> bool
tied A dict mapping parameter names to their tied constraint.

Methods Summary

__call__(*args, **kwargs) Evaluate the model on some input variables.
add_model(model, mode) Create a CompositeModel by chaining the current model with the new one using the specified mode.
copy() Return a copy of this model.
inverse() Returns a callable object which performs the inverse transform.
invert() Invert coordinates iteratively if possible.

Attributes Documentation

bounds

A dict mapping parameter names to their upper and lower bounds as (min, max) tuples.

eqcons

List of parameter equality constraints.

fittable = False
fixed

A dict mapping parameter names to their fixed constraint.

ineqcons

List of parameter inequality constraints.

linear = True
model_constraints = [u'eqcons', u'ineqcons']
model_set_axis
n_inputs = 1
n_outputs = 1
param_dim

Deprecated since version 0.4: The param_dim function is deprecated and may be removed in a future version. Use len(model) instead.

param_names = []

List of names of the parameters that describe models of this type.

The parameters in this list 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.

param_sets

Return parameters as a pset.

This is an array where each column represents one parameter set.

parameter_constraints = [u'fixed', u'tied', u'bounds']
parameters

A flattened array of all parameter values in all parameter sets.

Fittable parameters maintain this list and fitters modify it.

standard_broadcasting = True
tied

A dict mapping parameter names to their tied constraint.

Methods Documentation

__call__(*args, **kwargs)[source] [edit on github]

Evaluate the model on some input variables.

add_model(model, mode)[source] [edit on github]

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

‘parallel’, ‘serial’, ‘p’ or ‘s’ a flag indicating whether to combine the models in series or in parallel

Returns:

model : CompositeModel

an instance of CompositeModel

copy()[source] [edit on github]

Return a copy of this model.

Uses a deep copy so that all model attributes, including parameter values, are copied as well.

inverse()[source] [edit on github]

Returns a callable object which performs the inverse transform.

invert()[source] [edit on github]

Invert coordinates iteratively if possible.

Page Contents