state.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:PonyGE2 作者: PonyGE 项目源码 文件源码
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']
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号