📄 kcluster.h
字号:
#pragma once
// K聚类算法
class KCluster
{
private:
// 数据类型
struct DataType
{
double *Data; // 内嵌数据
int Father; // 数据所属簇号
double *Uncle; // 数据和簇中心的距离
};
// 簇类型
struct ClusterType
{
double *Center;
int Sonnum;
};
int DataNum; //聚类样本数目
int Dimension; //样本维数
int ClusterNum; //分类数
DataType *DataMember;
ClusterType *ClusterMember;
ClusterType *NewCluster;
ClusterType *OldCluster;
int ClusterIdxA;
int ClusterIdxB;
bool ClusteringCompleted;
public:
// DataNum 聚类样本数目
// Dimension 样本维数
// ClusterNum 分类数
// DataSet 指向数据集的指针
KCluster(int dataNum, int dimension, int clusterNum, double *DataSet);
~KCluster(void);
void NewCenterPlus(ClusterType *pData, int Idx, double *pValue, int Dimension);
void NewCenterReduce(ClusterType *pData, int Idx, double *pValue, int Dimension);
// 设置数据集
void GetDataSet(DataType *pData, double *pValue, int DataNum, int Dimension);
// 设置数据
void GetValue(double *pValue1, double *pValue2, int Dimension);
int FindFather(double *pValue, int ClusterNum);
double SquareDistance(double *pValue1, double *pValue2, int Dimension);
int Compare(double *pValue1, double *pValue2, int Dimension);
double AimFunction();
// 开始聚类
void StartClustering();
bool SetupClustering();
// 获得聚类Cluster的数据
int GetClusterData(int Cluster, double *DataSet);
int GetClusterCenter(double *Center);
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -