commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles Sadowski <gil...@harfang.homelinux.org>
Subject Re: [math] QR decomposition in HarmonicFitter
Date Sun, 12 Aug 2012 16:09:23 GMT
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: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message