Find minimum Sum while keeping variable fix

조회 수: 1 (최근 30일)
Andrea D'Amato
Andrea D'Amato 2021년 3월 9일
댓글: Andrea D'Amato 2021년 3월 10일
Hi guys,
I need a little help with my optimization problem.
I need to find the values of Parameters a and b, such that sum of squared residuals is minimized but while the average of the transformed vector is equal to a given value.
I try to run it with fmincon but this doesn't seem to work for the equality constraint.
function [SSE]=logit3(Par,x)
if nargin<5;
ir=0; %default ir=0
end;
if rows(Par)<cols(Par); % put parameters in column
Par=Par';
end;
if rows(Par)~=3; % check for the the right number of parameters as inputs
error('Dimension of Par not compatible');
end;
%% Assign the Parameters to the Elements in the Vector
a=Par(1);
b=Par(end-1);
meanpd=Par(end);
%%
T=rows(x);
y=zeros(T,1);
res=zeros(T,1);
for i=1:T
y(i)= (1/(1+exp(-(a+b*x(i)))));
res(i)=(y(i)-1).^2;
end
meanpd=mean(y);
SSE=sum(res);
end

답변 (1개)

Alan Weiss
Alan Weiss 2021년 3월 10일
I don't see your equality constraint. If the equality constraint is a nonlinear constraint, you need to pass it in the fmincon nonlcon argument. If it is a linear constraint, pass it as Aeq-beq arguments.
If you need more info or I have misunderstood you, please show us your fmincon call as well as your objective function call.
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 1
Andrea D'Amato
Andrea D'Amato 2021년 3월 10일
Indeed I didn't put the constraint since I use this code as a fucntion to transform my variable x in a logit.
In my "main" code I used this code:
% x is variable
Par=[1;1;0.05];
Aeq=[0 0 1];
beq=0.05;
options=optimset('Display','iter','Algorithm','interior-point','TolFun',0.000001,'TolX',0.000000001,'MaxFunEvals',1000);
[theta]=fmincon('logit3',Par,[],[],Aeq,beq,[],[],[],options,x);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by