资源简介
大学教授编写的粒子群算法代码,MATLAB实现。通用性好,函数参数模块化,有详细的注释,便于移值。直接定义自己的目标函数(适应度函数、代价函数)即可使用。
代码片段和文件信息
%
% Copyright (c) 2016 Yarpiz (www.yarpiz.com)
% All rights reserved. Please read the “license.txt“ for license terms.
%
% Project Code: YTEA101
% Project title: Particle Swarm Optimization Video Tutorial
% Publisher: Yarpiz (www.yarpiz.com)
%
% Developer and Instructor: S. Mostapha Kalami Heris (Member of Yarpiz Team)
%
% Contact Info: sm.kalami@gmail.com info@yarpiz.com
%
function out = PSO(problem params)
%% Problem Definiton
CostFunction = problem.CostFunction; % Cost Function
nVar = problem.nVar; % Number of Unknown (Decision) Variables
VarSize = [1 nVar]; % Matrix Size of Decision Variables
VarMin = problem.VarMin; % Lower Bound of Decision Variables
VarMax = problem.VarMax; % Upper Bound of Decision Variables
%% Parameters of PSO
MaxIt = params.MaxIt; % Maximum Number of Iterations
nPop = params.nPop; % Population Size (Swarm Size)
w = params.w; % Intertia Coefficient
wdamp = params.wdamp; % Damping Ratio of Inertia Coefficient
c1 = params.c1; % Personal Acceleration Coefficient
c2 = params.c2; % Social Acceleration Coefficient
% The Flag for Showing Iteration Information
ShowIterInfo = params.ShowIterInfo;
MaxVelocity = 0.2*(VarMax-VarMin);
MinVelocity = -MaxVelocity;
%% Initialization
% The Particle Template
empty_particle.Position = [];
empty_particle.Velocity = [];
empty_particle.Cost = [];
empty_particle.Best.Position = [];
empty_particle.Best.Cost = [];
% Create Population Array
particle = repmat(empty_particle nPop 1);
% Initialize Global Best
GlobalBest.Cost = inf;
% Initialize Population Members
for i=1:nPop
% Generate Random Solution
particle(i).Position = unifrnd(VarMin VarMax VarSize);
% Initialize Velocity
particle(i).Velocity = zeros(VarSize);
% Evaluation
particle(i).Cost = CostFunction(particle(i).Position);
% Update the Personal Best
particle(i).Best.Position = particle(i).Position;
particle(i).Best.Cost = particle(i).Cost;
% Update Global Best
if particle(i).Best.Cost < GlobalBest.Cost
GlobalBest = particle(i).Best;
end
end
% Array to Hold Best Cost Value on Each Iteration
BestCosts = zeros(MaxIt 1);
%% Main Loop of PSO
for it=1:MaxIt
for i=1:nPop
% Update Velocity
particle(i).Velocity = w*particle(i).Velocity ...
+ c1*rand(VarSize).*(particle(i).Best.Position - particle(i).Position) ...
+ c2*rand(VarSize).*(GlobalBest.Position - particle(i).Position);
% Apply Velocity Limits
particle(i).Velocity = max(particle(i).Velocity MinVelocity);
particle(i).Velocity = min(particle(i).Velocit
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4316 2016-05-20 03:16 PSO.m
文件 1415 2016-05-20 03:16 pso1.m
文件 448 2016-05-20 03:15 Sphere.m
- 上一篇:matlab处理数字图像贴标签
- 下一篇:MT4持仓助手v1.3
相关资源
- matlab处理数字图像贴标签
- MATLAB程序(图像去噪 滤波 锐化 边缘
- MATLAB多径+扩频+rake接受+误码率曲线
- 二维云模型MATLAB
- 用于解决复杂网络社区划分的FastNew
- MIMO 注水算法 Matlab代码
- 分布式电源接入对配电网的影响
- matlab材料力学剪力图弯矩图绘制程序
- 路径规划 matlab
- Matlab图像识别
- 图像滤波Matlab代码
- 微电网光伏并网过程进行仿真microgr
-
双极性SPWM的simuli
nk仿真 - 无网格matlab程序
- 将世界时间转换为格林威治恒星时的
- MATLAB串口采集数据进阶
- MATLABGUI图割法(Grabcut)对象分割
- Matlab光学实验程序
- 人眼识别matlab
- 传染病模型的MATLAB程序和图数学模型
- VREP与MATLAB联合仿真程序--UR5机械臂动
- MATLAB-robotic-toolbox工具箱学习笔记
- 用matlab实现银行卡卡号定位并自动切
- 采用格子bolzmann方法MATLAB模拟圆柱绕流
- matlab 实现语音增强含维纳滤波、谱减
- 费诺编码matlab程序
- 单相桥式整流电路闭环相控调压
- 基于LDA(fisherface)和KNN的人脸识别
- jakes model实现锐利多径的matlab代码
- 用matlab实现均值滤波去除高斯白噪声
评论
共有 条评论