Speeding up exhaustive search
4 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Alan Weiss
on 5 Feb 2013
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
0 Comments
More Answers (1)
Doug Hull
on 5 Feb 2013
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.
0 Comments
See Also
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!