Package boxmin :: Package tests :: Module ModelParameters :: Class ModelParameters
[hide private]

Class ModelParameters

source code

A model has a set of parameters associated with it. Each parameter has a name, units and a value. To display fit results there is an optional title separate from the name, and an expanded description such as might show up in a tooltip for a fit user interface.

The value may be constrained by natural bounds such as depth greater than zero or volume fraction between zero and one. The value may also be constrained to be a discrete integer such as the number of repeats in a layer model, though it is still represented by a double in the fit. More complicated constraints such as interface depth less than layer depth are not supported within the model parameter structure, though they may be possible in some fitting engines.

A set of parameters with the same name, bounds, etc., can be represented as a vector.

Within the model, start with a blank set of parameters and add them one at a time using:

from numpy import array from fit import ModelParameters P = ModelParameters() P.add('P1',array('d',[1]*5),tip='P1 is a vector of 5 elements') P.add('P2',4,lo=0,hi=1,tip='P2 is bounded by [0,1]') P.add('P3',5,discrete=True,tip='P3 is an integer defaulting to 5') P.add('P4',3,units='cm',tip='P4 is measured in centimeters')

The values of the parameters can be accessed by name from the model:

P.P1[3] = 4. P.P4 = 2

Note that declaring a parameter to be discrete doesn't force the value to be integer. In fact it will be stored as a float, and the model will have to force it to be an integer when it reads it. Not all fit engines will handle discrete values properly.

The values can also be accessed by number:
P[0] = 4. P[3] = 2

Other properties can also be accessed by number, such as title, tip and bounds.

Instance Methods [hide private]
 
add(self, name, value, units=None, lo=None, hi=None, discrete=False, tip=None, title=None)
Add a parameter to a model
source code
 
bounds(self, n)
Return (lo,hi) bounds for parameter n
source code
 
name(self, n=None)
Return the name of parameter n, or the list of all names
source code
 
title(self, n=None)
Return title for parameter n or for the model if no n specified
source code
 
tip(self, n=None)
Return tip for parameter n or for the model if no n specified
source code
 
units(self, n)
Return units for parameter n
source code
 
discrete(self, n=None)
Return the indices of discrete parameters, or True if parameter n is discrete
source code
 
__len__(self) source code
 
__getitem__(self, n) source code
 
__setitem__(self, n, v) source code
 
__delitem__(self, n) source code
 
__get__(self, a) source code
 
__set__(self, a, v) source code
 
__delete__(self, a) source code
 
__contains__(self, a) source code
 
__init__(self, title, tip=None)
Construct a set of model parameters
source code