Index: trunk/psLib/src/math/psMinimizeLMM.c
===================================================================
--- trunk/psLib/src/math/psMinimizeLMM.c	(revision 17355)
+++ trunk/psLib/src/math/psMinimizeLMM.c	(revision 19845)
@@ -10,6 +10,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-04-07 00:45:21 $
+ *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-10-02 20:49:22 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -91,4 +91,12 @@
         psTrace ("psLib.math", 4, "singular matrix in Guess ABP\n");
         return(false);
+    }
+
+    // check for non-finite entries in result
+    for (int i = 0; i < Beta->n; i++) {
+	if (!isfinite(Beta->data.F32[i])) {
+	    // psError(PS_ERR_BAD_PARAMETER_VALUE, 3, "Fit value diverges: vector[%d] is %.2f\n", i, Beta->data.F32[i]);
+	    return false;
+	}
     }
 
@@ -453,4 +461,7 @@
                 Chisq, min->lastDelta, dLinear, rho, lambda);
 
+        psTrace("psLib.math.dLinear", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: %f\n", min->value,
+                Chisq, min->lastDelta, dLinear, rho, lambda);
+
         // dump some useful info if trace is defined
         if (psTraceGetLevel("psLib.math") >= 6) {
@@ -459,6 +470,6 @@
         }
 
-        /* if (Chisq < min->value) {  */
-        if (rho > 0.0) {
+        /* rho is positive if the new chisq is smaller; allow for some insignificant change (slight negative rho) */
+        if (rho >= -1e-6) {
             min->lastDelta = (min->value - Chisq) / (dy->n - params->n);
             min->value = Chisq;
