Mercurial > dive4elements > river
changeset 3202:307842cf8d9e
FixA: Make fitting more tolerant.
flys-artifacts/trunk@4819 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 27 Jun 2012 17:29:33 +0000 |
parents | 1c00ed73ccf4 |
children | 1b9f791937c3 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java |
diffstat | 2 files changed, 34 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed Jun 27 16:41:02 2012 +0000 +++ b/flys-artifacts/ChangeLog Wed Jun 27 17:29:33 2012 +0000 @@ -1,3 +1,9 @@ +2012-06-27 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java: + If fitting fails for tolerance of 1e-10 increase it incremental + by factor of 10 to 1e-3 and only bail out if it fails on this level. + 2012-06-27 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/math/fitting/Exp.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java Wed Jun 27 16:41:02 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java Wed Jun 27 17:29:33 2012 +0000 @@ -22,6 +22,9 @@ import org.apache.log4j.Logger; +import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer; +import org.apache.commons.math.optimization.general.GaussNewtonOptimizer; + public class Fitting { private static Logger log = Logger.getLogger(Fitting.class); @@ -157,24 +160,38 @@ return false; } - LevenbergMarquardtOptimizer lmo = new LevenbergMarquardtOptimizer(); - List<IndexedValue> inputs = new ArrayList<IndexedValue>(xs.size()); de.intevation.flys.artifacts.math.Function instance = null; + LevenbergMarquardtOptimizer lmo = null; + for (;;) { - CurveFitter cf = new CurveFitter(lmo); + parameters = null; + for (double tolerance = 1e-10; tolerance < 1e-3; tolerance *= 10d) { - for (int i = 0, N = xs.size(); i < N; ++i) { - cf.addObservedPoint(xs.getQuick(i), ys.getQuick(i)); + lmo = new LevenbergMarquardtOptimizer(); + lmo.setCostRelativeTolerance(tolerance); + lmo.setOrthoTolerance(tolerance); + lmo.setParRelativeTolerance(tolerance); + + CurveFitter cf = new CurveFitter(lmo); + + for (int i = 0, N = xs.size(); i < N; ++i) { + cf.addObservedPoint(xs.getQuick(i), ys.getQuick(i)); + } + + try { + parameters = cf.fit(function, function.getInitialGuess()); + break; + } + catch (MathException me) { + if (log.isDebugEnabled()) { + log.debug("tolerance " + tolerance + " + failed."); + } + } } - - try { - parameters = cf.fit(function, function.getInitialGuess()); - } - catch (MathException me) { - log.warn(me); + if (parameters == null) { return false; }