Double initial guess for the surface kink position.
authorW. Trevor King <wking@drexel.edu>
Fri, 27 Aug 2010 21:31:39 +0000 (17:31 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 27 Aug 2010 21:31:39 +0000 (17:31 -0400)
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:
    _______
   /
  /

hooke/plugin/vclamp.py
hooke/util/fit.py

index 0cfad0d..88306ff 100644 (file)
@@ -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
index 1360677..6d2e303 100644 (file)
@@ -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