How to restart a script for optimization after shutting down

2 visualizzazioni (ultimi 30 giorni)
I would like to run a genetic algorithm to adjust certain parameters in a simulation that takes a very long time to converge.
Given a population of 50 6-uplets and 100 iterations, I estimate the time needed to converge at just over a week.
The problem is that I can't leave the computer running over the weekend. So my question is, how can I resume the calculation where I left off before switching off the computer?

Risposta accettata

Govind KM
Govind KM il 15 Giu 2023
Modificato: Govind KM il 15 Giu 2023
Hi Jean,
It looks like you basicallly need a way to save the state of the GA before switching off the computer. One way to do this would be to run the algorithm for a specific number of generations (say N) each time. Once the execution of the first N generations is complete, you can get the final population as an output from the ga function, which can then be used for the next set of generations as the initial population. You can run the algorithm in parts in this way, only running it when you are sure that you have the required time to run the specified number of generations. You can reduce N as per the availability of your computer. I assume all other parameters such as fitness function would remain the same between the execution of these generations.
% Create the GA options structure
options = optimoptions('ga');
% Set the population size and the initial population matrix
% Let p be the final population after the execution of the previous set of
% generations
populationSize = size(p, 1);
options.PopulationSize = populationSize;
options.PopulationType = 'custom';
options.InitialPopulationMatrix = p;
You can refer to the following documentation site for detailed information about passing the initial population to the function and getting final population as output :
https://in.mathworks.com/help/gads/ga.html (Input arguments -> Options -> InitialPopulationMatrix, Outputs -> Population)

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by