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 Center および File ExchangeSolver 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