commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Garrett Kane <gk...@us.ibm.com>
Subject [math] QR decomposition in HarmonicFitter
Date Wed, 08 Aug 2012 16:42:55 GMT


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
	at
org.apache.commons.math3.optimization.general.LevenbergMarquardtOptimizer.qrDecomposition
(
LevenbergMarquardtOptimizer.java:848)
	at
org.apache.commons.math3.optimization.general.LevenbergMarquardtOptimizer.doOptimize
(
LevenbergMarquardtOptimizer.java:312)
	at
org.apache.commons.math3.optimization.direct.BaseAbstractMultivariateVectorOptimizer.optimize
(
BaseAbstractMultivariateVectorOptimizer.java:134)
	at
org.apache.commons.math3.optimization.general.AbstractLeastSquaresOptimizer.optimize
(
AbstractLeastSquaresOptimizer.java:273)
	at
org.apache.commons.math3.optimization.general.AbstractLeastSquaresOptimizer.optimize
(
AbstractLeastSquaresOptimizer.java:51)
	at org.apache.commons.math3.optimization.fitting.CurveFitter.fit(
CurveFitter.java:157)
	at org.apache.commons.math3.optimization.fitting.CurveFitter.fit(
CurveFitter.java:124)
	at org.apache.commons.math3.optimization.fitting.HarmonicFitter.fit(
HarmonicFitter.java:61)
	at FFT.main(FFT.java:16)
Can anyone help me? Should I be using a different
optimizer/fitter/something out of a separate library? The double[] real is
just a test set, actual data will be much more noisy as it comes from
real-world sensors
Thanks
-Garrett
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message