pmlpp/mlpp/kmeans/kmeans.h

48 lines
973 B
C
Raw Normal View History

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