生成聚类中心:最大最小距离算法

样本:x0(0 0), x1(3 8), x2(2 2), x3(1 1), x4(5 3), x5(4 8), x6(6 3), x7(5 4), x8(6 4), x9(7 5)


一个粗糙的最大最小距离算法代码

#include 
using namespace std;
const double INF=9999999999999;
const int MAXN=1e6+10;
double D;//Distance limit between different Cluster Centers
int sum;//The number of Pattern
bool isCenter[MAXN];//save Cluster Centers
typedef struct Pattern{
    double x,y;
    int id;
}Pattern;
Pattern node[MAXN];
typedef struct Clusters{
    vector  Cluster_Center;
    vector  Cluster[MAXN];
public:
    bool empty(){
        return Cluster_Center.empty()?1:0;
    }
    void push(Pattern x){
        Cluster_Center.push_back(x);
        return ;
    }
    double dis(Pattern x){
        double mindis=INF,tempdis;
        int len=Cluster_Center.size();
        for(int i=0;imaxndis){
                    newCenter=i;
                    maxndis=tempdis;
                }
            }

        }
        if(maxndis


你可能感兴趣的:(——————札记——————,>模式识别<)