public abstract class Extrapolation extends Object
algebra.LinearPrediction proved
insufficient.
The idea is now, and at the time of this writing I have no clue if this will be successful, to take a bunch of measurements (say, 100) and try either a linear or parabolic regression. Due to the evenly spaced measurement intervalls, the calculation of the design matrix can be skipped, the formulars get rather simple.
Assuming a fit to the yk data points according to
yk ≈ a+bt+ct²
with
t=kΔt, Δt=1,
we have to minimize the deviation
χ² = ∑(a+bk+ck²-yk)².
Differentiation with respect to a, b, and c and setting this derivative
zero immediately gives you the parameters (n … number of points):
a = 3[3n²S+3n(S-4Sk)+2(S-3Sk+5Skk)]/(n(n²-3n+2))
b = (6S-6na-c(2n³+3n²+n))/(3n(n+1))
c = 30[n²S+3n(S-2Sk)+2(S-3(Sk-Skk))]/(n(n4-5n²+4)),
S := ∑yk
Sk := ∑kyk
Skk := ∑k²yk.
A simply linear fit a+bk yields:
a = S/n-b(n+1)/2
b = 12(Sk-S(n+1)/2)/n³
This abstract base class only provides common properties to both, linear and
parabolic extrapolation. The actual extrapolating polynom is defined in
non-abstract subclasses.| Modifier and Type | Field and Description |
|---|---|
private int |
base
The base size of the extrapolating class, data is trimmed to this.
|
private int |
brink
An index pointer to allow proper update of data array and sums.
|
(package private) Polynom |
extrapolate
The polynom that is the extrapolator.
|
(package private) double[] |
sum
The different data sums.
|
(package private) double[] |
yk
The data array of values to extrapolate.
|
(package private) double |
yk2sum
The sum of the squares of the data points.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Extrapolation(double[] data)
Constructs a new extrapolation object.
|
protected |
Extrapolation(int base)
Constructs a new extrapolation object.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract Polynom |
calcPolynom()
The abstract method returning the extrapolating polynom.
|
protected void |
calcSum(int degree)
Calculates the data sums according to the following schema:
First, the ∑yk is calculated and stored in
sum[0].
Now, as long as j is less or equal the argument,
∑kjyk is evaluated and stored at
sum[j].
|
abstract double |
getChi2()
Returns an estimate of the goodness-of-fit.
|
int |
getN()
Returns the length of the data set.
|
Polynom |
getPolynom()
Returns the extrapolating polynom of the extrapolator.
|
double |
predict(int step)
Uses the extrapolating polynom to predict one value in the future,
exactly spaced at the argument steps ahead.
|
void |
setData(double[] data)
Sets the measurment points of the extrapolator.
|
double |
shiftBackward(double addyk)
Shifts the entire data set backward for one point.
|
double |
shiftForward(double addyk)
Shifts the entire data set forward for one point.
|
protected abstract Polynom |
updatePolynom()
The abstract method returning an updated polynom if data has changed.
|
private void |
updateSum(double out,
double in,
double step)
Updates the data sums after shifting forward or backward for one index.
|
boolean |
valid() |
Polynom extrapolate
double[] yk
double[] sum
double yk2sum
private int brink
private final int base
protected Extrapolation(int base)
setData(double[]).protected Extrapolation(double[] data)
setData(double[]) method with the array
argument.public void setData(double[] data)
calcPolynom(). To allow
one-step index shifting of the data, the brink index pointer is
set to zero, indicating that the next data element that drops out is
on index zero.public boolean valid()
public int getN()
public double shiftForward(double addyk)
brink index, the element
there is the element that drops out of the extrapolator's base.
These two elements are also used to update the extrapolator's sums
accordingly. At last, the extrapolating polynomial is updated with a call
to the updatePolynom() method that may possibly fork into the
calcPolynom() method of the daughter class, but is intended for
speed-up calculus.public double shiftBackward(double addyk)
brink-1 index, the element
there is the element that drops out of the extrapolator's base.
These two elements are also used to update the extrapolator's sums
accordingly. At last, the extrapolating polynom is updated with a call
to the updatePolynom() method that may possibly fork into the
calcPolynom() method of the daugther class, but is intended for
speed-up calculus.public double predict(int step)
step - The index of the future value to predict, 0=now.public Polynom getPolynom()
public abstract double getChi2()
protected abstract Polynom calcPolynom()
calcSum(int) method.protected abstract Polynom updatePolynom()
sum are up-to-date. calcPolynom() if no speed-gain can be achieved.protected void calcSum(int degree)
degree - The degree of the extrapolating polynom, 1=linearprivate void updateSum(double out,
double in,
double step)
Skm = ∑m over j (±1)m-j Skj+…
The maximum degree m of the sums is deduced from the array size
of the sum array.out - The value that drops out from the data set.in - The value that newly enters the data set.step - Either 1 or -1, for backward/forward update.