如何告诉gnuplot忽略非收敛拟合 [英] How to tell gnuplot to ignore non-converging fits

查看:91
本文介绍了如何告诉gnuplot忽略非收敛拟合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找良好的初始条件时遇到了一些问题,而这种适应性只会表现得不好.因此,我想到了将其插入循环中的方法,以强行使用它,告诉gnuplot保持拟合,直到他得到小于100%的相对偏差,同时每次重新运行该循环时都随机更改初始值,我写了类似的东西

I am having some issues with finding good initial conditions for a fit that just won't behave. So I had the idea to Brute-force it by inserting it in a loop that tells gnuplot to keep fitting until he gets a relative deviation of less than 100% while randomly changing initial values each time he re runs the loop, i wrote something like that:

while(abs(m_err/m) > 1){
    m = rand(0)*0.3
    k = rand(0)
    x_0 = 15 + rand(0)*10 
    fit logi(x) 'data.csv' u 1:8 via m,k,x_0
}   

我将rand函数相乘,以便得到的值接近我希望适合的值.

i multiply the rand function so that i get values near the value i expect to be good for fitting.

该方法显然导致很多拟合不收敛,并且无法在脚本中间循环进行.如果拟合不收敛或给出奇异矩阵,我怎么能告诉gnuplot忽略这一点并重新运行随机化和拟合循环?

This method obviously results in a lot of fits not converging and stopping the script mid-loop. How can i tell gnuplot to simply ignore this and just re-run the randomization and fitting loop if the fit doesn't converge or it gives a singular matrix?

推荐答案

了解所使用的gnuplot版本可能会有所帮助.据我所知,不收敛不是当前gnuplot中的致命错误.它会显示一条错误消息,但仍然应该继续.如果不是这种情况,您可以尝试设置最大迭代次数,然后在拟合返回时自己测试收敛性.例如

It might help to know what version of gnuplot you are using. So far as I know non-convergence is not a fatal error in current gnuplot. It prints an error message but should continue anyway. If that is not the case, you might try setting a maximum number of iterations and then testing for convergence yourself when the fit returns. E.g.

set fit maxiter 100   # no limit by default
set fit limit 1.e-5   # this is the default convergence criterion
do for [i=1:100] {
  a = something + i*0.01
  b = something_else
  fit f(x) 'datafile' using 1:2 via a, b
  if (FIT_ITER < 100) break;   # It converged!
}
if (FIT_ITER >= 100) {
  print "No starting point led to convergence."
  exit
}

这篇关于如何告诉gnuplot忽略非收敛拟合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