Parameter optimization with genetic algorithms
Mostra commenti meno recenti
Hey there,
I have a question concerning GA. I want to optimize several parameter at once by using a function handle. One example is the optimization for a set-up of 2 variables. Each vector consists of 10 possible values so an exhaustive search would comprise 100 trials. Instead of the exhaustive search I want to use GA which for example only needs 20 trials to find the optimal set-up. The optimization function has to be a classification function whose error value should be minimized. How can I implement the 2 variables into the function?
Thanks a lot in advance
Danyo
5 Commenti
Matt J
il 29 Giu 2013
How do you conclude that GA would only require 20 trials?
Daniel
il 29 Giu 2013
Matthew Eicholtz
il 29 Giu 2013
I'm not sure I understand the question. Are you asking how to do a GA on two variables?
Daniel
il 29 Giu 2013
Your question isn't specific enough for us to know what to advise you other than "do what the GA documentation says". Have you done
>> doc ga
What are you looking for beyond what's written there?
Risposte (1)
This page gives an example of ga optimization over integer variables
The example with Rastrigin's Function is a 2 variable problem and shows you how to make one of the variables integer-variable, though of course you could make them both integers if you wished.
20 Commenti
Daniel, If Sigma and C are the unknowns, then the fitness function must be computed in terms of them and you must combine them into one vector. If it's convenient for you, you can unpack them into separate variables inside the workspace of the fitness function
function dy = fitness(Unknowns)
Sigma=Unknowns(1);
C=Unknowns(2);
......
end
You must use constraint arguments and IntCon to specify the range of values sigma and C can assume. For example, if both are integers from 0 to 10, you would do,
lb=[0;0];
ub=[10;10];
IntCon=[1;1];
[x fval] = ga(@fitness, 2,[],[],[],[],lb,ub,[],IntCon);
Daniel
il 30 Giu 2013
No, your fitness function is still wrong. You should have 2 unknowns (sigma and C) not 20. Also, I had IntCon wrong. It should be
IntCon=[1,2]
Daniel
il 1 Lug 2013
Matt J
il 1 Lug 2013
You mean you're still getting "Tenth input argument must be a valid structure created with GAOPTIMSET..."? Is it possible you have an older version of MATLAB?
Daniel
il 1 Lug 2013
Matt J
il 1 Lug 2013
You'll have to run "doc ga" and see if the IntCon input argument is supported in R2008. It looks like it might not be supported and you will have to upgrade if you want integer programming capability.
Sean de Wolski
il 1 Lug 2013
I think it was introduced in 11b era.
Daniel
il 1 Lug 2013
I don't really understand why sigma is discrete. In your expression for the kernel, it looks like sigma is the variance of a Gaussian pmf. So why not allow the optimizer to vary it continuously? And could you do the same with C? If you explain a bit more about the meaning of C,we can analyze whether discrete optimization is really needed and whether the whole thing might be doable via fminunc/fmincon.
Daniel
il 1 Lug 2013
Matt J
il 1 Lug 2013
The setup would be the same as we've been discussing, except that you would omit the IntCon argument. I'm beginning to wonder, though, whether GA is really the appropriate tool here, as opposed to FMINCON. One reason for staying with GA is that it's not obvious whether your objective function is smooth or not. I guess it also depends on whether there are lots of local minima to avoid.
Matt J
il 1 Lug 2013
svmtrain at 186 Group must be a vector.
The error originates in svmtrain, apparently because KLASSE_1 is expected to be a vector, but isn't.
Daniel
il 1 Lug 2013
Daniel
il 1 Lug 2013
Matt J
il 2 Lug 2013
Daniel Commented:
I figured it out. And I have changed the set-up to: options=gaoptimset('Vectorized', 'off') ; [x fval] = ga(@fitness, 2,[],[],[],[],lb,ub,[],options);
Bur Matt, this take forever, and the range for C and Sigma is not even large yet. Is there a way to speed it up? like discrete values as input for C and Sigma so that GA does only have to combine to find the best solution for the SVM?
Many thanks, I know it must sound really stupid, but I am really new to GA especially in MATLAB
Matt J
il 2 Lug 2013
If your fitness function is expensive, then the process will inevitably be slow....
You could try an exhaustive search on a coarse grid sigma=C=1:5:20. From the results of that, you could then do a finer grid optimization with tighter bounds. Or you could do a continuous domain optimization with GA within the tighter bounds.
Categorie
Scopri di più su Genetic Algorithm in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!