當前位置: 首頁>>代碼示例>>Python>>正文


Python Problem.sphere方法代碼示例

本文整理匯總了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
開發者ID:rfapo,項目名稱:PSO-python,代碼行數:29,代碼來源:PsoExample.py


注:本文中的Problem.Problem.sphere方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。