【数据聚类】基于蝙蝠算法实现数据聚类附matlab代码

简介: 【数据聚类】基于蝙蝠算法实现数据聚类附matlab代码

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法  神经网络预测雷达通信 无线传感器

信号处理图像处理路径规划元胞自动机无人机

⛄ 内容介绍

聚类分析是近年来迅速发展起来的一种新兴的数据处理技术,它在许多领域有着广泛的应用,尤其是在数据挖掘领域.本文实现基于蝙蝠算法实现数据聚类。

⛄ 部分代码

%%-------------------------------------------------------------------------

% (Citation details):                                                    %

% J. Senthilnath, Sushant Kulkarni, J.A. Benediktsson and X.S. Yang      %

% (2016) "",        %

% IEEE Letters for Geoscience and Remote Sensing Letters,                %

%  Vol. 13, No. 4, pp.599?03.                                           %

%%-------------------------------------------------------------------------


function [best]=Bat_Algorithm(traindat,limits,v)

% Default parameters

n= 5;                                 % Population size, typically 10 to 40

N_gen= 50;                       % Number of generations


% Iteration parameters

A=zeros(n,1);                    % Loudness  (constant or decreasing)

r= zeros(n,1);                    % Pulse rate (constant or decreasing)

% The frequency range determines the scalings

% These values need to be changed as necessary

Qmin=0;                           % Frequency minimum

Qmax=2;                          % Frequency maximum

% Dimension of the search variables

d=v;                                  % Number of dimensions


N_iter=0;                           % Total number of function evaluations


% Upper limit/bounds/ a vector

Ub=limits(1,:);

% Lower limit/bounds/ a vector

Lb=limits(2,:);


% Initializing arrays

Q=zeros(n,1);                     % Frequency of Bats

v=zeros(n,d);                      % Velocities of Bats


% Initialize the population/solutions

for i=1:n,

 Sol(i,:)=Lb+(Ub-Lb).*rand(1,d);

 Fitness(i)=Fun(Sol(i,:));

  r(i)=rand(1);

  A(i)=1+rand(1);

end

r0=r;

plot(Sol(:,1),Sol(:,2),'gs', 'LineWidth',1.5);     % plot initial solutions for visualization

hold on;


% Find the initial best solution

% Here, probable center with least distance in cluster

[fmin, I]=min(Fitness);

best=Sol(I,:);


% Start of iterations -- Bat Algorithm (essential part)  %

for t=1:N_gen

       % Loop over all bats/solutions

       for i=1:n

           Q(i)=Qmin+(Qmax-Qmin)*rand;

           v(i,:)=v(i,:)+(Sol(i,:)-best)*Q(i);

           S(i,:)=Sol(i,:)+v(i,:);

           tem(1,:) = Sol(i,:);                  % Solution before movement

           % Apply simple bounds/limits

           S(i,:)=simplebounds(S(i,:),Lb,Ub);

           % Pulse rate

           if rand>r(i)

               % The factor 0.001 limits the step sizes of random walks

               S(i,:)=S(i,:)+0.001*randn(1,d);

               S(i,:)=simplebounds(S(i,:),Lb,Ub);

           end


          % Evaluate new solutions

          Fnew=Fun(S(i,:));

          % Update if the solution improves, or not too loud

          if (Fnew<=Fitness(i)) && (rand<A(i))

               Sol(i,:)=S(i,:);                   % Replace initial solution with improvised solution

               tem(2,:) = S(i,:);                % Solution after movement

               Fitness(i)=Fnew;              % Replace initial fitness with improvised fitness

               A(i)=0.9*A(i);                  % Update the Loudness of Bats

               r(i)=r0(i)*(1-exp(-0.9*N_gen)); % Update the Pitch of Bats

          end


         % Find and update the current best solution

         if Fnew<=fmin,

               best=S(i,:);

               fmin=Fnew;

         end

       

       % plot the movement of the solutions

       pause(0.005)

       hold on;

       plot(tem(:,1),tem(:,2),'k:');  

     

       end

       N_iter=N_iter+n;

end


% plot the final optimal cluster center

plot(best(1),best(2),'k*', 'LineWidth',3)

legend('Class 1 Training','Class 2 Training','Class 1 Testing','Class 2 Testing ','Agents','Agents Movement','Location','NorthEastOutside')

