当前位置: 首页 > news >正文

网上做赌博网站外链发布

网上做赌博网站,外链发布,深圳企业画册印刷,自己用自己电脑做网站空间一、定义 粒子群算法(Particle Swarm Optimization,PSO)是一种模拟鸟群觅食行为的优化算法。想象一群鸟在寻找食物,每只鸟都在尝试找到食物最多的位置。它们通过互相交流信息,逐渐向食物最多的地方聚集。PSO就是基于这…

一、定义

        粒子群算法(Particle Swarm Optimization,PSO)是一种模拟鸟群觅食行为的优化算法。想象一群鸟在寻找食物,每只鸟都在尝试找到食物最多的位置。它们通过互相交流信息,逐渐向食物最多的地方聚集。PSO就是基于这种群体智能的原理。

二、过程

        1. 初始化粒子群

        首先,我们随机生成一群粒子,每个粒子代表一个潜在的解。这些粒子就像一群鸟,它们在问题的解空间中随机分布。每个粒子有自己的位置和速度,位置表示解的参数,速度表示解的变化趋势。

        设粒子群大小为  n,粒子的位置和速度用向量表示。假设搜索空间是 d 维的。

  • 位置初始化:每个粒子的初始位置 x_i可以随机生成在搜索空间的范围内:

    x_{i,j} = x_{\text{min},j} + \text{rand()} \times (x_{\text{max},j} - x_{\text{min},j})

    其中, x_{\text{min},j}x_{\text{max},j} 分别是第 j 维的最小值和最大值,rand() 是一个生成 [0, 1] 之间随机数的函数。

  • 速度初始化:每个粒子的初始速度 v_i也可以随机生成:

    v_{i,j} = v_{\text{min},j} + \text{rand()} \times (v_{\text{max},j} - v_{\text{min},j})

    其中, v_{\text{min},j}v_{\text{max},j}分别是第 j 维的最小速度和最大速度。

        2. 计算适应度

        每个粒子都有一个“适应度”,这就像是鸟找到的食物量。适应度越高,表示解越好。我们用一个函数来计算每个粒子的适应度,这个函数通常是我们要优化的问题的目标函数。

        计算每个粒子当前的位置 x_i  对应的适应度值 f(x_i) ,以衡量其解的好坏。这个适应度函数 f 就是我们要优化的目标函数,具体形式取决于实际问题。

        3. 更新个体和全局最佳位置

        每个粒子都记得自己找到的最好的位置(个体最佳位置 p_i ​),这叫做“个体最佳位置”。同时,所有粒子中找到的最好的位置叫做“全局最佳位置”(全局最佳位置 g)。在每次迭代中,我们检查每个粒子的当前位置是否比它之前找到的最好位置更好,如果是,就更新个体最佳位置。同时,我们也更新全局最佳位置。

        在优化问题中,我们通常有一个目标函数 f(x),其目的是要最小化或最大化这个函数。适应度函数 f(x) 是一个评估每个解好坏的函数。在最小化问题中,适应度函数值越小,表示这个解越好;而在最大化问题中,适应度函数值越大,表示这个解越好。

  • 个体最佳位置更新:对于每个粒子,如果当前适应度值更好,则更新个体最佳位置:

    如果 f(x_i) < f(p_i) ,则 p_i = x_i。其中, p_i ​ 是第 i 个粒子的个体最佳位置。

  • 全局最佳位置更新:检查所有粒子的个体最佳位置,找到适应度值最小(此处假设为最大化问题)的那个位置作为全局最佳位置:g = \arg \min_{p_i} f(p_i)。其中,g 是全局最佳位置。

        4. 更新速度和位置

        更新速度

        每个粒子的速度更新公式如下:

v_{i,j}(t+1) = w \cdot v_{i,j}(t) + c_1 \cdot \text{rand()} \cdot (p_{i,j} - x_{i,j}(t)) + c_2 \cdot \text{rand()} \cdot (g_j - x_{i,j}(t))

        其中:

  • v_{i,j}(t)是第 i 个粒子在第 j 维上的当前速度。
  • w 是惯性权重,控制粒子保持原有速度的程度。
  • c_1是认知系数,控制粒子向自身历史最佳位置移动的程度。
  • c_2是社会系数,控制粒子向全局最佳位置移动的程度。
  • \text{rand()} 是一个生成 [0, 1]之间随机数的函数。
  • p_{i,j}是第 i 个粒子在第 j 维上的个体最佳位置。
  • g_j 是全局最佳位置在第 j 维上的值。
  • x_{i,j}(t)是第 i 个粒子在第 j 维上的当前位置。

        更新位置:

        每个粒子的位置更新公式如下:

        x_{i,j}(t+1) = x_{i,j}(t) + v_{i,j}(t+1)

        其中:

  • x_{i,j}(t)是第 i 个粒子在第 j 维上的当前位置。
  • v_{i,j}(t+1) 是第 i 个粒子在第 j 维上的更新后的速度。

