求解带边界约束的非线性最小二乘法 [英] Solver for non-linear least squares with boundary constraints

查看:158
本文介绍了求解带边界约束的非线性最小二乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找Julia中Matlab的 lsqnonlin 函数的类似物.

I'm looking for an analog to Matlab's lsqnonlin function in Julia.

LsqFit.jl 看起来不错,但不接受Matlab实现中的相同参数;具体来说:

LsqFit.jl looks great, but doesn't accept the same arguments Matlab's implementation does; specifically:

  • 下界
  • 上限
  • 初始条件

其中初始条件,下界和上限是长度为6的向量.

where initial conditions, lower, and upper bounds are vectors of length 6.

任何建议都会很棒.谢谢!

Any advice would be awesome. Thanks!

推荐答案

实际上,确实如此,只是自述文件中没有对此进行说明(出于良好的考虑,这里是一个稳定的链接

Actually, it does, it's just not explained in the readme (for good measure, here is a stable link README.md).

目前尚不清楚您所说的初始条件.如果您指的是初始参数,则很有可能.

It is unclear what you mean by initial conditions. If you mean initial parameters, this is very much possible.

using LsqFit

# a two-parameter exponential model
# x: array of independent variables
# p: array of model parameters
model(x, p) = p[1]*exp.(-x.*p[2])

# some example data
# xdata: independent variables
# ydata: dependent variable
xdata = linspace(0,10,20)
ydata = model(xdata, [1.0 2.0]) + 0.01*randn(length(xdata))
p0 = [0.5, 0.5]

fit = curve_fit(model, xdata, ydata, p0)

(摘自手册).这里的 p0 是初始参数向量.

(taken from the manual). Here p0 is the initial parameter vector.

这将为您提供非常接近 [1.0,2.0] 的东西.但是,如果我们想将参数限制在 [0,1] x [0,1] 中怎么办?然后,我们只需将关键字参数 lower upper 设置为上下边界的向量

This will give you something very close to [1.0, 2.0]. But what if we want to constrain the parameter to be in [0,1]x[0,1]? Then we simply set the keyword arguments lower and upper to be vectors of lower and upper bounds

fit = curve_fit(model, xdata, ydata, p0; lower = zeros(2), upper = ones(2))

根据您的确切数据,应该给出类似 [1.0,1.0] 的内容.

That should give something like [1.0, 1.0] depending on your exact data.

这篇关于求解带边界约束的非线性最小二乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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