How to optimize the rows of a vector given by a self-built function?
Show older comments
Hi,
I have built a function that takes a large number of scalars (x,y,z,w,...) and gives back a long vector Q = buildQ(x,y,z,w,...).
Now I would like to independently optimize (maximize) each line of Q over all (x,y,z,w,...) given some constraints on them (ub and lb).
I would like to use fmincon to do it, however I don't know how to write the objective functions (Q lines) in the form needed to use it, for what I understand the objective function in fmincon should be a function handle that gives back a scalar.
For example I tried writing Q =@(x,y,z,w,...) buildQ(x,y,z,w,...) and then optimize in a loop, but then I can't index the lines like Q(i), or Q(i)(x,y,z,w,...) etc (matlabs gives an error message saying I can't do this). I also tried writing e.x. Q(1) =@(x,y,z,w,...) buildQ(x,y,z,w,...)(1) and it doesn't work for the same reason.
Is there a smart way to do this??
This sounds like it should be an easy task however I'm confused on how to implement it
If anyone can help, it would be great, thanks
Answers (2)
Matt J
on 29 May 2021
0 votes
This sounds like it should be an easy task
Not to me. Is Q(1), Q(2), ...,Q(N) each a function of a different, non-overlapping, independent set of variables?
If so, just feed the scalar objective f(x,y,z..)= sum(Q) to fmincon.
If not, then it is not clear what it means to 'optimize' them. How can you simultaneously minimize a set of quantities that cannot be independently controlled?
4 Comments
Nina
on 29 May 2021
Nina
on 29 May 2021
Well, unless you can modify your buildQ to restrict the computation to only a single Q(i) (see my other answer) then you must settle for the brute force way,
for i=1:N
unknowns = fmincon(@(unknowns) myObjective(unknowns,i), unknowns0, ______)
end
function negQi=myObjective(unknowns,i)
unknowns=num2cell(unknowns);
Q=buildQ(unknowns{:});
negQi=-Q(i);
end
but what I want to do are independent optmizations on each line of Q.
Ideally, you would modify buildQ to let you restrict computation to only a single Q(i) Then you could do N independent optimizations easily in a loop. That would probably be the fastest way, since each Q(i) is a function of a relatively low dimensional space.
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!