我有一组向量(曲线),我想匹配到一条曲线。问题不仅仅是找到一组曲线的线性组合,这些曲线将与单个曲线最为匹配(这可以通过最小二乘法Ax=B来实现)。我需要能够添加约束,例如将拟合中使用的曲线数量限制为特定数量,或者曲线彼此相邻。这些约束条件可以在混合整数线性规划优化中找到。
我已经开始使用lsqlin,它允许约束,并且能够将变量限制为>0.0,但在添加更多约束方面,我感到不知所措。有没有一种方法可以将整数约束添加到最小二乘法中,或者有没有一种方法可以用MILP来解决这个问题?
非常感谢在正确方向上的任何帮助!
编辑:
根据ErwinKalvelagen的建议,我正在尝试使用CPLEX及其Quadratic解算器,但到目前为止,我还没有成功地使其工作。我创建了一个最小的“notworking”示例,并上传了
data here
和下面的代码。问题是matlabs LS solver
lsqlin
能够解决,但是CPLEX
cplexlsqnonneglin
退货
CPLEX错误5002:%s不是凸面
对于相同的问题。
function [ ] = minWorkingLSexample( )
%MINWORKINGLSEXAMPLE for LS with matlab and CPLEX
%matlab is able to solve the least squares, CPLEX returns error:
% Error using cplexlsqnonneglin
% CPLEX Error 5002: %s is not convex.
%
%
% Error in Backscatter_Transform_excel2_readMut_LINPROG_CPLEX (line 203)
% cplexlsqnonneglin (C,d);
%
load('C_n_d_2.mat')
lb = zeros(size(C,2),1);
options = optimoptions('lsqlin','Algorithm','trust-region-reflective');
[fact2,resnorm,residual,exitflag,output] = ...
lsqlin(C,d,[],[],[],[],lb,[],[],options);
%% CPLEX
ctype = cellstr(repmat('C',1,size(C,2)));
options = cplexoptimset;
options.Display = 'on';
[fact3, resnorm, residual, exitflag, output] = ...
cplexlsqnonneglin (C,d);
end