Skip to content

Commit 9faa627

Browse files
committed
allow HallOfFame files to be read as population_begin.pkl files for initializing evolutionary algorithms
1 parent 3564384 commit 9faa627

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

python/casm/casm/learn/evolve.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import deap.tools
99
import deap.algorithms
1010
from operator import attrgetter
11+
from deap.tools import HallOfFame
1112

1213

1314
def initNRandomOn(container, n_features, n_features_init):
@@ -204,6 +205,7 @@ def initialize_population(n_population, toolbox, filename=None, verbose=True):
204205
"""
205206
if filename is not None and os.path.exists(filename):
206207
load initial population
208+
# may be List[Individual] or HallOfFame, which is converted to List[Individual]
207209
else:
208210
create random initial population of size n_population via toolbox.population
209211
"""
@@ -214,6 +216,9 @@ def initialize_population(n_population, toolbox, filename=None, verbose=True):
214216
print "Loading initial population:", filename
215217
with open(filename, 'rb') as f:
216218
pop = pickle.load(f)
219+
if isinstance(pop, HallOfFame):
220+
# convert to List
221+
pop = [indiv for indiv in pop]
217222
else:
218223
if verbose:
219224
print "Constructing initial population"

python/casm/casm/learn/fit.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,8 @@ def print_input_help():
793793
# Options for "evolve_params_kwargs":
794794
#
795795
# "n_population": int, optional, default=100
796-
# Population size. This many random initial starting individuals are
797-
# created.
796+
# Initial population size. This many random initial starting individuals
797+
# are created if no "pop_begin_filename" file exists.
798798
#
799799
# "n_halloffame": int, optional, default=25
800800
# Maxsize of the hall of fame which holds the best individuals
@@ -819,6 +819,11 @@ def print_input_help():
819819
# exists. For example, if "filename_prefix" is "Ef_kfold10" and
820820
# "pop_begin_filename" is "population_begin.pkl", then the initial
821821
# population is read from the file "Ef_kfold10_population_begin.pkl".
822+
#
823+
# The population file may contain either a list of individual,
824+
# as written to the "population_end.pkl" file, or a HallOfFame
825+
# instance, as written to either an "evolve_halloffame.pkl" file or
826+
# overall casm-learn "halloffame.pkl" file.
822827
#
823828
# "pop_end_filename": string, optional, default="population_end.pkl"
824829
# Filename where the final population is saved. For example, if

0 commit comments

Comments
 (0)