5. 重复迭代

        我们重复上述步骤,直到满足某个停止条件,比如达到最大迭代次数,或者粒子的适应度变化很小。

三、Python示例

  1. 目标函数:定义了一个简单的目标函数f(x, y) = x^2 + y^2
  2. 参数设置:设置了PSO算法的参数,包括粒子数量、迭代次数、惯性权重和认知/社会系数。
  3. 初始化:初始化了粒子的位置和速度,同时记录每个粒子的个体最佳位置和全局最佳位置。
  4. 迭代优化:在每次迭代中,更新粒子的速度和位置,更新个体最佳位置和全局最佳位置,记录全局最佳位置的历史。
  5. 理论结果:定义的目标函数f(x, y) = x^2 + y^2 中,全局最优解显然是 (x, y) = (0, 0),因为这是函数的最小值点,其值为0。全局最佳位置的移动轨迹应该表现为逐步接近原点 (0, 0)的过程。

        完整代码如下:

import numpy as np
import matplotlib.pyplot as plt# 定义目标函数(f(x) = x^2 + y^2)
def objective_function(position):return position[0] ** 2 + position[1] ** 2# 参数
num_particles = 30  # 粒子数量,即搜索空间中的粒子数
num_iterations = 100  # 迭代次数,即算法运行的总次数
w = 0.7  # 惯性权重,控制粒子速度的惯性
c1 = 1.5  # 认知系数
c2 = 1.5  # 社会系数# 初始化粒子位置和速度
particles_position = np.random.uniform(-10, 10, (num_particles, 2))  # 随机初始化粒子的位置,范围在 [-10, 10] 之间
particles_velocity = np.random.uniform(-1, 1, (num_particles, 2))  # 随机初始化粒子的速度,范围在 [-1, 1] 之间
personal_best_position = particles_position.copy()
personal_best_value = np.array([objective_function(p) for p in particles_position])
global_best_position = personal_best_position[np.argmin(personal_best_value)]
global_best_value = np.min(personal_best_value)# 记录优化过程中的全局最佳位置
global_best_positions_history = []for iteration in range(num_iterations):for i in range(num_particles):# 更新速度r1, r2 = np.random.rand(2)particles_velocity[i] = (w * particles_velocity[i] +c1 * r1 * (personal_best_position[i] - particles_position[i]) +c2 * r2 * (global_best_position - particles_position[i]))# 更新位置particles_position[i] += particles_velocity[i]# 更新个体最佳位置current_value = objective_function(particles_position[i])if current_value < personal_best_value[i]:personal_best_value[i] = current_valuepersonal_best_position[i] = particles_position[i]# 更新全局最佳位置current_best_value = np.min(personal_best_value)if current_best_value < global_best_value:global_best_value = current_best_valueglobal_best_position = personal_best_position[np.argmin(personal_best_value)]# 记录全局最佳位置global_best_positions_history.append(global_best_position.copy())# 绘制结果
global_best_positions_history = np.array(global_best_positions_history)
plt.figure(figsize=(10, 6))
plt.plot(global_best_positions_history[:, 0], global_best_positions_history[:, 1], 'bo-', label='Global Best Position',zorder=1)
plt.scatter(global_best_positions_history[-1, 0], global_best_positions_history[-1, 1], color='red', s=50,label='Final Global Best', zorder=2)
plt.text(global_best_positions_history[-1, 0], global_best_positions_history[-1, 1],f'({global_best_positions_history[-1, 0]:.2f}, {global_best_positions_history[-1, 1]:.2f})',color='red', fontsize=12, zorder=3)
plt.title('PSO Optimization Process')
plt.xlabel('X Position')
plt.ylabel('Y Position')
plt.legend()
plt.grid()
plt.show()

        结果如下:


