Clear Filters
Clear Filters

Can one of MATLAB's optimization algorithms (e.g. particle swarm optimization) take the place of this brute force parameter sweep iteration?

7 views (last 30 days)
I want to find an optimal set of parameters but the time to run through every combination (in a brute force parameter sweep) will be too much computation time. Can particle swarm optimization (or another algorithm) be used instead? The code is not written stricly as a function like the documentation examples use...
I want the values of var1, var2 and var3 that minimize the output value, out1.
var1 = (-60:0.1:60)';
var2 = (-110:0.1:110)';
var3 = (3.5:0.1:18.5)';
% Set up the design matrix, desMat
desMat = {var1,var2,var3};
[desMat{:}]=ndgrid(desMat{:});
n=length(desMat);
desMat = reshape(cat(n+1,desMat{:}),[],n);
parfor kk = 1:NS
var1a = desMat(kk,1); var2a = desMat(kk,2); var3a = desMat(kk,3);
[out1] = Function_Pd(var1a,var2a,var3a);
end

Accepted Answer

Walter Roberson
Walter Roberson on 9 Aug 2022
In theory, NO, none of those functions can take the place of a parameter sweep for a generalized calculation.
There are calculations for which it can be proven that knowing the value of a function at any finite number of locations does not give you information about the value of the function at a given location.
There are functions that there is no known way to calculate, such as the list of locations at which the prime number estimate function swaps between being an overestimate and underestimate.
So, it cannot always be done.
Whether it is possible for your calculation depends upon what you are calculating.
There is a set of functions for which unconstrained Genetic Algorithm is guaranteed to converge. It has been rather some time since I last looked at the relevant theory; my vague memory is that it is not much better than Quadratic functions. Unless, that is, you go by definitions such as https://www.researchgate.net/publication/220616519_Convergence_Criteria_for_Genetic_Algorithms which says that provided that you mutate long enough that you will get convergence (they give upper bounds on number of iterations for some conditions, but I cannot read the paper myself.)
  1 Comment
Paul Safier
Paul Safier on 11 Aug 2022
@Walter Roberson thanks for your input and tip! I was able to couch the function into the form that MATLAB's particle swarm optimization requires and it worked to provide a pretty good result. I don't know if it's the absolute best (global minimum), but it is definitely sufficient for what I need. I may try a genetic algorithm as well and see what that can offer. Thanks again.

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!