Make ModelFitter._data_scale_factor determination more robust with wierd data.
authorW. Trevor King <wking@drexel.edu>
Tue, 10 Aug 2010 17:09:44 +0000 (13:09 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 10 Aug 2010 17:09:44 +0000 (13:09 -0400)
hooke/util/fit.py

index d5e4d0364493ce757add0f6daa3716a9c8edf13e..efea0188291ce58e014ecd952e40f793a6fbc106 100644 (file)
@@ -140,7 +140,10 @@ class ModelFitter (object):
         self.info = info
         self._rescale = rescale
         if rescale == True:
-            self._data_scale_factor = data.std()
+            for x in [data.std(), data.max()-data.min(), abs(data.max()), 1.0]:
+                if x != 0:
+                    self._data_scale_factor = x
+                    break
         else:
             self._data_scale_factor = 1.0
 
@@ -159,7 +162,7 @@ class ModelFitter (object):
         if self._rescale == True:
             params = [p*s for p,s in zip(params, self._param_scale_factors)]
         residual = self._data - self.model(params)
-        if self._rescale == True or False:
+        if self._rescale == True:
             residual /= self._data_scale_factor
         return residual