Speeding up exhaustive search

10 次查看(过去 30 天)
I need to find the global minimum of a function using exhaustive search. I have 10 function variables x1,x2,x3,...,x10 ∈ [0,10]. In order to produce all possible combinations of those function variables, i have written a code with 10 for loops and check their value.
Although this works, i would like to speed it up because it takes too much time to finish. Parfor can not help me here because the loops are not independent.
I would like some suggestions on how to speed up this code. Part of my code:
x=zeros(1,10);
for x1=1:10
x(1)=x(1)+step; %step=1 so at each iteration x(1)=1,2,3,...,10
for x2=1:10
if x(2)==10
x(2)=0;
end
x(2)=x(2)+step;
end
repeat for each variable
%evaluate f(x1,x2,x3,...,x10)
end
  4 个评论
Doug Hull
Doug Hull 2013-2-5
Are X1, X2, etc constrained to be integers? It is not clear.
dimitris
dimitris 2013-2-5
Firstly, thank you for replying.
About the subject, the idea is to reduce gradually the step, but first i must speed up my code, because for step=1 it takes too much time, imagine what will happen for step=0.1 or less. I have already used genetic algorithm from optimization toolbox but now i want to do this exhaustively.

请先登录,再进行评论。

采纳的回答

Alan Weiss
Alan Weiss 2013-2-5
If I understand you correctly, you have 11 possible values for each component, so are planning to execute 11^10 evaluations. That is an awful lot of computing.
Is it possible to vectorize your code? If so, you could evaluate, say, 11^5 points at once, return the values, and take the minimum. I mean, write your objective function as a function of a single vector x = (x(1),...,x(10), and evaluate it for all values of x(6),...,x(10) simultaneously. You would have to perform this evaluation only about 11^5 times, once for each possible value of x(1),...,x(5). For an example of what I mean, see this example of evaluating a vectorized function.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

更多回答(1 个)

Doug Hull
Doug Hull 2013-2-5
This is going to be so dependent on your problem.
Is it smooth? Can you start with a 3x3x3x... grid, then search in the most likely areas?
Have you run the profiler? This will tell you where the code is running the slowest.
You will have to show us the algorithm for any realistic help on this. Just modify the question (rather than comment) with the new information.

类别

Help CenterFile Exchange 中查找有关 Surrogate Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by