vec_math
Class PhaseRegression

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

public class PhaseRegression
extends AbstractFit

An analyser that fits a cosine wave with phase shift, but fixed 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 all its three parameters a_0, b_0, and c_0. This fit can be performed using GeneralRegression#harmonic. We assign variable names according to 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;
   


Nested Class Summary
private static class PhaseRegression.PhaseModel
          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 DEFERRORINDEX
          Default error index.
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 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_ERRORINDEX
          The index of the measure error, defaults to none.
static String KEY_PERIOD
          This is the main fitting parameter.
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_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.
static String PHASE
          The name of the phase constant.
private  PhaseRegression.PhaseModel phasemodel
          The model.
private  double q
          The q-value of the fit, available after fit().
 
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
PhaseRegression(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.
 double qualityOfFit()
          Significance is the q-value of the regression.
 boolean setConstant(Variable p)
          We need tthe period as a constant.
 
Methods inherited from class vec_math.AbstractFit
formatError, formatValue, getChi2, getModelParameterErrors, getModelParameterValues, getR2, getRms, init, setInitialCondition
 
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

PHASE

public static final String PHASE
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_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_ERRORINDEX

public static final String KEY_ERRORINDEX
The index of the measure error, defaults to none.

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

DEFERRORINDEX

private static final int DEFERRORINDEX
Default error index.

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

q

private double q
The q-value of the fit, available after fit().


fitted

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


phasemodel

private PhaseRegression.PhaseModel phasemodel
The model.

Constructor Detail

PhaseRegression

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

Method Detail

setConstant

public boolean setConstant(Variable p)
We need tthe period as a constant.

Specified by:
setConstant in interface ModelFitting
Overrides:
setConstant in class AbstractFit
Returns:
false, if the constant 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.


qualityOfFit

public double qualityOfFit()
Significance is the q-value of the regression. All parameters are ignored.

Specified by:
qualityOfFit in interface ModelFitting
Overrides:
qualityOfFit in class AbstractFit