How to use the log sum exp function to model this constraint ?

48 views
Skip to first unread message

JackJack

unread,
Sep 1, 2024, 7:35:21 AM9/1/24
to YALMIP
Dear Professor Johan,

How can I model the following log sum exp constraint using the logsumexp function 
ModelEXP.png

I have read the document but due to my background as an engineer and not a mathematician, I find it difficult to understand.


https://yalmip.github.io/tutorial/exponentialcone/


I hope you can provide some assistance.

Thank you very much and best regards.

JackJack

unread,
Sep 1, 2024, 10:39:32 AM9/1/24
to YALMIP
% Define variables
x1 = sdpvar(1);
x2 = sdpvar(1);
x3 = sdpvar(1);
x4 = sdpvar(1);
t = sdpvar(1);
% Define constants (you may need to assign specific values)
c1 = 9; % Example value, adjust as needed
c2 = 100; % Example value, adjust as needed
% Set up the constraint using logsumexp
constraint = logsumexp([x1 - 2*x2 + log(c1), x3 - 6*x4 - log(c2)]) <= t;
% Define the objective
objective = t;
% Set up the optimization problem
ops = sdpsettings('solver', 'mosek'); % Specify MOSEK as the solver
problem = optimize(constraint, objective, ops);
% Check the result
if problem.problem == 0
disp('Solved successfully');
optimal_t = value(t);
optimal_x = [value(x1), value(x2), value(x3), value(x4)];
disp(['Optimal t: ', num2str(optimal_t)]);
disp('Optimal x values:');
disp(optimal_x);
else
disp('Problem encountered');
end Particularly, this code give me a bunch of strange error.

Johan Löfberg

unread,
Sep 2, 2024, 2:02:56 AM9/2/24
to YALMIP
You would have to be way more specific than "a bunch of strange error"

The model is ill-posed though as you can make the vector go to -inf meaning exp will go to 0 meaning log and thus objective will go to -inf

JackJack

unread,
Sep 2, 2024, 7:45:32 AM9/2/24
to YALMIP
Thank you, I have checked again. The strange error is not YALMIP related. The root cause is that because I install both YALMIP and CVX and both of them has the logsumexp function so they are conflicting each other. By uninstalling CVX, everything works fine.

Therefore, my question is now more related to the syntax of of the logsumexp command.

That is "Does this YALMIP syntax (above) correctly represent the mathematical constraint (below) ?"

 

syntax.png

Thank you and best regard !

Mark L. Stone

unread,
Sep 2, 2024, 7:59:11 AM9/2/24
to YALMIP
Rather than uninstalling CVX, you can just get rid of its `logsumexp`, which is just a useless function which says that you should use `log_sum_exp`.

Johan Löfberg

unread,
Sep 2, 2024, 7:59:26 AM9/2/24
to YALMIP

JackJack

unread,
Sep 2, 2024, 8:54:48 AM9/2/24
to YALMIP
Thank you so much Professor Mark and Professor Johan for your support !

@Johan: Are there anyway to contribute to the YALMIP documentation so that it could be clearer ?
I hope to do so because I see that YALMIP is very good but sometime the document is not rich enough.

Johan Löfberg

unread,
Sep 2, 2024, 9:15:14 AM9/2/24
to YALMIP

Just make a pull-request on the repo

Reply all
Reply to author
Forward
0 new messages