MATLAB Answers


regarding the use of fmincon with large set of data

Asked by Giorgio Biondini on 9 Feb 2018 at 17:52
Latest activity Edited by Giorgio Biondini on 9 Feb 2018 at 21:13

Hi community.

I am using fmincon to find some optimum mix using a large set of data and have come to a couple of doubts.

First the relevant section of my code:

 x0 = [a_ms a_lc a_lr]; %initial state
epsi = 1 ; % Epsilon factor
options =optimoptions('fmincon','Algorithm','active-set') ;
A = [e_ms e_lc e_lr] ; % equation left side
b = epsi*csm ; % equation right side
[x_res,fval] = fmincon(@objfun,x0,A,b,[],[],[],[],[],options);
valopt = x_res(1)*e_ms + x_res(2)*e_lc + x_res(3)*e_lr ;

I want to find the decision variables a_ms, a_lc and a_lr that minimize an objective function objfun . A is a 24000x3 matrix with data of production from three different sources and b is a 240000x1 vector with consumption data. As it is my first time using fmincon, is the approach in the code the correct one to optimize the problem for all the data?

After running the above lines, if I change one parameter in my objective function sometimes I get one of the three optimal values of the result ( x_res(2) ) as a negative, so I was thinking to include a restriction so that none of the decision variables can be less than zero. How can I do this?, shoud I add three more rows at the bottom of A and b in order to reflect this or is there another way?

Thanks beforehand for your help.

Giorgio B.


Log in to comment.

1 Answer

Answer by John D'Errico
on 9 Feb 2018 at 18:22
 Accepted Answer

This is not even remotely a large problem. That you have a moderately large (but not really) array of size 24000x3 is not relevant. What matters are the number of variables. You have THREE variables, which makes this essentially a trivially small problem.

We are not told what objfun does. Is objfun a linear relationship in the parameters? I'm wondering if it is so. If so, then fmincon is not even the right tool to solve this. You might want to use a tool like lsqlin or even linprog.

fmincon, lsqlin, and linprog all allow both linear inequality constraints, as well as bound constraints. Note all of those [] bracket parameters where you passed in nothing to fmincon? consider what the variable called lb would do. lb stands for lower bounds of course. So if it makes no sense for a variable to be negative in your process, then a lower bound of zero will be appropriate.

Sometimes, tools like fmincon can allow a variable to exceed the bound constraints by a tiny amount. If even this is intolerable, then you can always consider working in a log domain. Thus fmincon will optimize the log of the variable. In the function, you would work with exp(x), which is always positive of course. This allows you to approach arbitrarily close to zero, yet not fall below that bound.

  1 Comment

Thanks John.

This set of data is a small sample of the one much larger I want to work with, but it makes sense for the number of variables to be the one that determines the problem's hardship.

The objective function I am using is one of the type


where csm_t is the aforementioned consumption at time t, a_kt each of the (three) decision variables at t, R_kt the production of each source at time t and k1, k2 and lambda some constants.

So I decided to use a nonlinear optimizer as fmincon, but I'm open to a more suited option. Your advice about lower bounds is probably what I need, so I'm going to check it out a little.

Thanks, Giorgio B.

Log in to comment.

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today