Hello.

> > 
> > I am trying to set up a harmonic fitter to determine periodicity of a data
> > set. My code:
> > import org.apache.commons.math3.optimization.fitting.HarmonicFitter;
> > import org.apache.commons.math3.optimization.fitting.WeightedObservedPoint;
> > import
> > org.apache.commons.math3.optimization.general.LevenbergMarquardtOptimizer;
> > 
> > 
> > public class FFT {
> >     public static void main(String[] args){
> >             double[] real =
> > {0,1,2,3,2,1,0,-1,-2,-3,-2,-1,0,1,2,3,2,1,0,-1,-2,-3,-2,-1,0,1,2,3,2,1,0};
> >             WeightedObservedPoint[] points = new WeightedObservedPoint
> > [real.length];
> >             HarmonicFitter fitter = new HarmonicFitter(new
> > LevenbergMarquardtOptimizer());
> >             for(int i = 0; i < real.length; i++){
> >                     points[i] = new WeightedObservedPoint(1,i,real[i]);
> >                     fitter.addObservedPoint(new WeightedObservedPoint
> > (1,i,real[i]));
> >             }
> >             HarmonicFitter.ParameterGuesser guesser = new
> > HarmonicFitter.ParameterGuesser(points);
> >             double[] guess = fitter.fit(guesser.guess());
> >             for(double x:guess){
> >                     System.out.println(x);
> >             }
> >     }
> > }
> > 
> > and the error:
> > Exception in thread "main"
> > org.apache.commons.math3.exception.ConvergenceException: illegal state:
> > unable to perform Q.R decomposition on the 31x3 jacobian matrix
> > [...]
> 
> This seems to be caused by the "degenerate" input (a slight change in the
> values and the fit proceeds fine). In order to investigate where the problem
> occurs, it might be worth opening a report on the Commons Math bug tracking
> system. [Unfortunately the web site is currently down...]

The "guess()" method in "HarmonicFitter" returns a wrong value for
"amplitude".
The problem is in the value of "c2", computed at line 295 in
"HarmonicFitter.java": For this set of points, the value is zero, which
produces infinity (at line 320).
[I don't know whether the "guesser" code could be improved to avoid such a
situation, or if we can just check for "c2" being zero and return something
more appropriate if this is the case...]


Best,
Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to