vec_math
Class ExpressionFit.AmoebaModel

java.lang.Object
  extended by vec_math.ExpressionFit.AmoebaModel
All Implemented Interfaces:
DataModel
Enclosing class:
ExpressionFit

protected static class ExpressionFit.AmoebaModel
extends Object
implements DataModel

A multidimensional that evaluates a function f given as a string like

       a0*cos(a1*$t+a2)
       
on all input data, such that it returns
       Σ(y_i-y_av-f_i)&pow2;
       
The independet variable is always at index zero in the input data, and the dependent y_i is at the index provided at construct.


Field Summary
private  VectorG[] data
          Input data, on each VectorG only zero and yindex is used.
private  ExpressionNode fit
          The expression that is the model.
static String TIME
          The name of the independant variable in the expression.
private  double yav
          The average of the dependant variable.
private  int yindex
          The index of the dependant variable.
 
Constructor Summary
protected ExpressionFit.AmoebaModel(String model)
          Only constructs with an expression node.
  ExpressionFit.AmoebaModel(String model, VectorG[] mag, int y)
          Constructs a new Amoeba Model.
 
Method Summary
 double evaluateModel(VectorG a, VectorG time)
          Returns the model at a single point.
 int getMeasureCount()
          The number of dimensions is the variables count minus one.
 double[] getMeasurementErrors()
          Returns null.
 double[] getMeasures()
          Returns the measures.
 double[] getModel(VectorG a)
          The model
private  double[] getModelAtData(VectorG a)
          Returns the current model fit at all data points.
 int getParameterCount()
          The number of dimensions is the variables count minus one.
 double[] getResiduals(VectorG a)
          Returns the residuals of the measures to the data model.
 VectorG[] getTimes()
          Returns the times, this is an array of 1-d vectors initialized to data[].0.
 double[] getTotalErrors()
          Returns null.
private  String printModel(VectorG a)
          We convert the expression parsed for printing, and during evaluate.
protected  boolean setModelData(VectorG[] matrix)
          Sets the model data and the model index.
protected  boolean setModelIndex(int yi)
          Sets the model data index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIME

public static final String TIME
The name of the independant variable in the expression.

See Also:
Constant Field Values

data

private VectorG[] data
Input data, on each VectorG only zero and yindex is used.


yindex

private int yindex
The index of the dependant variable.


yav

private double yav
The average of the dependant variable.


fit

private ExpressionNode fit
The expression that is the model.

Constructor Detail

ExpressionFit.AmoebaModel

public ExpressionFit.AmoebaModel(String model,
                                 VectorG[] mag,
                                 int y)
                          throws ParseException
Constructs a new Amoeba Model.

Throws:
ParseException

ExpressionFit.AmoebaModel

protected ExpressionFit.AmoebaModel(String model)
                             throws ParseException
Only constructs with an expression node. Is protected to hinder unauthorized use. Subclasses must ensure that the model data and index is set, according to setModelData(vec_math.VectorG[]) and setModelIndex(int) before this multidimensional is used.

Throws:
ParseException
Method Detail

setModelData

protected boolean setModelData(VectorG[] matrix)
Sets the model data and the model index. Only after a call to this method and setModelIndex(int), the amoeba model may be used.

Returns:
True, if model can be used now.

setModelIndex

protected boolean setModelIndex(int yi)
Sets the model data index. . Only after a call to this method and setModelData(vec_math.VectorG[]), the amoeba model may be used.

Returns:
True, if model can be used now.

getParameterCount

public int getParameterCount()
The number of dimensions is the variables count minus one.

Specified by:
getParameterCount in interface DataModel
Returns:
The number of parameters in the model. This equals the dimension of the input vector in DataModel.getModel(vec_math.VectorG).

getMeasureCount

public int getMeasureCount()
The number of dimensions is the variables count minus one.

Specified by:
getMeasureCount in interface DataModel
Returns:
The number of measurements in the data model. This equals the dimension of the return vector in DataModel.getModel(vec_math.VectorG).

getMeasures

public double[] getMeasures()
Returns the measures.

Specified by:
getMeasures in interface DataModel

getTotalErrors

public double[] getTotalErrors()
Returns null.

Specified by:
getTotalErrors in interface DataModel

getMeasurementErrors

public double[] getMeasurementErrors()
Returns null.

Specified by:
getMeasurementErrors in interface DataModel

getTimes

public VectorG[] getTimes()
Returns the times, this is an array of 1-d vectors initialized to data[].0.

Specified by:
getTimes in interface DataModel
Returns:
An array of dimension DataModel.getMeasureCount().

getModel

public double[] getModel(VectorG a)
The model

Specified by:
getModel in interface DataModel
Parameters:
a - The model parameters
Returns:
A model for the data points depending on the model parameters.

getResiduals

public double[] getResiduals(VectorG a)
Returns the residuals of the measures to the data model. This equals calling getMeasures() and getModel(vec_math.VectorG) and returning the difference between both.

Specified by:
getResiduals in interface DataModel
Parameters:
a - The model parameters, not necessarily the best fit.

getModelAtData

private double[] getModelAtData(VectorG a)
                         throws ParseException
Returns the current model fit at all data points.

Throws:
ParseException

evaluateModel

public double evaluateModel(VectorG a,
                            VectorG time)
Returns the model at a single point.

Specified by:
evaluateModel in interface DataModel
Parameters:
a - The model parameters
time - The (one)dimensional vector of independant variables.

printModel

private String printModel(VectorG a)
We convert the expression parsed for printing, and during evaluate.