org.apache.commons.math3.fitting
public static class HarmonicFitter.ParameterGuesser extends Object
The algorithm used to guess the coefficients is as follows:
We know f (t) at some sampling points t_{i} and want to find a, ω and φ such that f (t) = a cos (ω t + φ).
From the analytical expression, we can compute two primitives :
If2 (t) = ∫ f^{2} = a^{2} × [t + S (t)] / 2 If'2 (t) = ∫ f'^{2} = a^{2} ω^{2} × [t  S (t)] / 2 where S (t) = sin (2 (ω t + φ)) / (2 ω)
We can remove S between these expressions :
If'2 (t) = a^{2} ω^{2} t  ω^{2} If2 (t)
The preceding expression shows that If'2 (t) is a linear combination of both t and If2 (t): If'2 (t) = A × t + B × If2 (t)
From the primitive, we can deduce the same form for definite integrals between t_{1} and t_{i} for each t_{i} :
If2 (t_{i})  If2 (t_{1}) = A × (t_{i}  t_{1}) + B × (If2 (t_{i})  If2 (t_{1}))
We can find the coefficients A and B that best fit the sample to this linear expression by computing the definite integrals for each sample points.
For a bilinear expression z (x_{i}, y_{i}) = A × x_{i} + B × y_{i}, the coefficients A and B that minimize a least square criterion ∑ (z_{i}  z (x_{i}, y_{i}))^{2} are given by these expressions:
∑y_{i}y_{i} ∑x_{i}z_{i}  ∑x_{i}y_{i} ∑y_{i}z_{i} A =  ∑x_{i}x_{i} ∑y_{i}y_{i}  ∑x_{i}y_{i} ∑x_{i}y_{i} ∑x_{i}x_{i} ∑y_{i}z_{i}  ∑x_{i}y_{i} ∑x_{i}z_{i} B =  ∑x_{i}x_{i} ∑y_{i}y_{i}  ∑x_{i}y_{i} ∑x_{i}y_{i}
In fact, we can assume both a and ω are positive and compute them directly, knowing that A = a^{2} ω^{2} and that B =  ω^{2}. The complete algorithm is therefore:
for each t_{i} from t_{1} to t_{n1}, compute: f (t_{i}) f' (t_{i}) = (f (t_{i+1})  f(t_{i1})) / (t_{i+1}  t_{i1}) x_{i} = t_{i}  t_{1} y_{i} = ∫ f^{2} from t_{1} to t_{i} z_{i} = ∫ f'^{2} from t_{1} to t_{i} update the sums ∑x_{i}x_{i}, ∑y_{i}y_{i}, ∑x_{i}y_{i}, ∑x_{i}z_{i} and ∑y_{i}z_{i} end for  \  ∑y_{i}y_{i} ∑x_{i}z_{i}  ∑x_{i}y_{i} ∑y_{i}z_{i} a = \   \ ∑x_{i}y_{i} ∑x_{i}z_{i}  ∑x_{i}x_{i} ∑y_{i}z_{i}  \  ∑x_{i}y_{i} ∑x_{i}z_{i}  ∑x_{i}x_{i} ∑y_{i}z_{i} ω = \   \ ∑x_{i}x_{i} ∑y_{i}y_{i}  ∑x_{i}y_{i} ∑x_{i}y_{i}
Once we know ω, we can compute:
fc = ω f (t) cos (ω t)  f' (t) sin (ω t) fs = ω f (t) sin (ω t) + f' (t) cos (ω t)
It appears that fc = a ω cos (φ)
and
fs = a ω sin (φ)
, so we can use these
expressions to compute φ. The best estimate over the sample is
given by averaging these expressions.
Since integrals and means are involved in the preceding estimations, these operations run in O(n) time, where n is the number of measurements.
Constructor and Description 

HarmonicFitter.ParameterGuesser(WeightedObservedPoint[] observations)
Simple constructor.

public HarmonicFitter.ParameterGuesser(WeightedObservedPoint[] observations)
observations
 Sampled observations.NumberIsTooSmallException
 if the sample is too short.ZeroException
 if the abscissa range is zero.MathIllegalStateException
 when the guessing procedure cannot
produce sensible results.public double[] guess()
Copyright © 2003–2015 The Apache Software Foundation. All rights reserved.