小编ero*_*cun的帖子

用线性/非线性回归拟合两条曲线

我需要用 JuMP 将两条曲线(都应该属于三次函数)拟合成一组点。

我已经完成了一条曲线的拟合,但我正在努力将 2 条曲线拟合到同一个数据集中。

我想,如果我可以将点分布到曲线上——所以如果每个点只能使用一次——我可以像下面那样做,但它没有用。(我知道我可以使用更复杂的东西,我想保持简单。)

这是我当前代码的一部分:

# cubicFunc is a two dimensional array which accepts cubicFunc[x,degree]

@variable(m, mult1[1:4]) // 0:3 because it's cubic
@variable(m, mult2[1:4]) // 0:3 because it's cubic

@variable(m, 0 <= includeIn1[1:numOfPoints] <= 1, Int)
@variable(m, 0 <= includeIn2[1:numOfPoints] <= 1, Int)

# some kind of hack to force one of them to 0 and other one to 1
@constraint(m, loop[i in 1:numOfPoints], includeIn1[i] + includeIn2[i] == 1)

@objective(m, Min, sum( (yPoints - cubicFunc*mult1).*includeIn1 .^2 ) …
Run Code Online (Sandbox Code Playgroud)

regression mathematical-optimization curve-fitting julia julia-jump

8
推荐指数
1
解决办法
346
查看次数