本文整理汇总了Python中scipy.optimize._differentialevolution.DifferentialEvolutionSolver.init_population_random方法的典型用法代码示例。如果您正苦于以下问题:Python DifferentialEvolutionSolver.init_population_random方法的具体用法?Python DifferentialEvolutionSolver.init_population_random怎么用?Python DifferentialEvolutionSolver.init_population_random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.optimize._differentialevolution.DifferentialEvolutionSolver
的用法示例。
在下文中一共展示了DifferentialEvolutionSolver.init_population_random方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_population_initiation
# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import init_population_random [as 别名]
def test_population_initiation(self):
# test the different modes of population initiation
# init must be either 'latinhypercube' or 'random'
# raising ValueError is something else is passed in
assert_raises(ValueError,
DifferentialEvolutionSolver,
*(rosen, self.bounds),
**{'init': 'rubbish'})
solver = DifferentialEvolutionSolver(rosen, self.bounds)
# check that population initiation:
# 1) resets _nfev to 0
# 2) all population energies are np.inf
solver.init_population_random()
assert_equal(solver._nfev, 0)
assert_(np.all(np.isinf(solver.population_energies)))
solver.init_population_lhs()
assert_equal(solver._nfev, 0)
assert_(np.all(np.isinf(solver.population_energies)))
# we should be able to initialise with our own array
population = np.linspace(-1, 3, 10).reshape(5, 2)
solver = DifferentialEvolutionSolver(rosen, self.bounds,
init=population,
strategy='best2bin',
atol=0.01, seed=1, popsize=5)
assert_equal(solver._nfev, 0)
assert_(np.all(np.isinf(solver.population_energies)))
assert_(solver.num_population_members == 5)
assert_(solver.population_shape == (5, 2))
# check that the population was initialised correctly
unscaled_population = np.clip(solver._unscale_parameters(population),
0, 1)
assert_almost_equal(solver.population[:5], unscaled_population)
# population values need to be clipped to bounds
assert_almost_equal(np.min(solver.population[:5]), 0)
assert_almost_equal(np.max(solver.population[:5]), 1)
# shouldn't be able to initialise with an array if it's the wrong shape
# this would have too many parameters
population = np.linspace(-1, 3, 15).reshape(5, 3)
assert_raises(ValueError,
DifferentialEvolutionSolver,
*(rosen, self.bounds),
**{'init': population})
示例2: test_population_initiation
# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import init_population_random [as 别名]
def test_population_initiation(self):
# test the different modes of population initiation
# init must be either 'latinhypercube' or 'random'
# raising ValueError is something else is passed in
assert_raises(ValueError,
DifferentialEvolutionSolver,
*(rosen, self.bounds),
**{'init': 'rubbish'})
solver = DifferentialEvolutionSolver(rosen, self.bounds)
# check that population initiation:
# 1) resets _nfev to 0
# 2) all population energies are np.inf
solver.init_population_random()
assert_equal(solver._nfev, 0)
assert_(np.all(np.isinf(solver.population_energies)))
solver.init_population_lhs()
assert_equal(solver._nfev, 0)
assert_(np.all(np.isinf(solver.population_energies)))