1. Introduction
Particle Swarm Optimization, also known as Particle Swarm Optimization or Particle Swarm Optimization, abbreviated as PSO, is a new evolutionary algorithm (Evolutionary Algorithm-EA) developed by J. Kennedy and RC Eberhart in recent years. ). The PSO algorithm is a kind of evolutionary algorithm. It is similar to the simulated annealing algorithm. It also starts from a random solution and finds the optimal solution through iteration. It also evaluates the quality of the solution through fitness, but it is simpler than the rules of genetic algorithm. It does not have the "Crossover" and "Mutation" operations of genetic algorithms. It finds the global optimum by following the current searched optimal value. This algorithm has attracted the attention of academia due to its advantages such as easy implementation, high accuracy, and fast convergence, and has demonstrated its superiority in solving practical problems. Particle swarm algorithm is a parallel algorithm.
Second, the source code
%Kmeans Cluster Algorithm Based on Particle Optimization Algorithm
clc;
clear all;
format long;
tic
data=[1702.8 1639.79 2068.74
1877.93 1860.96 1975.3
867.81 2334.68 2535.1
1831.49 1713.11 1604.68
460.69 3274.77 2172.99
2374.98 3346.98 975.31
2271.89 3482.97 946.7
1783.64 1597.99 2261.31
198.83 3250.45 2445.08
1494.63 2072.59 2550.51
1597.03 1921.52 2126.76
1598.93 1921.08 1623.33
1243.13 1814.07 3441.07
2336.31 2640.26 1599.63
354 3300.12 2373.61
2144.47 2501.62 591.51
426.31 3105.29 2057.8
1507.13 1556.89 1954.51
343.07 3271.72 2036.94
2201.94 3196.22 935.53
2232.43 3077.87 1298.87
1580.1 1752.07 2463.04
1962.4 1594.97 1835.95
1495.18 1957.44 3498.02
1125.17 1594.39 2937.73
24.22 3447.31 2145.01
1269.07 1910.72 2701.97
1802.07 1725.81 1966.35
1817.36 1926.4 2328.79
1860.45 1782.88 1875.13];
%--------参数设定-----------
N=70;%粒子数
c1=1.6;c2=1.6;%设定学习因子值(速度更新参数)
wmax=0.9;wmin=0.4;%设定惯性权重初始及终止值
M=1600;%最大迭代数
K=4;%类别数
[S D]=size(data);%样本数和特征维数
%--------初始化----------------
for i=1:N
clmat(i,:)=randperm(S);%随机取整数
end
clmat(clmat>K)=fix(rand*K+1);%取整函数
fitt=inf*ones(1,N);%初始化个体最优适应度
fg=inf;%初始化群体最优适应度
fljg=clmat(1,:);%当前最优分类
v=rand(N,K*D);%初始速度
x=zeros(N,K*D);%初始化粒子群位置
y=x;%初始化个体最优解
pg=x(1,:);%初始化群体最优解
cen=zeros(K,D);%类别中心定维
fitt2=fitt;%粒子适应度定维
Three, running results
Four, remarks
Complete code or write on behalf of adding QQ1575304183