|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectstella.math.Extrapolation
public abstract class Extrapolation
A class to predict sensor readings for at least 120 sec.
A very specific part of mathematics, probably only useful for STELLA.
The idea is that we take evenly spaced measurements (sensor datas) and
extrapolate them 120 sec into the future to properly trace clouds swapping
over the building. In fact, actual measurements show that the rise time in
the humidity can be close to 200 sec., so fast detection of a rise is
inevitable. Linear Prediction 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.
| Field Summary | |
|---|---|
private int |
brink
An index pointer to allow proper update of data array and sums. |
protected Polynom |
extrapolate
The polynom that is the extrapolator. |
protected double[] |
sum
The different data sums. |
protected double[] |
yk
The data array of values to extrapolate. |
protected double |
yk2sum
The sum of the squares of the data points. |
| Constructor Summary | |
|---|---|
protected |
Extrapolation()
Constructs a new extrapolation object. |
protected |
Extrapolation(double[] data)
Constructs a new extrapolation object. |
| Method Summary | |
|---|---|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Polynom extrapolate
protected double[] yk
protected double[] sum
protected double yk2sum
private int brink
| Constructor Detail |
|---|
protected Extrapolation()
setData(double[]).
protected Extrapolation(double[] data)
setData(double[]) method with the array
argument.
| Method Detail |
|---|
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 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 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 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=linear
private 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.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||