Genetic algorithm

General forum for EasySpin: questions, how to's, etc.
Post Reply
cjmagon
Newbie
Posts: 2
Joined: Wed Apr 03, 2024 10:04 am

Genetic algorithm

Post by cjmagon »

I am very grateful for your excellent work on the EasySpin software. It has been fundamental to my research.

At the moment, I have a question. I have not been able to change the "PopulationSize" and "maxGenerations" parameters in the input of the "Genetic" algorithm of "esfit." I am using version 6.0.6. I wonder what I might be doing wrong or overlooking. Could you provide me with a simple example?

katarkon
Local Expert
Posts: 209
Joined: Mon Jan 12, 2015 4:01 am

Re: Genetic algorithm

Post by katarkon »

https://easyspin.org/easyspin/documentation/esfit.html

Parameters for the genetic algorithm:
FitOpt.PopulationSize
A number giving the size of the population, that is the number of parameter sets and simulations in one generation. The default value is 20, but for fittings with many parameters, this value should be increased.
FitOpt.EliteCount
A number specifying the number of populations (ordered in terms of decreasing score) carried over to the next generation without recombination and mutation. The default value is 2 or 10% of the population size, whichever is larger.
FitOpt.maxGenerations
A number specifying the maximum number of generations the algorithm should run. After this number has been reached, the algorithm terminates, no matter how good or bad the best fit so far is. The default value is 10000. A large value is appropriate for fittings with many parameters, if only very few parameters are fitted, maxGenerations can be decreased.
FitOpt.TolFun
Termination tolerance for error function value (default = 1e-5).

cjmagon
Newbie
Posts: 2
Joined: Wed Apr 03, 2024 10:04 am

Re: Genetic algorithm

Post by cjmagon »

Thanks for the answer, but I've already read and re-read the esfit documentation several times.
I think I didn't explain my problem correctly.
My code is the following:

SimOpt.Method = 'matrix';
FitOpt.PopulationSize = 50;
FitOpt.maxGenerations = 50000;
FitOpt.AutoScale = 'lsq';
FitOpt.Method = 'genetic fcn';
esfit(Yexp,@pepper,{{Sys1,Sys2,Sys3,Sys4,Sys5,Sys6},Exp,SimOpt},{{Vary1,Vary2,Vary3,Vary4,Vary5,Vary6}},FitOpt);

And, after run command, the text in the log window of esfit is:

Running optimization algorithm with 9 active parameters...
9 parameters
population 20, elite 2
10000 generations

As you see, the values of population and generations are the default ones: they did not change as I asked for.

tec000
Newbie
Posts: 2
Joined: Fri May 03, 2024 9:38 am

Re: Genetic algorithm

Post by tec000 »

This is a bug that will be fixed in the next release. Thank you for reporting it!

In the meantime, you can change the algorithm options within the GUI through the settings dialog that opens by pressing the button next to the function display and algorithm selection.

Post Reply