How to continue without solution min max constraint problem.

1 visualizzazione (ultimi 30 giorni)
Hello,
Solving a min max constraint problem in matlab,is a part/function of my whole code. This function finds the optimal linear combination of the distributions, x and y such that it approximates z very good. The problem is that the code is terminated if the optimization problem cannot be solved. In that case I would like to use choose my own values for the optimal parameters.
So I wrote this part in the code:
%If the optimal solution is not found then:
if sum(OptArgum(1:2))<1
OptArgum(1)=0.5;
OptArgum(2)=0.5;
end
But It does not work. So now I am left with two questions:
1) Can you give me some suggestion for better code?
2) How can I add arguments to the code such as 'MaxFunEvals', 1000, 'Maxiter', 1000, such that the code is not terminated easily?
Thank you in advance
This is the code of my function:
function[OptArgum,v]=ModelParametersMinMax (x, y, z)
%This function finds the optimal linear combination of the distributions, x and y such that it approximates z very good. z=a*x+(1-a)*y
%input
% x =The pdf vector of process x
% y =The pdf vector of process y
% z =The pdf vector of all processes together
%output
%OptArgum=A vector that consist of three entrees all coefficients for x,y and z
%v =A linear combination of the x and y such that v can be approximated by: a*x+(1-a)*y
%Construction of the constraint matrix
Aleq=[];
bleq=[];
Aeq=[1 1 0];
beq=1;
%bound of the variables
lb=[0 0 0];
ub=[];
x0=0.1*rand(3,1);%initial guess
Cs=[x y -z];%coefficients of the objective function
% Solving the minmax constraint problem
[OptArgum, ~] = fminimax(@(x) Cs*x,x0,Aleq,bleq(:),Aeq,beq,lb,ub);
%If the optimal solution is not found then:
if sum(OptArgum(1:2))<1
OptArgum(1)=0.5;
OptArgum(2)=0.5;
end
v=OptArgum(1)*xPred + OptArgum(2)*xEstimatedRate;%approximation for z
end

Risposta accettata

Matt J
Matt J il 14 Dic 2018
Modificato: Matt J il 14 Dic 2018
options=optimoptions(@fminimax,__________);
% Solving the minmax constraint problem
[OptArgum, ~,~,exitflag] = fminimax(@(x) Cs*x,x0,Aleq,bleq(:),Aeq,beq,lb,ub,[],options);
%If the optimal solution is not found then:
if exitflag<=0
OptArgum(1)=0.5;
OptArgum(2)=0.5;
end
  1 Commento
Clarisha Nijman
Clarisha Nijman il 15 Dic 2018
Thanks Matt,
This is exactly what I need, if an optimal solution is not found the whole code stops running, but now I know how to prevent that. However, I have to study the exitflag options better.
kind regards

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by