本文整理汇总了Python中history.History.add_population方法的典型用法代码示例。如果您正苦于以下问题:Python History.add_population方法的具体用法?Python History.add_population怎么用?Python History.add_population使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类history.History
的用法示例。
在下文中一共展示了History.add_population方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Algorithm
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add_population [as 别名]
class Algorithm(object):
"""
Runs the wintermute algorithm
"""
def __init__(self, model, options):
"""
Initialize the algorithm
:return: None
"""
self._model = model
self._options = options
self._history = History()
self._surrogate = None
self._rnd = None
def run(self):
"""
Run the optimization algorithm
:return: The run history
:rtype: History
"""
self._rnd = Random()
# TODO (JLD): Set the seed from the options
self._rnd.seed()
# Determine the initial population size based on the requirements for an initial surrogate model
parent_pop = self.get_initial_population()
# Evaluate the initial population
self.evaluate(parent_pop)
self._history.add_population(parent_pop)
# Generate a surrogate model
self._surrogate = Surrogate(parent_pop)
# Apply the moving operators to generate a child population
self.sort_population(parent_pop)
pop_size = self.culling_function(len(parent_pop))
child_pop = [ind.copy() for ind in parent_pop[0:pop_size]]
# Flag children for movement
for ind in child_pop:
if
# Sort the parent population and using the culling function, select the N+1 population size of individual
# to apply the moving operators on
# flag individuals for movement
# Apply the global moving operator
# Apply the local moving operator
# Sort the combined parent and child population and select the best N+1 population size individuals
# to become the new parent population
# Check convergence (depends on dynamic culling functions as well)
# Repeat
pass
def set_model(self, model):
"""
Set the model for the algorithm to use
:param model: The model to set
:type model: Model
:return: None
"""
self._model = model
def set_options(self, options):
"""
Set the algorithm options
:param options: The options to set
:type options: Options
:return: None
"""
self._options = options
def get_initial_population(self):
"""
Generate an initial populaion
:return: An initial population
:rtype: list(Individual)
"""
# Determine the initial population size
# Initial popualtion size depends on the number of dimensions and minimum number of points
# to generate an initial surrogate model
# Rule of thumb (D+1)(D+2)
# Require 2x the number of points 1) L2 Orthogonal Array 2) Latin Hypercube
# TODO (JLD): Look into DOE methods for large dimensionality space
# Given the model bounds, first generate an L2 orthogonal array DOE of size (n/2) and initialize
# the individuals at those points, and add them to the list.
# Then for the remaining n/2 individual, initialize them using a latin hypercube sampling and add them
# to the list
# return the population
return []
def get_initial_population_size(self):
"""
Get the initial population size
#.........这里部分代码省略.........