I need help to to make this work .I am using the quadprog function but i keep getting the problem is non convex.I would be glad if anyone could help.

1 次查看(过去 30 天)
function [x,IC,SST,SSR,SSE]=Constrained_FLSR_1(h)
D=[-0.04844752 0.041968141 -0.044564664 -0.050000004 -0.324629009 -0.148966655;
-0.304020248 0.131284505 0.472041681 0.352249637 0.098999992 0.281067416;
-0.074829705 -0.049999997 -0.094350919 -0.059151836 0.055000007 -0.154999971;
0.28895241 0.390694469 0.416666657 0.408958316 0.497573376 0.360221535;
-0.098011374 0.012270158 -0.067317739 -0.098011397 0.334000021 -0.120833755;
-0.175849974 -0.160909101 -0.174713209 -0.200000003 0.022500008 -0.18519102;
-0.141403094 -0.004999995 -0.098300003 -0.156213611 -0.048067875 -0.136289001;
-0.210274339 -0.191784486 -0.109999985 -0.15615499 -0.070813216 -0.184634596];
% Large data set
Large_Temp=[1:8];
Largetest=[1:8];
Large=union(Large_Temp,Largetest)
h=0.2;
OUT=D(Large,6)
IN=[ones(length(Large),1) D(Large,1:5)]
[M,N]=size(IN)
H=[2*sum(IN(:,1).^2),2*sum(IN(:,1).*IN(:,2)),2*sum(IN(:,3).*IN(:,1)),2*sum(IN(:,4).*IN(:,1)),2*sum(IN(:,5).*IN(:,1)),2*sum(IN(:,6).*IN(:,1)),0,0,0,0,0,0;
2*sum(IN(:,1).*IN(:,2)),2*sum(IN(:,2).^2),2*sum(IN(:,3).*IN(:,2)),2*sum(IN(:,4).*IN(:,2)),2*sum(IN(:,5).*IN(:,2)),2*sum(IN(:,6).*IN(:,2)),0,0,0,0,0,0;
2*sum(IN(:,1).*IN(:,3)),2*sum(IN(:,2).*IN(:,3)),2*sum(IN(:,3).^2), 2*sum(IN(:,4).*IN(:,3)) ,2*sum(IN(:,5).*IN(:,3)) ,2*sum(IN(:,6).*IN(:,3)),0,0,0,0,0,0;
2*sum(IN(:,1).*IN(:,4)),2*sum(IN(:,2).*IN(:,4)),2*sum(IN(:,3).*IN(:,4)),2*sum(IN(:,4)).^2,2*sum(IN(:,5).*IN(:,4)),2*sum(IN(:,6).*IN(:,4)),0,0,0,0,0,0;
2*sum(IN(:,1).*IN(:,5)),2*sum(IN(:,2).*IN(:,5)),2*sum(IN(:,3).*IN(:,5)),2*sum(IN(:,4).*IN(:,5)),2*sum(IN(:,5).^2),2*sum(IN(:,6).*IN(:,5)),0,0,0,0,0,0;
2*sum(IN(:,1).*IN(:,6)),2*sum(IN(:,2).*IN(:,6)),2*sum(IN(:,3).*IN(:,6)),2*sum(IN(:,4).*IN(:,6)),2*sum(IN(:,5).*IN(:,6)),2*sum(IN(:,6).^2),0,0,0,0,0,0;
0,0,0,0,0,0,(1/3)*sum(IN(:,1).^2),(1/3)*sum(IN(:,1).*IN(:,2)),(1/3)*sum(IN(:,1).*IN(:,3)),(1/3)*sum(IN(:,1).*IN(:,4)),(1/3)*sum(IN(:,1).*IN(:,5)),(1/3)*sum(IN(:,1).*IN(:,6));
0,0,0,0,0,0,(1/3)*sum(IN(:,1).*IN(:,2)),(1/3)*sum(IN(:,2).^2),(1/3)*sum(IN(:,2).*IN(:,3)),(1/3)*sum(IN(:,2).*IN(:,4)),(1/3)*sum(IN(:,2).*IN(:,5)),(1/3)*sum(IN(:,2).*IN(:,6));
0,0,0,0,0,0,(1/3)*sum(IN(:,1).*IN(:,3)),(1/3)*sum(IN(:,2).*IN(:,3)),(1/3)*sum(IN(:,3).^2),(1/3)*sum(IN(:,3).*IN(:,4)),(1/3)*sum(IN(:,3).*IN(:,5)),(1/3)*sum(IN(:,3).*IN(:,6));
0,0,0,0,0,0,(1/3)*sum(IN(:,1).*IN(:,4)),(1/3)*sum(IN(:,2).*IN(:,4)),(1/3)*sum(IN(:,3).*IN(:,4)),(1/3)*sum(IN(:,4).^2),(1/3)*sum(IN(:,4).*IN(:,5)),(1/3)*sum(IN(:,4).*IN(:,6));
0,0,0,0,0,0,(1/3)*sum(IN(:,1).*IN(:,5)),(1/3)*sum(IN(:,2).*IN(:,5)),(1/3)*sum(IN(:,3).*IN(:,5)),(1/3)*sum(IN(:,4).*IN(:,5)),(1/3)*sum(IN(:,5).^2),(1/3)*sum(IN(:,5).*IN(:,6));
0,0,0,0,0,0,(1/3)*sum(IN(:,1).*IN(:,6)),(1/3)*sum(IN(:,2).*IN(:,6)),(1/3)*sum(IN(:,3).*IN(:,6)),(1/3)*sum(IN(:,4).*IN(:,6)),(1/3)*sum(IN(:,5).*IN(:,6)),(1/3)*sum(IN(:,5).^2);]
f=[-2*sum(OUT.*IN(:,1));-2*sum(OUT.*IN(:,2));-2*sum(OUT.*IN(:,3));-2*sum(OUT.*IN(:,4));-2*sum(OUT.*IN(:,5));-2*sum(OUT.*IN(:,5));0;0;0;0;0;0]
%A=[-IN -(1-h)*abs(IN);IN -(1-h)*abs(IN);zeros(N,2*N);zeros(N,N) -eye(N,N)]
A=[-IN -(1-h)*(IN);IN -(1-h)*(IN);zeros(N,N) -eye(N,N)]
%b=[-OUT;OUT;zeros(2*N,1)];
b=[-OUT;OUT;zeros(N,1)];
options = optimoptions('quadprog','Algorithm','interior-point-convex');
x=quadprog(H,f,A,b,[],[],[],[],[],options)
antec=x(1:6)
postc=x(7:12)
err=abs(((IN*(antec)-OUT)./OUT))
me=mean(err)
sum1=0;
for i=1:8
sum1=sum1+(err(i,1)-me)^2;
end
voe=sum1/7

采纳的回答

Matt J
Matt J 2018-7-4
编辑:Matt J 2018-7-4
Use fmincon instead. Quadprog cannot handle a non-convex objective with linear inequality constraints that are not simple bounds.
Also, for better performance, use the lb,ub arguments (not A,b) to express pure bounds.
  5 个评论
Matt J
Matt J 2018-7-5
编辑:Matt J 2018-7-5
Yes, you can use all the constraint arguments (A,b,lb,ub,Aeq,beq) simultaneously and +/-Inf are legitimate values in lb,ub.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel Computing Fundamentals 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by