vec_math
Class LinearPrediction

java.lang.Object
  extended by vec_math.LinearPrediction
Direct Known Subclasses:
LinearPrediction.Debug, MaximumEntropy

public class LinearPrediction
extends Object

A class based on the linear prediction code given in

   Numerical Recipes in C, p568ff.
   
It allows the calculating of the LP coefficients based on routine memcof and the prediction of values with these coefficients based on predic. This simple version is taylored for a first glimpse on the capabilities of linear prediction, therefore no root-adjusting algorithm is implemented.

The normal use of this class is as follows:


Nested Class Summary
static class LinearPrediction.Debug
          A debugging class.
 
Field Summary
private  double average
          The mean of the data.
private  double[] data
          The data array.
private  double[] lp
          The coefficients to the linear prediction.
private  boolean unbias
          Whether to subtract the mean prior to coefficient calculation.
private  double xms
          The mean square discrepancy on calculation of the ceofficients.
 
Constructor Summary
LinearPrediction()
          Constructs a new linear prediction object with no bias removing.
LinearPrediction(boolean subtract)
          Constructs a new linear prediction object.
 
Method Summary
 double calculateCoefficients(int m)
          Calculates the linear prediction coefficients.
 double[] getCoefficients()
          Returns the linear prediction coefficients.
 double[] getData()
          Returns the data set.
 double getDiscrepancy()
          Returns the mean square discrepancy as stored after a calculation of the coefficients using calculateCoefficients(int) or NaN if no calculation has been done.
 double[] predict(int fut)
          Predict the stated number of data points.
 void setData(double[] newdata)
          Sets the data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

unbias

private boolean unbias
Whether to subtract the mean prior to coefficient calculation.


average

private double average
The mean of the data. Only calculated when needed.


data

private double[] data
The data array. Its length is equal to the data points used.


lp

private double[] lp
The coefficients to the linear prediction.


xms

private double xms
The mean square discrepancy on calculation of the ceofficients.

Constructor Detail

LinearPrediction

public LinearPrediction()
Constructs a new linear prediction object with no bias removing.


LinearPrediction

public LinearPrediction(boolean subtract)
Constructs a new linear prediction object. If the supplied boolean is true, the data mean is subtracted prior to the calculation of the LP coefficients and added again on the predicted values.

Parameters:
subtract - Whether to subtract the mean.
Method Detail

setData

public void setData(double[] newdata)
Sets the data. Any LP coefficients calculated previously are rendered invalid.

Parameters:
newdata - Data set where linear prediction should be applied to.

getData

public double[] getData()
Returns the data set. If no data has been set, null is returned.


getCoefficients

public double[] getCoefficients()
Returns the linear prediction coefficients. The coefficients must be calculated beforehand with a call to calculateCoefficients(int).


getDiscrepancy

public double getDiscrepancy()
Returns the mean square discrepancy as stored after a calculation of the coefficients using calculateCoefficients(int) or NaN if no calculation has been done.


calculateCoefficients

public double calculateCoefficients(int m)
Calculates the linear prediction coefficients. If no data is present, Double.NaN is returned. If bias removal is requested, then the average of the data set is calculated and removed on calculating the LP coefficients, i.e. the data set stays untouched.

Parameters:
m - The number of LP coefficients to calculate.
Returns:
The mean square discrepancy.

predict

public double[] predict(int fut)
Predict the stated number of data points. The data must have been set and the linear prediction coefficients must have been calculated before this method can be used. If unbiased prediction is wanted, the average of the data is added to the predicted values.

Returns:
A double array holding the predicted values or null on error.