From 9ba5c8d2c93ee5ae1a76cde519b54e24a5835e95 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 10 Aug 2010 13:09:44 -0400 Subject: [PATCH] Make ModelFitter._data_scale_factor determination more robust with wierd data. --- hooke/util/fit.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hooke/util/fit.py b/hooke/util/fit.py index d5e4d03..efea018 100644 --- a/hooke/util/fit.py +++ b/hooke/util/fit.py @@ -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 -- 2.26.2