Clear Filters
Clear Filters

how to do the exhaustive search?

11 views (last 30 days)
Jason
Jason on 5 Oct 2016
Commented: Jason on 6 Oct 2016
Dear all, I have a function with 7 variables, each variable belong to [0,20]. I want to search directly from the combination of these variables and find the global minimum value. Do you know is there any methods which are fit to this problem? Thank you in advance!

Accepted Answer

Alan Weiss
Alan Weiss on 5 Oct 2016
Perhaps your problem is one of integer values, 0 through 20 for each of your seven variables. If you cannot vectorize your function evaluations, then you are left with the prospect of evaluating the objective function 21^7 ~ 2e9 times, which would be quite time-consuming, but straightforward.
xbest = [0,0,0,0,0,0,0]
fmin = fun(xbest);
for i1 = 0:20
for i2 = 0:20
...
for i7 = 1:20
x = [i1,i2,i3,i4,i5,i6,i7]
f = fun(x)
if f < fmin
xbest = x
fmin = f
end
...
end
If you can vectorize your function evaluation, say x(5), x(6), and x(7), then you will have a much smaller set of indices to loop over. You would, in that example, need to evaluate 21^3 = 9261 function values at once and take the minimum. You would loop over that 21^4 = 194481 times.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  3 Comments
Alan Weiss
Alan Weiss on 5 Oct 2016
Edited: Alan Weiss on 5 Oct 2016
This documentation discusses the theory of vectorization. This documentation from Global Optimization Toolbox describes its use in an optimization problem.
Basically, if you can write your function so that it gives you the value for several variables at once, then you can save time. To vectorize on your last variable, have
fun(x1,x2,x3,x4,x5,x6,:)
return a column vector of all 21 values that come from setting the x7 entry to 0, 1, ..., 20. If you can also have
fun(x1,x2,x3,x4,x5,:,:)
return all 21*21 entries that come from setting x6 and x7 to their various values, even better.
It is up to you to figure out how to write your function to give you these values efficiently, in just one function call rather than in a loop. You might simply want to make a matrix that contains the 21^2 entries (0:20)x(0:20); I mean
[0,0
0,1
...
0,20
1,0
1,1
...
20,20]
and use that as the entry to your program. For example, you could try the following:
[XX YY] = ndgrid(0:20);
pts = [XX(:),YY(:)];
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Jason
Jason on 6 Oct 2016
Alan, Thank you vey much !

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!