1 简介
本文针对数据聚类分析和最优化问题的相似点,用模拟退火算法进行聚类分析。根据数据对象的特征,提出了基于模拟退火的产生函数和迭代方案。通过实例验证,表明该新算法能够有效地解决数据聚类分析问题。
2 部分代码
% clc;
close all;clear all;
p=[ 1739.94 1675.15 2395.96
373.3 3087.05 2429.47
1756.77 1652 1514.98
864.45 1647.31 2665.9
222.85 3059.54 2002.33
877.88 2031.66 3071.18
1803.58 1583.12 2163.05
2352.12 2557.04 1411.53
401.3 3259.94 2150.98
363.34 3477.95 2462.86
1571.17 1731.04 1735.33
104.8 3389.83 2421.83
499.85 3305.75 2196.22
2297.28 3340.14 535.62
2092.62 3177.21 584.32
1418.79 1775.89 2772.9
1845.59 1918.81 2226.49
2205.36 3243.74 1202.69
2949.16 3244.44 662.42
1692.62 1867.5 2108.97
1680.67 1575.78 1725.1
2802.88 3017.11 1984.98
172.78 3084.49 2328.65
2063.54 3199.76 1257.21
1449.58 1641.58 3405.12
1651.52 1713.28 1570.38
341.59 3076.62 2438.63
291.02 3095.68 2088.95
237.63 3077.78 2251.96
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 1927.4 2328.79
1860.45 1782.88 1875.13
];
[num,n]=size(p); %样品数目
centernum=4; %类别数目
IDXO=[1 2 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ];
% size(IDXO)
CO(1,:)=[ 1739.94 1675.15 2395.96];
CO(2,:)=[373.3 3087.05 2429.47];
CO(3,:)=[1756.77 1652 1514.98];
end
%内层循环结束
T=T*0.9;
% if(T==0)
% break;
% end
time=time+1;
% if(time-timeb>1000)
% break;
% end
disp('已退火次数');
A=time-1
disp('最优目标函数值');
J=JO
end
time1=toc%退火需要的时间
hold on;
plot3(CO(:,1),CO(:,2),CO(:,3),'o');grid;box
%title('蚁群聚类结果(R=100,t=10000)')
xlabel('X')
ylabel('Y')
zlabel('Z')
index1 = find(IDXN == 1)
index2 = find(IDXN == 2)
index3 = find(IDXN == 3)
index4 = find(IDXN == 4)
plot3(p(index1,1),p(index1,2),p(index1,3),'r+');grid;
plot3(p(index2,1),p(index2,2),p(index2,3),'g*');grid;
plot3(p(index3,1),p(index3,2),p(index3,3),'kx');grid;
plot3(p(index4,1),p(index4,2),p(index4,3),'m.');grid;
3 仿真结果
4 参考文献
[1]高亮, 王喆, 孙卫. 基于模拟退火算法的数据聚类分析[J]. 石河子大学学报:自然科学版, 2006, 24(4):3.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。