Skip to content

[pixkit ml] clustering: Data clustering

Yun-Fu Liu edited this page Mar 28, 2014 · 4 revisions

fuzzyCMeans

Cluster the input data of any dimension to several sets by using fuzzy concept.

C++: bool clustering::fuzzyCMeans(const std::vector<<std::vector> &src, std::vector<<std::vector> &dst, const int seedNum, const int K, const double m, const int iterNum, std::vector<<std::vector> &initialPosi = std::vector<<std::vector>(), pixkit::clustering::FUZZYCM_TYPE type = FUZZYCM_RANDPOS);

Parameters:

  • src - Input data.
  • dst - Output data.
  • seedNum - The number of centroid searching processes with different initial seed position (if type=FUZZYCM_RANDPOS is set)
  • K - The number of clusters. For instance, if you want to segment the input data to two different sets, then you must set it to 2.
  • m - The fuzzy coefficient. If set this argument close to 1.0, then the cluster effect like K-Means clustering.
  • iterNum - Convergence condition. The number of iterations during each centroid searching process. The larger the slower.
  • initialPosi - The argument is relate to the type, which is the next argument. The initial position can define by the user or computer.
  • type - If user set the type to FUZZYCM_USERDEFINEPOS, then the initial position will define by the user. If user set the type to FUZZYCM_RANDPOS, then the initial position will define random by the computer.

Return Value:

  • bool - If the function is complete correctly, it will return true.

Example:

std::vector<std::vector<double>> src(2,std::vector<double>(2,0)),dst;
src[0][0] = 1;	src[0][1] = 1; // The set #1's position (1,1)
src[1][0] = 10;	src[1][1] = 2; // The set #2's position (10,2)
pixkit::clustering::fuzzyCMeans(src,dst,1,2,2.0,15);

KMeans

Cluster the input data of any dimension to several sets.

C++: bool clustering::KMeans(std::vector<<std::vector> &src, std::vector<<std::vector> &dst, int K, int iter, pixkit::clustering::KM_TYPE type = KM_RANDPOS);

Parameters:

  • src - Input data.
  • dst - Output data.
  • K - The number of clusters. For instance, if you want to segment the input data to two different sets, then you must set it to 2.
  • iter - Convergence condition. The number of iterations during each centroid searching process. The larger the slower.
  • type - If user set the type to KM_USERDEFINEPOS, then the initial position will define by the user. If user set the type to KM_RANDPOS, then the initial position will define random by the computer.
  • KM_TYPE - If user set the type to 1, then the initial position will define by the user. If user set the type to 2, then the initial position will define random by the computer.

Return Value:

  • bool - If the function is complete correctly, it will return true.

Example:

std::vector<std::vector<double>> src(2,std::vector<double>(2,0)),dst;
src[0][0] = 1;	src[0][1] = 1; // The set #1's position (1,1)
src[1][0] = 10;	src[1][1] = 2; // The set #2's position (10,2)
pixkit::clustering::kMeans(src,dst,2,10);

Clone this wiki locally