vec_math
Class HarmonicFit

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by vec_math.AbstractFit
                  extended by vec_math.HarmonicFit
All Implemented Interfaces:
Cloneable, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, ModelFitting

public class HarmonicFit
extends AbstractFit

A fit to a cosine wave with phase shift, variable period to the input data. If writtn as

   y_fit=c_0+a_0*cos(ωt)+b_0*sin(ωt),
   
the fitting function y_fit is linear in its three parameters a_0, b_0, and c_0 and only non-linear in ω. Nevertheless, this non-linearity renders this fit much more demanding then the pure linear fit PhaseRegression, where the period is held fixed. In applications, where the period is known a priori, this latter class should be used for fitting. This fitter should be used mainly for sparse data, to improve a vaguely defined period. We assign variable names according to OFFSET, AMPLITUDE, and T0, where t0 and amplitude are calculated from the linear parameters as
   amplitude²=a_0²+b_0²
   tan(ωt_0)=b_0/a_0;
   


Nested Class Summary
private static class HarmonicFit.HarmonicModel
          Our data model.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
static String AMPLITUDE
          The name of the amplitude constant.
private static int DEFTINDEX
          Default time index.
private static String DEFUNITAMPLITUDE
          Default units of the parameters.
private static String DEFUNITOFFSET
          Default units of the parameters.
private static String DEFUNITPERIOD
          Default units of the parameters.
private static String DEFUNITPHASE
          Default units of the parameters.
private static int DEFYINDEX
          Default y index.
private  List<Variable> fitted
          The fitted values to C+A*cos(2pi/P*t+PHI).
static String KEY_EPSILON
          Default improvement in chi-2 to induce terminating loop.
static String KEY_EXTERNALERROR
          Default external error.
static String KEY_ITER
          Default number of maximum iteration in levenberg-marquardt.
static String KEY_LAMBDA
          Default starting value for the 'fudge factor' boosting hessian.
static String KEY_PERIOD
          This is the main fitting parameter.
static String KEY_TERMINATE
          Default number of maximum improvements, if epsilon is reached.
static String KEY_TINDEX
          The index of the time, defaults to zero.
static String KEY_UNITAMPLITUDE
          The units of the parameters.
static String KEY_UNITOFFSET
          The units of the parameters.
static String KEY_UNITPERIOD
          The units of the parameters.
static String KEY_UNITPHASE
          The units of the parameters.
static String KEY_YINDEX
          The index of the measure, defaults to one.
static String OFFSET
          The name of the offset constant.
static String PERIOD
          period constant.
private  HarmonicFit.HarmonicModel phasemodel
          The model.
static String T0
          The name of the phase constant.
 
Fields inherited from class vec_math.AbstractFit
KEY_DEFAULTERROR, KEY_DEFAULTFORMAT, KEY_ERRORFORMAT, KEY_PARAMETERFORMAT
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
HarmonicFit(Map<String,String> prop)
          Constructs a new regression analyser.
 
Method Summary
 List<Variable> fit()
          We fit the amplitude and phase plus mgnitude offset only, the period stays constant.
 DataModel getDataModel()
          Returns the phase model.
 List<Variable> getFittedParameters()
          Returns the fitted parameters.
 DataModel prepareFit(VectorG[] in)
          Visualization means performing a linear Regression using GeneralRegression#harmonic.
 boolean setInitialCondition(Variable p)
          We need the period as an initial condition.
 
Methods inherited from class vec_math.AbstractFit
formatError, formatValue, getChi2, getModelParameterErrors, getModelParameterValues, getR2, getRms, init, qualityOfFit, setConstant
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 

Field Detail

PERIOD

public static final String PERIOD
period constant.

See Also:
Constant Field Values

AMPLITUDE

public static final String AMPLITUDE
The name of the amplitude constant.

See Also:
Constant Field Values

OFFSET

public static final String OFFSET
The name of the offset constant.

See Also:
Constant Field Values

T0

public static final String T0
The name of the phase constant.

See Also:
Constant Field Values

KEY_UNITAMPLITUDE

public static final String KEY_UNITAMPLITUDE
The units of the parameters.

