Page 1 of 1

Genetic algorithm

Posted: Mon Feb 17, 2025 7:46 am
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?


Re: Genetic algorithm

Posted: Mon Feb 17, 2025 10:47 pm
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).


Re: Genetic algorithm

Posted: Thu Feb 20, 2025 1:23 pm
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.


Re: Genetic algorithm

Posted: Tue Mar 04, 2025 1:14 pm
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.