聚类算法---MBSAS

算法思路:

确定一种恒量两个数据之间相似度(距离),确定一个阀值theta以及最多能够聚类的类别个数q.先将第一个作为第一类,然后每进入一个样本与之前的所有样本计算距离,当距离大于阀值并且没有达到类别个数的时候,我们将其当作另外一类,否则把它归为离它最近的那个。同时这里与一个类别的距离是与这一类样本的均值(m)的距离,不断更新。

mCnewk=(nCnewk1)mColdk+xnCnewk

function  [bel,m]=MBSAS(X,threshold,q,order)
%Input
%      :the column of X represents a sample
%      :thershold is uesd to divide whether the sample into the C
%      :q is the number of clusters
%      :order represents the order  of presentation of the vectors of X

%Output:
%      :bel is the corresponding label;
%      :m
%---------------------------------Ordering the data------------------------
[l,N]=size(X);
if(length(order)==N)
    X1=[];
    for i=1:N
        X1=[X1 X(:,order(i))];
    end
   X=X1;
   clear X1;
end
%--------------------------------Cluster determining phase-----------------

n_clust=1;
[l,N]=size(X);
bel=zeros(1,N);
bel(1)=n_clust;
m=X(:,1);
for i=2:N
    [m1,m2]=size(m);
    %Dertermining the closest cluster representative
      [s1,s2]=min(sqrt(sum((m-X(:,i)*ones(1,m2)).^2)));
    if (s1>threshold)&&(n_clust<q)
        n_clust=n_clust+1;
        bel(i)=n_clust;
        m=[m X(:,i)];
    end
end
[m1,m2]=size(m);%m2 is the number of cluster
%----------------------------Pattern classification phase-------------------
for i=1:N
    if(bel(i)==0)
        [s1,s2]=min(sqrt(sum((m-X(:,i)*ones(1,m2)).^2)));
        bel(i)=s2;
        m(:,s2)=((sum(bel==s2)-1)*m(:,s2)+X(:,i))/sum(bel==s2);
    end
end






end
算法缺点:

聚类依赖与样本出现的顺序,以及阀值对其结果的影响非常大。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值