动态聚类中 C-均值算法 (K-均值算法)的C++实现

一:说明

动态聚类方法是模式识别中一种普遍采用的方法,它具有以下3个要点:

    1:选定某种距离度量作为样本间的相似性度量

    2:确定某个评价聚类结果质量的准则函数

    3:给定某个初始分类,然后用迭代算法找出使准则函数取极值的最好的聚类结果

本文给出了 C-均值算法 的 C++  实现。

(算法描述参见  边肇祺  张学工等  << 模式识别 >> P237 清华大学出版社)

 

二:源码

 

2.1  头文件

 

#pragma once

#include <list>

#include <vector>

using namespace std;

#define DATANUM 19

#define MAXDIST 333333

 

struct CData

{

    int x1;

    int x2;

};

 

 

class CCMean

{

public:

    CCMean(CData *pdata);

    ~CCMean(void);

    void init(); 

    void work(int InitClassNum);

 

private:

    // calculate the mean of class i:

    void CalcuMean( int i );

 

    // calculate the ERROR of class i:

    void CalcuJc(int i);

    void CalcuJe();

 

    // step 1 of C-Mean algorithm

    void InitDeploy();

 

    // step 4 and 5 of C-Mean algorithm

    // da is now in class i,

    // return ture when moving da from class to class k

    // return false when we do not move da

    bool MoveItoK( const CData& da, int i, int &k );

 

    // calculate the distance of to data:

    int  dist( const CData& mean, const CData& da);

 

    // print result:

    void OutPut();

 

 

    // iClassNum is the initial class number, in text book, iClassNum <==> C

    int iClassNum;

 

    // pointer to data array:

    CData *pData;

 

    // store the mean of all classes. just ueses 0 to iClassNum - 1;

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值