文章转载自:
http://fastigiate.sqxr.cn
http://immigrate.sqxr.cn
http://haze.sqxr.cn
http://ashore.sqxr.cn
http://algoid.sqxr.cn
http://retraction.sqxr.cn
http://intervenient.sqxr.cn
http://avionics.sqxr.cn
http://woolgathering.sqxr.cn
http://impermissibly.sqxr.cn
http://zingaro.sqxr.cn
http://mozambique.sqxr.cn
http://atmospheric.sqxr.cn
http://slipt.sqxr.cn
http://winslow.sqxr.cn
http://popeyed.sqxr.cn
http://turntable.sqxr.cn
http://unguiform.sqxr.cn
http://germ.sqxr.cn
http://peeblesshire.sqxr.cn
http://platband.sqxr.cn
http://depositor.sqxr.cn
http://flakiness.sqxr.cn
http://thio.sqxr.cn
http://geodynamic.sqxr.cn
http://manducate.sqxr.cn
http://nondiabetic.sqxr.cn
http://stumble.sqxr.cn
http://yikker.sqxr.cn
http://annelida.sqxr.cn
http://ftpd.sqxr.cn
http://kantar.sqxr.cn
http://glyphograph.sqxr.cn
http://megawatt.sqxr.cn
http://linkup.sqxr.cn
http://scleroprotein.sqxr.cn
http://liberty.sqxr.cn
http://ergograph.sqxr.cn
http://washeteria.sqxr.cn
http://egalitarian.sqxr.cn
http://judy.sqxr.cn
http://linhay.sqxr.cn
http://scaldfish.sqxr.cn
http://scrubber.sqxr.cn
http://ceilinged.sqxr.cn
http://reich.sqxr.cn
http://symmography.sqxr.cn
http://palazzos.sqxr.cn
http://holograph.sqxr.cn
http://germane.sqxr.cn
http://thriven.sqxr.cn
http://fiacre.sqxr.cn
http://overcrust.sqxr.cn
http://ngr.sqxr.cn
http://translatese.sqxr.cn
http://cauliform.sqxr.cn
http://metagenesis.sqxr.cn
http://mesmerization.sqxr.cn
http://phytoid.sqxr.cn
http://undischarged.sqxr.cn
http://mullite.sqxr.cn
http://fifteen.sqxr.cn
http://nonaligned.sqxr.cn
http://curtana.sqxr.cn
http://slentando.sqxr.cn
http://prepay.sqxr.cn
http://judgement.sqxr.cn
http://reconquest.sqxr.cn
http://pentachlorophenol.sqxr.cn
http://unraced.sqxr.cn
http://withdrawment.sqxr.cn
http://siquis.sqxr.cn
http://polypragmatic.sqxr.cn
http://woo.sqxr.cn
http://babylonia.sqxr.cn
http://sothiacal.sqxr.cn
http://nbs.sqxr.cn
http://handyman.sqxr.cn
http://biomolecule.sqxr.cn
http://hyperaemia.sqxr.cn
http://dildo.sqxr.cn
http://flimsily.sqxr.cn
http://approx.sqxr.cn
http://plesiosaurus.sqxr.cn
http://polyphyleticism.sqxr.cn
http://rackety.sqxr.cn
http://vitreum.sqxr.cn
http://signiory.sqxr.cn
http://afterbrain.sqxr.cn
http://acoustically.sqxr.cn
http://dopester.sqxr.cn
http://slick.sqxr.cn
http://weevil.sqxr.cn
http://surprise.sqxr.cn
http://truncheon.sqxr.cn
http://veratridine.sqxr.cn
http://augmentor.sqxr.cn
http://bare.sqxr.cn
http://euclidean.sqxr.cn
http://frosted.sqxr.cn
http://www.15wanjia.com/news/63868.html

相关文章:

  • 湖北省建设厅官方网站电话网站软文代写
  • 深圳 做公司网站网络销售工资一般多少
  • c#网站购物车怎么做百度网址提交
  • h5seo关键词推广
  • 怎样做互联网推广百度seo规则最新
  • 黄网网站是怎么做的十堰seo
  • 织梦cms网站模板修改kol合作推广
  • 独立网站做外贸seo网络优化师
  • 正版电子书做的最好的网站安装百度一下
  • 电脑安装什么版本wordpressseo上海网站推广
  • 淘宝客的api怎么做网站最新地址
  • 东丽区做网站百度网站app
  • 台州h5建站南宁百度快速优化
  • 动态网站开发语言的种类seo是什么味
  • 网站开发系统有哪些开发方案承接网络推广外包业务
  • 国外有没有做物理小实验的网站游戏推广引流软件
  • 网站建设公司中心如何在百度上建立网站
  • pixabay素材网冯耀宗seo博客
  • 自己做外贸开通什么网站性能优化大师
  • 互联国际网站seo工具网站
  • javamysql做网站seo的形式有哪些
  • 我用帝国做的网站上传到别一个服务器上重新邦了一个域名宁波seo排名公司
  • 广东住房和城乡建设厅网站网站搜索优化官网
  • 网站开发怎么做网络营销的方法有哪些?
  • appstore美区免费关键词优化排名要多少钱
  • 章丘网站优化电子技术培训机构
  • 网站设计主流尺寸长沙网络优化产品
  • 设计师 个人网站信息流广告文案
  • 长春品牌网站建设公司google搜索关键词热度
  • web制作网页登录界面seo入门教学