Octave 中的非线性拟合

Nonlinear fits in Octave

目前我正在使用 GNU Octave 的 'optim' 包中的 nonlin_curvefit 函数来将数据与 .但是这次我确实也需要返回参数的不确定性来确定拟合的质量。阅读文档后,我使用函数 curvefit_stat 绑定。 但是,每当我总是在使用此功能时遇到错误并且我无法理解错误消息。我正在使用 Ubuntu 18.04 的默认存储库中的 Octave 4.2.2。

下面是独立的最小示例和错误消息。 Startparameters init_cvg 通常会产生好的结果,而使用 init_dvg 通常会导致不合适:

1;

x = linspace(-2*pi, 2*pi, 600);
ydata = 3.4*sin(1.6*x) + rand(size(x))*1.3;

f = @(p, x) p(1)*sin(p(2).*x);
function y  = testfun(p ,x)
  y = p(1).*sin(p(2).*x);
endfunction

init_cvg = [1; 1.1];
init_dvg = [1; 1.0];

[pc, mod_valc, cvgc, outpc] = nonlin_curvefit(f, init_cvg, x, ydata);
[pd, mod_vald, cvgd, outpd] = nonlin_curvefit(f, init_dvg, x, ydata);


hold off
plot(x, yd, "b.");
hold on;
plot(x, mod_valc, "r-");
plot(x, mod_vald, "color", [0.9 0.4 0.3]);

settings = optimset("ret_covp", true);
covpc = curvefit_stat(f, pc, x, ydata, settings);
covpd = curvefit_stat(f, pd, x, ydata, settings);

puts("sqrt(diag(covpc))")
sqrt(diag(covpc))

puts("sqrt(diag(covpd))")
sqrt(diag(covpd))

当我使用 f 作为模型函数时出现第一个错误消息,当我使用 testfun 代替时出现第二个错误消息:

>> curvefit_stat_TEST
error: label of objective function must be specified
error: called from
    __residmin_stat__ at line 566 column 7
    curvefit_stat at line 56 column 7
    curvefit_stat_TEST at line 25 column 7
>> curvefit_stat_TEST
error: 'p' undefined near line 8 column 7
error: called from
    testfun at line 8 column 5
    curvefit_stat_TEST at line 25 column 7
>>

有人可以确认这个错误吗?

如有任何帮助,我将不胜感激。

我发现了问题。 我需要添加 "abjf_type"、"wls" 作为 optimset 的参数。