def set_state(state):
"""
Given a dictionary representing the state of an evolutionary run, set all
aspects of the system to re-create that state. The state includes the
current population, the current random state, the parameters dictionary,
the stats dictionary, and all lists in the utilities.stats.trackers module.
Sets all aspects of the system and then returns a population of
individuals at the current generation.
:param state: The complete state of a run.
:return: A population of individuals.
"""
from algorithm.parameters import params
from utilities.algorithm.initialise_run import set_param_imports
from stats.stats import stats
from utilities.stats import trackers
from time import time
# Set random state.
random.setstate(state['random_state'])
# Set stats.
for stat in state['stats']:
stats[stat] = state['stats'][stat]
# Set trackers.
for tracker in state['trackers']:
setattr(trackers, tracker, state['trackers'][tracker])
# Set parameters.
for param in state['params']:
params[param] = state['params'][param]
# Set correct param imports for specified function options, including
# error metrics and fitness functions.
set_param_imports()
# Set time adjustment to account for old time.
stats['time_adjust'] = time() - state['time']
return state['individuals']
评论列表
文章目录