【问题标题】:fit to time series using Gnuplot使用 Gnuplot 拟合时间序列
【发布时间】:2015-06-09 07:39:20
【问题描述】:

我是 Gnuplot 的忠实粉丝,现在我想对时间序列使用拟合函数。

我的数据集是这样的:

1.000000 1.000000 0.999795 0.000000 0.000000 0.421927 0.654222 -25.127700 1.000000 1994-08-12
1.000000 2.000000 0.046723 -0.227587 -0.689491 0.328387 1.000000 0.000000 1.000000 1994-08-12 
2.000000 1.000000 0.945762 0.000000 0.000000 0.400038 0.582360 -8.624480 1.000000 1995-04-19 
2.000000 2.000000 0.060228 -0.056367 -0.680224 0.551019 1.000000 0.000000 1.000000 1995-04-19
3.000000 1.000000 1.016430 0.000000 0.000000 0.574478 0.489638 -3.286880 1.000000 1995-07-15

还有我的合适剧本:

set timefmt "%Y-%m-%d"
set xdata time
set format x "%Y-%m-%d"
f(x)=a+b*x
fit f(x) "model_fit.dat" u 10:($2==2?$4:1/0) via a,b

所以我对时间数据进行了条件拟合。 我的问题是,Gnuplot 拟合函数不适用于时间数据。 我在这里发现了一个类似的问题:Linear regression for time series with Gnuplot 但我不想使用其他软件。而且我也不知道如何将时间值更改为数字,然后再返回....

谁能帮我用 Gnuplot 解决这个问题?

非常感谢!

【问题讨论】:

    标签: gnuplot time-series curve-fitting linear-regression


    【解决方案1】:

    确实,gnuplot 的拟合机制适用于时间数据。你必须只注意一些细节。

    通常,可以精确求解通过两个数据点的线性拟合。但是 gnuplot 通常会进行非线性拟合,因此初始值很重要。

    用于线的有效 x 值以秒为单位。在这里使用 b = 1e-8 的初始值可以正常工作:

    set timefmt "%Y-%m-%d"
    set xdata time
    set format x "%Y-%m-%d"
    f(x)=a+b*x
    a = 1
    b = 1e-8
    fit f(x) "model_fit.dat" u 10:($2==2?$4:1/0) via a,b
    
    plot "model_fit.dat" u 10:($2==2?$4:1/0) lt 1 pt 7 title 'data',\
         f(x) w l lt 1 title 'fit'
    

    【讨论】:

    • 这种拟合对我不起作用...... gnuplot 说拟合在 3 次迭代后收敛。拟合后 a 的值根本没有改变!所以我认为gnuplot在拟合a时有一些问题。 (参数b的拟合看起来不错)
    • 你有哪个 gnuplot 版本?我用 5.0 测试过。尝试将 a 设置为 -7 以适合
    • 我使用 4.6。 gnuplot 的版本,现在我将它升级到 5.0 版。然后再试一次。
    • 它适用于 gnuplot 5.0。为了我。非常感谢!
    猜你喜欢
    • 2023-03-24
    • 2020-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多