See Also:
Constant Field Values

KEY_UNITPHASE

public static final String KEY_UNITPHASE
The units of the parameters.

See Also:
Constant Field Values

KEY_UNITPERIOD

public static final String KEY_UNITPERIOD
The units of the parameters.

See Also:
Constant Field Values

KEY_UNITOFFSET

public static final String KEY_UNITOFFSET
The units of the parameters.

See Also:
Constant Field Values

KEY_PERIOD

public static final String KEY_PERIOD
This is the main fitting parameter.

See Also:
Constant Field Values

KEY_TINDEX

public static final String KEY_TINDEX
The index of the time, defaults to zero.

See Also:
Constant Field Values

KEY_YINDEX

public static final String KEY_YINDEX
The index of the measure, defaults to one.

See Also:
Constant Field Values

KEY_ITER

public static final String KEY_ITER
Default number of maximum iteration in levenberg-marquardt.

See Also:
Constant Field Values

KEY_TERMINATE

public static final String KEY_TERMINATE
Default number of maximum improvements, if epsilon is reached.

See Also:
Constant Field Values

KEY_EPSILON

public static final String KEY_EPSILON
Default improvement in chi-2 to induce terminating loop.

See Also:
Constant Field Values

KEY_LAMBDA

public static final String KEY_LAMBDA
Default starting value for the 'fudge factor' boosting hessian.

See Also:
Constant Field Values

KEY_EXTERNALERROR

public static final String KEY_EXTERNALERROR
Default external error.

See Also:
Constant Field Values

DEFTINDEX

private static final int DEFTINDEX
Default time index.

See Also:
Constant Field Values

DEFYINDEX

private static final int DEFYINDEX
Default y index.

See Also:
Constant Field Values

DEFUNITPERIOD

private static final String DEFUNITPERIOD
Default units of the parameters.

See Also:
Constant Field Values

DEFUNITAMPLITUDE

private static final String DEFUNITAMPLITUDE
Default units of the parameters.

See Also:
Constant Field Values

DEFUNITPHASE

private static final String DEFUNITPHASE
Default units of the parameters.

See Also:
Constant Field Values

DEFUNITOFFSET

private static final String DEFUNITOFFSET
Default units of the parameters.

See Also:
Constant Field Values

fitted

private List<Variable> fitted
The fitted values to C+A*cos(2pi/P*t+PHI).


phasemodel

private HarmonicFit.HarmonicModel phasemodel
The model.

Constructor Detail

HarmonicFit

public HarmonicFit(Map<String,String> prop)
Constructs a new regression analyser.

Method Detail

setInitialCondition

public boolean setInitialCondition(Variable p)
We need the period as an initial condition.

Specified by:
setInitialCondition in interface ModelFitting
Overrides:
setInitialCondition in class AbstractFit
Returns:
false, if the initial condition does not apply to this model.

prepareFit

public DataModel prepareFit(VectorG[] in)
Visualization means performing a linear Regression using GeneralRegression#harmonic. The three linear parameters are fit into three fitting parameters OFFSET, AMPLITUDE, and #PHASE, where phase and amplitude are calculated from the linear parameters as
       amplitude²=a_0²+b_0²
       tan(ωt_0)=b_0/a_0;
       
The order of the returned array is at index zero amplitude, sigma amplitude, at index one, offset plus sigma, and at index two phase plus sigma.

Parameters:
in - An array of measurements. Each vector contains dependant and independant variables and eventually their errors.
Returns:
A three dimensional array of Vector2D.

fit

public List<Variable> fit()
We fit the amplitude and phase plus mgnitude offset only, the period stays constant. Thus, we return three parameters. For fitting the period starting with an intial condition, see PhaseFit. This fit has the advantage that by transforming the amplitude, phase function into a sin and cosine wave, we get a pure linear regression. This is done here, the result is transformed back to match the original (non-linear) model (holds also for parameter errors).

Returns:
Non-null, if a fit could be obtained.

getDataModel

public DataModel getDataModel()
Returns the phase model.


getFittedParameters

public List<Variable> getFittedParameters()
Returns the fitted parameters.