Effacer les filtres
Effacer les filtres

Find minimum Sum while keeping variable fix

2 vues (au cours des 30 derniers jours)
Andrea D'Amato
Andrea D'Amato le 9 Mar 2021
Commenté : Andrea D'Amato le 10 Mar 2021
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

Réponses (1)

Alan Weiss
Alan Weiss le 10 Mar 2021
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 commentaire
Andrea D'Amato
Andrea D'Amato le 10 Mar 2021
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);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Nonlinear Optimization dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by