From faead6c3fbe343ba97e70f8eda74a488c916b29a Mon Sep 17 00:00:00 2001
From: Luc Maisonobe
Date: Sun, 23 Mar 2008 13:36:03 +0000
Subject: [PATCH] detect numerical problems in Q.R decomposition for
Levenberg-Marquardt estimator and report them appropriately JIRA: MATH-199
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@640204 13f79535-47bb-0310-9956-ffa450edef68
---
.../LevenbergMarquardtEstimator.java | 7 +-
src/site/xdoc/changes.xml | 4 +
.../LevenbergMarquardtEstimatorTest.java | 82 +++++++++++++++++++
3 files changed, 92 insertions(+), 1 deletion(-)
diff --git a/src/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java b/src/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java
index 248ebf3c9..07bffbad1 100644
--- a/src/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java
+++ b/src/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java
@@ -733,8 +733,9 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
* are performed in non-increasing columns norms order thanks to columns
* pivoting. The diagonal elements of the R matrix are therefore also in
* non-increasing absolute values order.
+ * @exception EstimationException if the decomposition cannot be performed
*/
- private void qrDecomposition() {
+ private void qrDecomposition() throws EstimationException {
// initializations
for (int k = 0; k < cols; ++k) {
@@ -760,6 +761,10 @@ public class LevenbergMarquardtEstimator extends AbstractEstimator implements Se
double aki = jacobian[index];
norm2 += aki * aki;
}
+ if (Double.isInfinite(norm2) || Double.isNaN(norm2)) {
+ throw new EstimationException("unable to perform Q.R decomposition on the {0}x{1} jacobian matrix",
+ new Object[] { new Integer(rows), new Integer(cols) });
+ }
if (norm2 > ak2) {
nextColumn = i;
ak2 = norm2;
diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml
index f5aabb0d1..52c9b8a0d 100644
--- a/src/site/xdoc/changes.xml
+++ b/src/site/xdoc/changes.xml
@@ -47,6 +47,10 @@ Commons Math Release Notes
added an error detection for missing imaginary character while parsing complex string
+
+ detect numerical problems in Q.R decomposition for Levenberg-Marquardt estimator
+ and report them appropriately
+