本文整理匯總了Python中Problem.Problem.sphere方法的典型用法代碼示例。如果您正苦於以下問題:Python Problem.sphere方法的具體用法?Python Problem.sphere怎麽用?Python Problem.sphere使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Problem.Problem
的用法示例。
在下文中一共展示了Problem.sphere方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: search
# 需要導入模塊: from Problem import Problem [as 別名]
# 或者: from Problem.Problem import sphere [as 別名]
def search(iterations, population, low_bound, high_bound, max_vel, C1, C2, topology, pso_type):
problem = Problem()
fitness = []
pop = create_population(population)
collection = list(enumerate(pop, start=0))
gbest = update_global_best(pop)
lbest = gbest
fbest = gbest
for ite in xrange(iterations):
for i, particle in collection:
if topology == "local":
lbest = update_local_best(pop, i, lbest)
update_velocity(particle, lbest, max_vel, C1, C2, ite, pso_type)
elif topology == "focal":
fbest = update_local_best(pop, i, fbest)
update_velocity(particle, fbest, max_vel, C1, C2, ite, pso_type)
else:
update_velocity(particle, gbest, max_vel, C1, C2, ite, pso_type)
update_position(particle, low_bound, high_bound)
particle.cost = problem.sphere(particle.position)
update_personal_best(particle)
gbest = update_global_best(pop, gbest)
print "Iteration: ", ite, "Fitness: ", gbest.cost
fitness.append(gbest.cost)
return gbest, fitness