From: W. Trevor King Date: Fri, 27 Aug 2010 21:31:39 +0000 (-0400) Subject: Double initial guess for the surface kink position. X-Git-Url: http://git.tremily.us/?p=hooke.git;a=commitdiff_plain;h=964355d2abecaee76304b309ec2e3400158bdf6c Double initial guess for the surface kink position. The previous algorithm would fail for curves if 1) They didn't have many tension features to stretch out the range. 2) The contact slope "softened" a bit in the kink region. For example, try it on most of the test/vclamp_picoforce data ;). The new algorithm works perfectly on the ideal, boring curve: _______ / / --- diff --git a/hooke/plugin/vclamp.py b/hooke/plugin/vclamp.py index 0cfad0d..88306ff 100644 --- a/hooke/plugin/vclamp.py +++ b/hooke/plugin/vclamp.py @@ -165,7 +165,7 @@ Minimum `fit-contact-slope/guessed-contact-slope` ratio for a "good" fit. left_offset = self.info['min deflection'] middle_deflection = (self.info['min deflection'] + self.info['deflection range']/2.) - kink_position = (self._data > middle_deflection).argmax() + kink_position = 2*(self._data > middle_deflection).argmax() left_slope = ((self._data[-1] - self.info['min deflection']) /kink_position) right_slope = 0 diff --git a/hooke/util/fit.py b/hooke/util/fit.py index 1360677..6d2e303 100644 --- a/hooke/util/fit.py +++ b/hooke/util/fit.py @@ -187,6 +187,12 @@ 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 False: # fit debugging + if not hasattr(self, '_i_'): + self._i_ = 0 + self._data.tofile('data.%d' % self._i_, sep='\n') + self.model(params).tofile('model.%d' % self._i_, sep='\n') + self._i_ += 1 if self._rescale == True: residual /= self._data_scale_factor return residual