From: W. Trevor King Date: Tue, 10 Aug 2010 17:09:44 +0000 (-0400) Subject: Make ModelFitter._data_scale_factor determination more robust with wierd data. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9ba5c8d2c93ee5ae1a76cde519b54e24a5835e95;p=hooke.git Make ModelFitter._data_scale_factor determination more robust with wierd data. --- 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