2023-01-24 18:57:18 +01:00
|
|
|
|
|
|
|
#ifndef MLPP_K_MEANS_H
|
|
|
|
#define MLPP_K_MEANS_H
|
|
|
|
|
2023-01-23 21:13:26 +01:00
|
|
|
//
|
|
|
|
// KMeans.hpp
|
|
|
|
//
|
|
|
|
// Created by Marc Melikyan on 10/2/20.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <string>
|
2023-01-24 19:00:54 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace MLPP {
|
|
|
|
class KMeans {
|
|
|
|
public:
|
|
|
|
KMeans(std::vector<std::vector<double>> inputSet, int k, std::string init_type = "Default");
|
|
|
|
std::vector<std::vector<double>> modelSetTest(std::vector<std::vector<double>> X);
|
|
|
|
std::vector<double> modelTest(std::vector<double> x);
|
|
|
|
void train(int epoch_num, bool UI = 1);
|
|
|
|
double score();
|
|
|
|
std::vector<double> silhouette_scores();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Evaluate();
|
|
|
|
void computeMu();
|
|
|
|
|
|
|
|
void centroidInitialization(int k);
|
|
|
|
void kmeansppInitialization(int k);
|
|
|
|
double Cost();
|
|
|
|
|
|
|
|
std::vector<std::vector<double>> inputSet;
|
|
|
|
std::vector<std::vector<double>> mu;
|
|
|
|
std::vector<std::vector<double>> r;
|
|
|
|
|
|
|
|
double euclideanDistance(std::vector<double> A, std::vector<double> B);
|
|
|
|
|
|
|
|
double accuracy_threshold;
|
|
|
|
int k;
|
2023-01-23 21:13:26 +01:00
|
|
|
|
2023-01-24 19:00:54 +01:00
|
|
|
std::string init_type;
|
|
|
|
};
|
|
|
|
} //namespace MLPP
|
2023-01-23 21:13:26 +01:00
|
|
|
|
|
|
|
#endif /* KMeans_hpp */
|