Menu

#507 Prescale fit parameters (patch attached)

None
closed-accepted
nobody
fit (9)
7
2014-03-04
2010-11-09
michal
No

Gnuplot's fit command is fairly robust, but when asked to fit with parameters that differ in size by many orders of magnitude, the fit command fails.

While it's easy enough rescale a function so that the parameters are of similar magnitude, it isn't always obvious that this is necessary. But this can be done internally to the fit command.

I've attached a patch that touches 7 lines and adds 13 more to fit.c that does this. I've tested this on some data sets where the scaling problem arises, and also on the fits in fit.dem. If reasonable initial guesses are provided, the fits often (but not always) seem to converge in fewer iterations.

Related

Patches: #230

Discussion

  • michal

    michal - 2010-11-09

    patch to prescale fit parameters, against 4.4.2

     
  • Bastian Märkisch

    Update to current CVS; Preserve sign of parameters; Fix error variables

     
  • Bastian Märkisch

    Update of this patch to current CVS 4.7.

    Additionally, preserve the sign of the fit parameters. That way, we still obtain the correct correlation matrix. Also scale the parameter error saved to variables.

     
  • michal

    michal - 2013-03-11

    Update of this patch (against 4.6.1). corrected comment describing behaviour with initial parameter value of 0, made prescaling an option with set fit [no]prescale, also
    updated show fit, unset fit, and documentation.

     
  • michal

    michal - 2013-03-11

    update as above, but against cvs.

     
  • michal

    michal - 2013-03-12

    This version includes update to 'save' so prescale preference is remembered. Against 4.6.1.

     
  • michal

    michal - 2013-03-12

    and against current CVS

     
  • Ethan Merritt

    Ethan Merritt - 2013-03-12

    If I run "fit.dem" with and without prescaling enabled, one of the demos reports drastically different values in the parameter correlation matrix. (Note that the demo script must be edited to set prescaling after each "reset" command). Since correlation should not depend on scaling, I worry that this indicates an error. Comments?

     
  • Ethan Merritt

    Ethan Merritt - 2013-03-12

    Never mind. I now see that the problem case is the one where without prescaling the fit is stopped after 50 iterations for non-convergence. Removing the iteration limit produces results more in line with the prescaling run. So that's actually a demo of the better convergence with prescaling :-)

     
  • Ethan Merritt

    Ethan Merritt - 2014-02-17
    • Group: -->
    • Priority: 5 --> 7
     
  • Ethan Merritt

    Ethan Merritt - 2014-02-17

    I'm bumping the priority because we seem to have lost track of this one.

     
  • michal

    michal - 2014-02-19

    The patch was applied to CVS - but it would be great to see it appear in a release!

     
    • Bastian Märkisch

      It didn't make it for the 4.6.5 release, but I now backported the changes in the 4.7 branch to 4.6. Could you please have a look at it to check that I didn't miss any application of the scaling?

      It would also be great if you could supply an example where scaling is mandatory to get the fit to converge. The ones I looked at mostly also converged if start_lambda was set or the limit was lowered to 1e-8 - 1e-10.

       
  • Bastian Märkisch

    • labels: --> fit
     
  • Bastian Märkisch

    • status: open --> pending-accepted
     
  • michal

    michal - 2014-02-26

    The looks good to me. I'll upload a small data set and script that shows the failure with no prescale and success with prescale.

     
    • Bastian Märkisch

      Thanks for the feedback. Your test case is another example where gnuplot's estimate of a "good" initial value for lambda is too large. Without prescaling it is 4.87e10 because the initial values for the fit parameters are off by far. Using the brief mode of the 4.7 branch, you can easily see that lambda does not decrease during the fit. With FIT_START_LAMBDA = 10 (4.6) or set fit start_lambda 10 (4.7) e.g. the fit converges even without prescaling.

      In my opinion, prescaling should be done by default in 4.7 and we should probably limit start_lambda to < 100 or so. Decreasing the default limit to 1e-8 instead 1e-5 might also help to get it a little more "robust". What is your experience?

       
      • michal

        michal - 2014-02-27

        I don't think I've ever seen prescaling introduce a new problem, so I think enabling it by default is a good idea. Epsilon seems like a different issue - its scaling depends on the errors. I wouldn't think that making it smaller should cause any problems. I don't have enough experience with the starting lambda to say.

         
        • Bastian Märkisch

          Prescaling is enabled by default in 4.7 now.

          Concerning lambda, the save thing to do is probably to explicitely warn the user if it hasn't gone down during the fit. That should be a clear indication that the algorithm didn't properly converge.

           
  • michal

    michal - 2014-02-26

    Here's a script that fits that data.

     
  • michal

    michal - 2014-02-26

    These are more extreme. That last example still converged if you set FIT_START_LAMBDA by hand. This doesn't.

     
  • Bastian Märkisch

    • status: pending-accepted --> closed-accepted
     

Log in to post a comment.