How to use set implementation to avoid nested loops in an optimisation algorithm?

2 views (last 30 days)
Hello,
I implemented the following genetic algorithm to optimise the function F without any constraints to find to optimal variables x for any given m-n-u combination. Hence the following nested loop was necessary which seems to me very inefficient.
for index_m = 1:length(m)
m_loc = M(index_m);
for index_n = 1:length(n)
n_loc = n(index_n);
for index_u = 1:length(u)
u_loc = u(index_u);
% OPTIMISATION ALGORITHM
[x,G] = ga(@(x)F(M_loc,n_loc,u_loc,x),2,[],[],[],[],...
[x1_min x1_min], [x1_max x2_max],[],[1,2],options);
% SAVING THE OPTIMAL VALUES
opti_x1(index_m,index_n,index_u)=x(1);
opti_x2(index_m,index_n,index_u)=x(2);
end
end
end
My question is now whether there is a chance to avoid the nested loop by a set implementation within the optimisation function "ga". The aim would be to hand over the whole vectors m,n,u to automatically receive the resulting matrix x containing all the optimal x-values for any m-n-u combination. What would be the syntax for that? Thanks in advance.

Answers (2)

Alan Weiss
Alan Weiss on 6 May 2014
Sorry, the genetic algorithm only optimizes scalar fitness functions. I believe that there is no way to optimize a set of fitness functions at the same time.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 Comment
Matt J
Matt J on 6 May 2014
Edited: Matt J on 6 May 2014
You can scalarize the problem because the different functions have independent argument spaces. In other words, If f1(x), f2(y) are two versions of the objective function (e.g., corresponding to different triplets m,n,u), then you can find the optimal vectors x and y by minimizing the separable function
F(z)=f1(x)+f2(y)
where z is the concatenation z=[x,y]. Extensions to higher dimensions are obvious. However, it may not be the optimal strategy if the solutions vary gradually with m,n,u (see my Answer).

Sign in to comment.


Matt J
Matt J on 6 May 2014
Edited: Matt J on 6 May 2014
The aim would be to hand over the whole vectors m,n,u to automatically receive the resulting matrix x containing all the optimal x-values for any m-n-u combination.
That might not be the best strategy. If F() varies continuously with m,n,u and the different m,n,u that you are supplying change gradually from one data set to the next, it means the solution for the current (m,n,u) should be very close to the solution for the previous (m,n,u). It might therefore be faster to initialize a non-global optimizer with the previous solution x. The incremental refinement of the previous x should be fast, and take fewer iterations as compared to starting from scratch.

Community Treasure Hunt

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

Start Hunting!