herschel.ia.numeric.toolbox.fit
public class AbstractModel extends AbstractBasicModel
A model consists of one or more instantiations of (basic) models which
are concatenated in a chain of models using addModel(herschel.ia.numeric.toolbox.fit.AbstractModel). Almost all
methods defined in AbstractBasicModel are overwritten here,
recursively calling the AbstractBasicModel's methods.
An AbstractModel contains a NoiseScale, a measure of the noise.
As the AbstractModel is the last in line of the general, unspecific models it contains a number of Jython hooks and some methods to test the validity of partial derivatives against numerically calculated derivatives.
AbstractModel also implements a numerical derivation of partial to be used when partial is not given in the model definition itself. This same numerical derivation of partial is used in testPartial to indeed test whether the partial has been implemented properly.
| Constructor and Description |
|---|
AbstractModel(AbstractModel model)
AbstractModel copy constructor.
|
AbstractModel(int nparams)
AbstractModel.
|
AbstractModel(int nparams,
int ndim)
AbstractModel.
|
| Modifier and Type | Method and Description |
|---|---|
Double1d |
__call__(ModelInput x)
Jython wrapper method for returning the result of the model.
|
Double1d |
__call__(NumericData x)
Jython wrapper method for returning the result of the model.
|
double |
__getitem__(int i)
Jython wrapper method returning the i-th parameter.
|
AbstractModel |
__iadd__(AbstractModel model)
Jython wrapper method for making compound models using += operator.
|
AbstractModel |
__idiv__(AbstractModel model)
Jython wrapper method for making compound models using /= operator.
|
AbstractModel |
__imul__(AbstractModel model)
Jython wrapper method for making compound models using *= operator.
|
AbstractModel |
__isub__(AbstractModel model)
Jython wrapper method for making compound models using -= operator.
|
void |
addModel(AbstractModel model)
Make a compound model by concatinating/adding model to this.
|
double |
calc(double input)
Return the result of the model given the input.
|
void |
checkLimits(Double1d fitpar)
Checks whether the parameters are within limits.
|
void |
checkLimits(Double1d fitpar,
Int1d parlist)
Checks whether the parameters are within limits.
|
AbstractModel |
copy()
Return a copy.
|
void |
divideModel(AbstractModel model)
Make a compound model by concatinating/dividing by a model.
|
Double1d |
domain2Unit(Double1d dvalue)
Convert parameter values to unit-domain values.
|
double |
domain2Unit(double dvalue,
int kpar)
Convert a value within the domain of the parameter to one in [0,1].
|
Int1d |
getFitIndex()
Returns the indices of parameters to be fitted for the (compound) model.
|
Double1d |
getFitParameters()
Returns (fitted) parameters of the model.
|
double |
getFitParameters(int i)
Returns fitted parameter i of the model.
|
AbstractModel |
getHead()
Return the head of the Compound model.
|
double |
getHighLimit(int kpar)
Return the upper limit for the parameter.
|
Double1d |
getHighLimits()
Return upper limits for this model.
|
Unit<?> |
getIntegralUnit()
Return the integrated Unit.
|
IndexSet |
getLinearIndex()
Return null.
|
double |
getLowLimit(int kpar)
Return the lower limit for the parameter.
|
Double1d |
getLowLimits()
Return lower limits for this model.
|
AbstractModel |
getNext()
Return the next Model of a Compound model; null if none left.
|
NoiseScale |
getNoiseScale()
Return the noise scale class pertaining to this model.
|
int |
getNumberOfFittedParameters()
Returns the number of parameters to be fitted.
|
int |
getNumberOfParameters()
Returns the number of parameters of the (compound) model.
|
int |
getOperation()
Return the operation to be performed with next Model.
|
java.lang.String |
getParameterName(int k)
Return the name of the indicated parameter.
|
Double1d |
getParameters()
Returns (present) parameters of the (Compound) model.
|
Double1d |
getParameters(Double1d fitpar)
Returns parameters of the (compound) model, adapted to fixed parameters.
|
Unit<?> |
getParameterUnit(int k)
Return the unit of the indicated parameter.
|
AbstractPrior |
getPrior(int k)
Return the prior of the indicated parameter.
|
PriorList |
getPriorList()
Return the list of Priors.
|
Double1d |
getPriorRange()
Returns the (prior) range for the parameters of the model.
|
Double1d |
getStandardDeviations()
Returns (present) standard deviations for the parameters of the (Compound) model.
|
Unit<?> |
getXUnit(int k)
Return the unit of the independent (X) variables.
|
Unit<?> |
getYUnit()
Return the unit of the dependent (Y) variable.
|
boolean |
hasHighLimit(int kpar)
Return true if a upper limit is present for the parameter.
|
boolean |
hasLimits()
Return true if limits has been set for this model.
|
boolean |
hasLimits(Int1d fitindex)
Return true if limits has been set for this model.
|
boolean |
hasLowLimit(int kpar)
Return true if a lower limits is present for the parameter.
|
boolean |
isMixed()
Return false.
|
AbstractModel |
isolateModel(int k)
Return a (isolated) copy of the k-th model in the chain.
|
void |
keepFixed(Int1d fixed)
Keeps parameters fixed at the present values.
|
void |
keepFixed(Int1d fixed,
Double1d values)
Keeps parameters fixed at the provided values.
|
int |
length()
Return length of the chain.
|
void |
multiplyModel(AbstractModel model)
Make a compound model by concatinating/multiplying a model with this.
|
Double2d |
numPartial(ModelInput input,
Double1d fitpar)
Returns numerical partial derivatives of the model function.
|
Double2d |
partial(ModelInput input,
Double1d fitpar)
Return the partial derivs of the model at the ModelInput
|
Double2d |
partial(NumericData input,
Double1d fitpar)
Returns the partial derivatives calculated at the inputs.
|
Double1d |
partialDomain2Unit(Double1d dvalue)
Return a the derivate of the domain2Unit function to dval.
|
Double1d |
result(ModelInput input)
Returns the model values applied to the inputs.
|
Double1d |
result(ModelInput input,
Double1d fitpar)
Return the result of the model as applied to a ModelInput.
|
Double1d |
result(NumericData input)
Returns the model values applied to the inputs.
|
Double1d |
result(NumericData input,
Double1d fitpar)
Returns the model values applied to the inputs and params.
|
void |
setFitIndex(Int1d fitindex)
Sets the indices of parameters to be fitted for the (compound) model.
|
void |
setLimits(Double1d lolimits,
Double1d hilimits)
Sets the limits for the parameters of the compound model.
|
void |
setNoiseScale(NoiseScale ns)
Set the noise scale class to this model.
|
void |
setParameters(Double1d fitpar)
Sets (initial) parameters of the (compound) model.
|
void |
setPriorRange(Double1d range)
Sets the (prior) range for the parameters of the model.
|
void |
setPriors(AbstractPrior prior)
Set the priors on the parameters.
|
void |
setPriors(PriorList priors)
Set the priors on the parameters.
|
void |
setStandardDeviations(Double1d stdev)
Sets standard deviations for the parameters of the model.
|
void |
setUnits(java.util.ArrayList<Unit<?>> listxu,
Unit<?> yu)
Set the Units for x and y variables.
|
void |
setUnits(Unit<?> xu,
Unit<?> yu)
Set the Units for x and y variables.
|
Double1d |
stayInLimits(Double1d oldpar,
Double1d trypar,
Int1d parlist)
Return parameters guaranteed to be within limits.
|
Double1d |
stayInLimits(Double1d fitpar,
Int1d parlist)
Return parameters where out-of-bounds are replaced by limits.
|
void |
subtractModel(AbstractModel model)
Make a compound model by concatinating/subtracting a model from this.
|
void |
testPartial(double[] input,
Double1d params)
A test routine to check the calculation of the partial derivatives.
|
void |
testPartial(double input,
Double1d params)
A test routine to check the calculation of the partial derivatives.
|
void |
testPartial(int input,
Double1d params) |
void |
testPartial(ModelInput input,
Double1d params)
A test routine to check the calculation of the partial derivatives.
|
void |
testPartial(NumericData input,
Double1d params)
A test routine to check the calculation of the partial derivatives.
|
java.lang.String |
toString()
Returns a string representation of the model.
|
Double1d |
unit2Domain(Double1d uvalue)
Convert parameter values to unit-domain values.
|
double |
unit2Domain(double uvalue,
int kpar)
Convert a value in [0,1] to one inside the limits of the parameter.
|
void |
unsetLimits()
Unset the limits for the parameters.
|
public AbstractModel(int nparams)
nparams - the number of parameters in this modelpublic AbstractModel(int nparams,
int ndim)
nparams - the number of parameters in this modelndim - the dimensionality of the inputspublic AbstractModel(AbstractModel model)
model - to be copiedpublic AbstractModel copy()
public int getOperation()
public AbstractModel getNext()
public AbstractModel getHead()
public int length()
public AbstractModel isolateModel(int k)
k - the model number (head = 0)java.lang.IndexOutOfBoundsException - when the chain is shorter than k.public void addModel(AbstractModel model)
The final result is the sum of the individual results.
The compound model is implemented as a chain of AbstractBasicModels.
Each of these basic models contain the attributes (parameters, limits etc.)
and when needed these attributes are taken from there, or stored there.
The operation (addition in this case) is always with the total result of the
existing chain. For the use of "brackets" in a chain use ContainerModel.
model - to be added to thisjava.lang.IllegalArgumentException - when a model of a different dimensionality
is offered.public void subtractModel(AbstractModel model)
The final result is the difference of the models.
model - to be subtracted from thisjava.lang.IllegalArgumentException - when a model of a different dimensionality
is offered.addModelpublic void multiplyModel(AbstractModel model)
The final result is the product of the models.
model - to be multiplied byjava.lang.IllegalArgumentException - when a model of a different dimensionality
is offered.addModelpublic void divideModel(AbstractModel model)
The final result is the division of the models.
model - to be divided byjava.lang.IllegalArgumentException - when a model of a different dimensionality
is offered.addModelpublic Double1d result(ModelInput input,
Double1d fitpar)
input - ModelInputfitpar - for the modelpublic Double1d result(NumericData input,
Double1d fitpar)
input - the values at which the model should be calculatedfitpar - the for which the model should be calculatedpartial(NumericData, Double1d )public Double1d result(NumericData input)
input - the values at which the model should be calculatedpublic Double1d result(ModelInput input)
input - the values at which the model should be calculatedpublic Double2d partial(ModelInput input,
Double1d fitpar)
input - an input vector or arrayfitpar - for the modelpublic Double2d partial(NumericData input,
Double1d fitpar)
input - the values at which the partials should be calculatedfitpar - the parameters for which the partials should be calculatedresult(NumericData,Double1d)public java.lang.String toString()
public void keepFixed(Int1d fixed)
fixed - list of parameter indices to be kept fixed
(any order)keepFixed( Int1d, Double1d )public void keepFixed(Int1d fixed,
Double1d values)
fixed - list of parameter indices to be kept fixed
(any order)values - at which the parameters should be kept.
length of values <= length of fixed;
the remainder is left as is. They should be in the proper
order (that of the model).java.lang.IndexOutOfBoundsException - when a fixed index is out of range.public int getNumberOfParameters()
public int getNumberOfFittedParameters()
public Int1d getFitIndex()
public void setFitIndex(Int1d fitindex)
fitindex - the indicespublic void setParameters(Double1d fitpar)
fitpar - values for the parametersjava.lang.IndexOutOfBoundsException - when fitpar is too long.public Double1d getParameters(Double1d fitpar)
fitpar - fitted parameters.public Double1d getParameters()
public void setStandardDeviations(Double1d stdev)
stdev - for the parametersjava.lang.IndexOutOfBoundsException - when stdev is too longpublic Double1d getStandardDeviations()
public Double1d getFitParameters()
public double getFitParameters(int i)
i - index of the parameter to be returnedpublic Double2d numPartial(ModelInput input,
Double1d fitpar)
input - (single value)fitpar - a parameters vectorpublic void setPriors(AbstractPrior prior)
prior - all parameters get a copy.public void setPriors(PriorList priors)
priors - array of priors, same length as the parameterspublic PriorList getPriorList()
public AbstractPrior getPrior(int k)
k - parameter number.public java.lang.String getParameterName(int k)
k - parameter number.public Unit<?> getParameterUnit(int k)
k - parameter number.public Unit<?> getIntegralUnit()
k - the index of the parameterpublic void setUnits(Unit<?> xu, Unit<?> yu)
xu - unit for the x variableyu - unit for the y variablepublic void setUnits(java.util.ArrayList<Unit<?>> listxu, Unit<?> yu)
listxu - list of units for the x variableyu - unit for the y variablepublic Unit<?> getXUnit(int k)
k - the k-th dimension of Xpublic Unit<?> getYUnit()
public void setPriorRange(Double1d range)
range - public Double1d getPriorRange()
public void setNoiseScale(NoiseScale ns)
ns - the noise scale.public NoiseScale getNoiseScale()
public void setLimits(Double1d lolimits,
Double1d hilimits)
Note: Limits will also work when the model is used in a Minimizer. In that case the limits apply to the minimization range.
lolimits - lower limitshilimits - upper limitspublic void unsetLimits()
public boolean hasLowLimit(int kpar)
kpar - parameter indexpublic boolean hasHighLimit(int kpar)
kpar - parameter indexpublic double getLowLimit(int kpar)
kpar - parameter indexpublic double getHighLimit(int kpar)
kpar - parameter indexpublic Double1d getLowLimits()
public Double1d getHighLimits()
public boolean hasLimits(Int1d fitindex)
fitindex - list of indices to be fitted.public boolean hasLimits()
public Double1d stayInLimits(Double1d oldpar,
Double1d trypar,
Int1d parlist)
If out-of-limits the parameter is replaced by the midpoint between the old parameter and the limit.
oldpar - old parameters (must be inside limits)fitpar - parameters to be checkedfitindex - indices of the fitable parameterspublic Double1d stayInLimits(Double1d fitpar,
Int1d parlist)
fitpar - parameters to be checkedfitindex - indices of the fitable parameterspublic void checkLimits(Double1d fitpar)
fitpar - parameters to be checkedjava.lang.IllegalArgumentException - when out of limits.public void checkLimits(Double1d fitpar,
Int1d parlist)
fitpar - parameters to be checkedparlist - indices of the fitable parametersjava.lang.IllegalArgumentException - when out of limits.public double unit2Domain(double uvalue,
int kpar)
uvalue - value in [0,1]kpar - index of the parameterpublic Double1d unit2Domain(Double1d uvalue)
dvalue - parameter arraypublic double domain2Unit(double dvalue,
int kpar)
dvalue - value of parameterkpar - index of the parameterpublic Double1d domain2Unit(Double1d dvalue)
dvalue - parameter arraypublic Double1d partialDomain2Unit(Double1d dvalue)
dvalue - parameter arraypublic double calc(double input)
input - the input.public boolean isMixed()
public IndexSet getLinearIndex()
public double __getitem__(int i)
i - index for the parameter.#getParameter( int )public Double1d __call__(NumericData x)
x - apply the model to xresult( NumericData )public Double1d __call__(ModelInput x)
x - apply the model to xresult( ModelInput )public AbstractModel __iadd__(AbstractModel model)
model - a model to add to this (the existing chain)addModel( AbstractModel )public AbstractModel __isub__(AbstractModel model)
model - a model to subtract from this (the existing chain)addModel( AbstractModel )public AbstractModel __imul__(AbstractModel model)
model - a model to multiply with this (the existing chain)multiplyModel( AbstractModel )public AbstractModel __idiv__(AbstractModel model)
model - a model to divide this (the existing chain) bydivideModel( AbstractModel )public void testPartial(double input,
Double1d params)
input - value of the independent variableparams - parameters for the modelpublic void testPartial(int input,
Double1d params)
public void testPartial(double[] input,
Double1d params)
input - value of the independent variableparams - parameters for the modelpublic void testPartial(NumericData input,
Double1d params)
input - values of the independent variableparams - parameters for the modelpublic void testPartial(ModelInput input,
Double1d params)
input - values of the independent variableparams - parameters for the model