pymodelfit.core.ModelSequence

class pymodelfit.core.ModelSequence(models, extraparams=None, outputcontraction=None, interpolation='linear', interpolationdirection='y', offgrid=None)[source]

Bases: object

A group of models with attached parameters that can be used to infer the parameter values at an arbitrary point in the space defined by the models.

models must be a sequence of models or a 2-tuple with the second element a dictionary. If a model sequnce, they must all have the same parameter names and have compatible inputs. Otherwise, the first element specifies the type of model to use, and the second is a dictionary mapping parameter names to a sequence of parameter values.

The resultant models are expected to be a “sequence” in the sense that they can be interpolated across to get a meaningful parameter value between two models (e.g. double-valued model grids are not meaningful)

extraparams are parameters not a part of the model that are still available to be interpolated over. It must be None or a dictionary with values that are the same length as the model sequence.

output contraction can be either a function to call on the output of the models returning a scalar, None to do nothing to the output, ‘dist’ to use the euclidian distance (e.g. sqrt(sum(output**2)), or ‘sqdist’ to use the square of the distance.

interpolation may be either ‘linear’ for simple linear interpolation along the y-axis, or a 1D Model that will be fit with fitData on the contracted outputs.

interpolationdirection determines the direction along which interpolation is to be performed, and can be:

  • ‘y’: interpolate along the output axis (by far the fastest method)

  • ‘x’: interpolate along the input axis - requires that inv be defined

    for the models

  • ‘perp’: interpolate along the perpendicular of the tangent line for

    the closest model to the data point. Only meaningful for FunctionModel1D Models.

offgrid determines the behavior if a location is requested that is beyond the limits of the model sequence. It can be:

  • ‘raise’: raises a ValueError
  • ‘warn’: issue a warning
  • None: just output whatever the interpolating function provides - for linear interpolation, this takes the closest value.
__init__(models, extraparams=None, outputcontraction=None, interpolation='linear', interpolationdirection='y', offgrid=None)[source]

models must be a sequence of models or a 2-tuple with the second element a dictionary. If a model sequnce, they must all have the same parameter names and have compatible inputs. Otherwise, the first element specifies the type of model to use, and the second is a dictionary mapping parameter names to a sequence of parameter values.

The resultant models are expected to be a “sequence” in the sense that they can be interpolated across to get a meaningful parameter value between two models (e.g. double-valued model grids are not meaningful)

extraparams are parameters not a part of the model that are still available to be interpolated over. It must be None or a dictionary with values that are the same length as the model sequence.

output contraction can be either a function to call on the output of the models returning a scalar, None to do nothing to the output, ‘dist’ to use the euclidian distance (e.g. sqrt(sum(output**2)), or ‘sqdist’ to use the square of the distance.

interpolation may be either ‘linear’ for simple linear interpolation along the y-axis, or a 1D Model that will be fit with fitData on the contracted outputs.

interpolationdirection determines the direction along which interpolation is to be performed, and can be:

  • ‘y’: interpolate along the output axis (by far the fastest method)

  • ‘x’: interpolate along the input axis - requires that inv be defined

    for the models

  • ‘perp’: interpolate along the perpendicular of the tangent line for

    the closest model to the data point. Only meaningful for FunctionModel1D Models.

offgrid determines the behavior if a location is requested that is beyond the limits of the model sequence. It can be:

  • ‘raise’: raises a ValueError
  • ‘warn’: issue a warning
  • None: just output whatever the interpolating function provides - for linear interpolation, this takes the closest value.

Methods

__init__(models[, extraparams, ...]) models must be a sequence of models or a 2-tuple with the second
getParam(x, y[, parnames, contracty]) Computes the value of a requested parameter at the provided point in the input/output space of the models.
getParamArray(parnames) Generates an array of values for the requested parameter corresponding to each of the models.
getParams(xs, ys[, parnames, contracty]) Get parameters for an array of inputs - xs and ys should be matching sequences which each item matches the input and ouptut types of the models.
plot1D([x1, x2, legend, clf, n]) Plots the models in this ModelSequence assuming the models are 1D

Attributes

extraparams A tuple of the possible extra parameter names for this ModelSequence or
interpolation
interpolationdirection
offgrid
outputcontraction
params a tuple of the possible parameter names for this ModelSequence
extraparams None[source]

A tuple of the possible extra parameter names for this ModelSequence or None if there are none

getParam(x, y, parnames=None, contracty=True)[source]

Computes the value of a requested parameter at the provided point in the input/output space of the models.

parnames can be a single parameter name (output is then a scalar), a stirng with a comma-seperated list of parameters, a sequence of parameter names, or None to get a dictionary mapping parameter names to their value at the provided point

x and y should be inputs and outputs, respectively, of the Model objects that define this sequence.

if contracty is True, the output contraction will be applied to the provided y-value. Otherwise, it should be a scalar.

getParamArray(parnames)[source]

Generates an array of values for the requested parameter corresponding to each of the models.

parnames can be a single parameter name (output is then a scalar), a stirng with a comma-seperated list of parameters, a sequence of parameter names, or None to get a dictionary mapping parameter names to their arrays

getParams(xs, ys, parnames=None, contracty=True)[source]

Get parameters for an array of inputs - xs and ys should be matching sequences which each item matches the input and ouptut types of the models. For more info, see ModelSequence.getParam

params None[source]

a tuple of the possible parameter names for this ModelSequence

plot1D(x1=None, x2=None, legend=False, clf=True, n=100, **kwargs)[source]

Plots the models in this ModelSequence assuming the models are 1D

x1 and x2 are the upper and lower limits to the plot. If not specified, the rangehints for the models will be used

The output contraction function will be used to compute the y-axis.

legend determines if the legend with parameter value should be shown on the plot

kwargs are passed into the models’ plot method (except for n)

Previous topic

pymodelfit.core.CompositeModel2DScalar

Next topic

pymodelfit.core.register_model

This Page