deerlab.Model

class Model(nonlinfcn, constants=None, signature=None)[source]

Represents a model.

The Model class provides a way to create a new model object from a non-linear function. The Model class also provides access to the model parameters and allows them to be modified.

Attributes:
<parameter_name>deerlab.Parameter

Model parameter. One deerlab.Parameter instance is assigned for each parameter (with name <parameter_name>) in the model.

descriptionstring

Description of the model.

signaturestring

Call signature (keyword arguments in order) of the model.

nonlinmodelcallable

Function of the non-linear part of the model.

Nnonlinint scalar

Number of non-linear parameters in the model.

Nlinint scalar

Number of linear parameters in the model.

Nparamint scalar

Number of parameters in the model.

Methods table

__init__(nonlinfcn[, constants, signature])

Construct a new model from a non-linear function.

addlinear(name[, vec, normalization, lb, ...])

Add a new linear parameter (deerlab.Parameter object) to the model.

addnonlinear(key[, lb, ub, par0, name, ...])

Add a new non-linear parameter (deerlab.Parameter object) to the model.

getmetadata()

Utility function to quickly request all metadata attributes of the model in vector form.

rename_parameter(old, new)

Rename a parameter in the model.

Methods

Model.__init__(nonlinfcn, constants=None, signature=None)[source]

Construct a new model from a non-linear function.

Parameters:
nonlinfcncallable

Function that takes a set of non-linear parameters and returns either the full model response or the design matrix of the model response. A parameter will be added to the new model for each input argument defined in the function signature.

constantsstring or list thereof, optional

Names of the arguments taken by the nonlinfcn function to be defined as constants. These will not be added as parameters to the new model.

signaturelist of strings, optional

Signature of the nonlinfcn function to manually specify the names of the input arguments. For internal use (mostly).

Returns:
modelModel object

Model object instance that takes the parameters defined for nonlinfcn and returns the output of nonlinfcn.

Model.addlinear(name, vec=1, normalization=None, lb=-inf, ub=inf, par0=None, unit=None, description=None)[source]

Add a new linear parameter (deerlab.Parameter object) to the model.

Parameters:
namestring

Identifier of the parameter. This name will be used to refer to the parameter in the model.

vecint scalar, optional

Number of elements in the parameter. If vec>1 then the parameter will represent a vector of linear parameters of length vec. By default, a scalar parameter is defined.

normalizationcallable, optional

Normalization function of the parameter. If specified, upon fitting the parameter will be normalized and an the normalization factor will be reported separately. Does not add an additional normalization factor parameter. Must be function taking the parameter and returning the normalized parameter.

lbfloat or array_like, optional

Lower bound of the parameter. For vectorized parameters, must be a vector with vec elements. If not specified, it is set to -np.inf.

ubfloat or array_like, optional

Lower bound of the parameter. For vectorized parameters, must be a vector with vec elements. If not specified, it is set to +np.inf.

descriptionstring, optional

Description of the parameter.

unitstring, optional

Physical unit of the parameter.

Model.addnonlinear(key, lb=-inf, ub=inf, par0=None, name=None, unit=None, description=None)[source]

Add a new non-linear parameter (deerlab.Parameter object) to the model.

Parameters:
keystring

Identifier of the parameter. This name will be used to refer to the parameter in the model.

lbfloat or array_like, optional

Lower bound of the parameter. If not specified, it is set to -np.inf.

ubfloat or array_like, optional

Lower bound of the parameter. If not specified, it is set to +np.inf.

descriptionstring, optional

Description of the parameter.

unitstring, optional

Physical unit of the parameter.

Model.getmetadata()[source]

Utility function to quickly request all metadata attributes of the model in vector form. All elements are sorted according to the model function signature.

Returns:
metadatadict

Dictionary containing all the model’s metadata in ordered vectors. The model keys correspond to the model attributes, e.g. metadata['lb'] corresponds to the model’s parameters lower boundaries.

Model.rename_parameter(old, new)[source]

Rename a parameter in the model.

This method renames a parameter in the model. If the old parameter name does not exist, a KeyError is raised.

Parameters:
oldstring

Old parameter name.

newstring

New parameter name.

Inherited Methods