text(33,23,'* Cluster Centers', 'FontName','Times','Fontsize',12)

 

% Output/display

disp(['Number of evaluations: ',num2str(N_iter)]);

disp(['Best =',num2str(best),' fmin=',num2str(fmin)]);



% Application of simple limits/bounds

   function s=simplebounds(s,Lb,Ub)

       % Apply the lower bound vector

       ns_tmp=s;

       tt=ns_tmp<Lb;

       ns_tmp(tt)=Lb(tt);

 

       % Apply the upper bound vector

       J=ns_tmp>Ub;

       ns_tmp(J)=Ub(J);

       % Update this new move

       s=ns_tmp;

       

    end


⛄ 运行结果

⛄ 参考文献

[1]邹全, 常程威, 贾月月. 基于MATLAB的就业数据的聚类分析[J]. 考试周刊, 2016(53):2.

❤️ 关注我领取海量matlab电子书和数学建模资料
❤️部分理论引用网络文献,若有侵权联系博主删除


相关实践学习
部署高可用架构
本场景主要介绍如何使用云服务器ECS、负载均衡SLB、云数据库RDS和数据传输服务产品来部署多可用区高可用架构。
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
相关文章
|
3天前
|
算法 数据安全/隐私保护 计算机视觉
基于二维CS-SCHT变换和LABS方法的水印嵌入和提取算法matlab仿真
该内容包括一个算法的运行展示和详细步骤,使用了MATLAB2022a。算法涉及水印嵌入和提取,利用LAB色彩空间可能用于隐藏水印。水印通过二维CS-SCHT变换、低频系数处理和特定解码策略来提取。代码段展示了水印置乱、图像处理(如噪声、旋转、剪切等攻击)以及水印的逆置乱和提取过程。最后,计算并保存了比特率,用于评估水印的稳健性。
|
15小时前
|
机器学习/深度学习 算法 API
【Paddle】PCA线性代数基础 + 领域应用:人脸识别算法(1.1w字超详细:附公式、代码)
【Paddle】PCA线性代数基础 + 领域应用:人脸识别算法(1.1w字超详细:附公式、代码)
6 0
|
4天前
|
存储 算法 数据可视化
基于harris角点和RANSAC算法的图像拼接matlab仿真
本文介绍了使用MATLAB2022a进行图像拼接的流程,涉及Harris角点检测和RANSAC算法。Harris角点检测寻找图像中局部曲率变化显著的点,RANSAC则用于排除噪声和异常点,找到最佳匹配。核心程序包括自定义的Harris角点计算函数,RANSAC参数设置,以及匹配点的可视化和仿射变换矩阵计算,最终生成全景图像。
|
4天前
|
算法 Serverless
m基于遗传优化的LDPC码NMS译码算法最优归一化参数计算和误码率matlab仿真
MATLAB 2022a仿真实现了遗传优化的归一化最小和(NMS)译码算法,应用于低密度奇偶校验(LDPC)码。结果显示了遗传优化的迭代过程和误码率对比。遗传算法通过选择、交叉和变异操作寻找最佳归一化因子,以提升NMS译码性能。核心程序包括迭代优化、目标函数计算及性能绘图。最终,展示了SNR与误码率的关系,并保存了关键数据。
13 1
|
4天前
|
算法 关系型数据库 C语言
卡尔曼滤波简介+ 算法实现代码(转)
卡尔曼滤波简介+ 算法实现代码(转)
16 4
|
5天前
|
数据安全/隐私保护
地震波功率谱密度函数、功率谱密度曲线,反应谱转功率谱,matlab代码
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
|
5天前
|
数据安全/隐私保护
耐震时程曲线,matlab代码,自定义反应谱与地震波,优化源代码,地震波耐震时程曲线
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
|
5天前
|
算法 数据安全/隐私保护
matlab程序,傅里叶变换,频域数据,补零与不补零傅里叶变换
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
|
5天前
|
数据安全/隐私保护
matlab 曲线光滑,去毛刺,去离群值,数据滤波,高通滤波,低通滤波,带通滤波,带阻滤波
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
|
5天前
|
数据安全/隐私保护
时域与频域数据互相转换,傅里叶变换与逆傅里叶变换,matlab程序,时域转频域
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度

热门文章

最新文章