使用 gnuplot 提高 pfgplots 精度

使用 gnuplot 提高 pfgplots 精度

我已经测量了两种算法(一种简单算法和一种优化算法)的执行时间,并且我想显示测量数据并pgfplots为简单算法添加一条趋势线。

我已经使用 Matlabcftool获得了趋势线的多项式函数:

Linear model Poly2:
    fittedmodel(x) = p1*x^2 + p2*x + p3
    Coefficients (with 95% confidence bounds):
        p1 = 1.61e-06 (1.61e-06, 1.61e-06)
        p2 = -0.003371 (-0.003636, -0.003107)
        p3 = -0.0772 (-5.333, 5.179)

>> vpa(fittedmodel.p1)

ans =

0.0000016101333575269318185488581079978

>> vpa(fittedmodel.p2)

ans =

-0.0033714174188680659169370379402153

>> vpa(fittedmodel.p3)

ans =

-0.077204674695659905592215466185735

但将所有内容绘制到一个图形中pgfplots会在低值处产生错误的趋势线。

我使用它gnuplot作为趋势线,因为pgfplots甚至没有对低值做出任何输出。

我不知道我做错了什么,可能是精度不够。如果这是问题所在,我该如何改进?

这是我的 MWE:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{xcolor}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning, shapes, pgfplots.units, pgfplots.dateplot, calendar}
\pgfplotsset{width=12cm, compat=newest}

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}

\begin{tikzpicture}%[font=\large\sffamily]
    \begin{loglogaxis}[/pgf/number format/.cd,use comma,%
    use units=true,%
    y unit=s,%
    y unit prefix=m,%
    ylabel={Fut\'{a}si id\H{o}},%
    scaled y ticks=false,%
    y tick label style={/pgf/number format/fixed,%
        /pgf/number format/1000 sep=\thinspace},%
    x unit=n,%
    xlabel={Bemenet},%
    legend pos=north west,%
    legend style={draw=none}]
        \addplot+[mark=*,%
            mark options={scale=0.5,fill=blue,draw=blue},%
            color=blue] table[col sep=semicolon,%
            x=n,%
            y=t_naive] {exectime.csv};
        \addlegendentry{naive}

        \addplot[mark=none,%
            style=dashed,%
            color=blue!50!white,%
            domain=1:1000000000,%
            samples=1000] gnuplot {0.0000016101333575269318185488581079978 * x^2 - 0.0033714174188680659169370379402153 * x - 0.077204674695659905592215466185735};
        \addlegendentry{naive trend}

        \addplot+[mark=*,%
            mark options={scale=0.5,fill=red,draw=red},%
            color=red] table[col sep=semicolon,%
            x=n,%
            y=t_optimized] {exectime.csv};
        \addlegendentry{optimized}
    \end{loglogaxis}
\end{tikzpicture}

\end{document}

以下是 exectime.csv 文件的内容:

n;t_naive;t_optimized
1;0.00549499999999999;0.00004500000000000
2;0.00557399999999999;0.00004500000000000
3;0.00567399999999998;0.00017300000000000
4;0.00568299999999998;0.00017300000000000
5;0.00579299999999997;0.00021100000000000
6;0.00607500000000001;0.00047400000000000
7;0.00633200000000002;0.00059600000000000
8;0.00651200000000000;0.00077000000000000
9;0.00679999999999998;0.00088800000000000
10;0.00690799999999997;0.00093600000000000
20;0.00881400000000000;0.00188800000000000
30;0.01110500000000000;0.00308100000000000
40;0.01380300000000000;0.00416600000000000
50;0.01744700000000000;0.00563000000000000
60;0.02035800000000000;0.00680900000000001
70;0.02407600000000000;0.00820300000000001
80;0.02794400000000000;0.00928900000000000
90;0.03238200000000000;0.01039000000000000
100;0.03820100000000000;0.01162200000000000
200;0.09925500000000000;0.02850100000000000
300;0.19628100000000000;0.04459999999999990
400;0.29108000000000000;0.06029799999999990
500;0.42527000000000000;0.07618300000000010
600;0.58424000000000000;0.09287300000000000
700;0.79010700000000000;0.11013500000000000
800;0.98573400000000000;0.12708500000000000
900;1.21879600000000000;0.14422200000000000
1000;1.48462400000000000;0.16221400000000000
2000;5.56059100000000000;0.35208600000000000
3000;12.10970900000000000;0.54000899999999900
4000;21.03929400000000000;0.72470000000000000
5000;32.41173900000000000;0.91246400000000100
6000;46.36602000000000000;1.11181800000000000
7000;62.61670900000000000;1.30629200000000000
8000;81.58859900000000000;1.51091900000000000
9000;102.89399700000000000;1.71370300000000000
10000;126.75557200000000000;1.92297700000000000
25000;844.62786300000000000;5.06326700000000000
50000;3816.58308900000000000;10.59345300000000000
75000;8806.76242100000000000;16.10985800000000000
100000;15800.83862700000000000;22.00894600000000000
1000000;1606761.62740000000000000;232.43642700000000000
10000000;;2462.02062400000000000
100000000;;25872.93018000000000000
1000000000;;274393.61750000000000000

答案1

您可以在 中检查 gnuplot 的输出<filename>.pgf-plot.table。显然,前 ~300 个条目有“type=u”(似乎意味着“无界”)。Pgfplots 忽略了该标志(也许它应该处理它),这就是它产生错误输出的原因。

如果我使用 pgfplots 生成趋势线,我会得到与 gnuplot 相同的数据点 - 除了 pgfplots 会自动跳过所有无界坐标。

所有这些无界值都与趋势线的负函数值相关,并且负值的对数是未定义的。

相关内容