Prefixed more classes with MLPP.

This commit is contained in:
Relintai 2023-01-25 00:25:18 +01:00
parent d6e9d20c91
commit e399330a6c
6 changed files with 23 additions and 23 deletions

View File

@ -8,7 +8,7 @@
std::tuple<bool, double> HypothesisTesting::chiSquareTest(std::vector<double> observed, std::vector<double> expected) {
std::tuple<bool, double> MLPPHypothesisTesting::chiSquareTest(std::vector<double> observed, std::vector<double> expected) {
double df = observed.size() - 1; // These are our degrees of freedom
double sum = 0;
for (int i = 0; i < observed.size(); i++) {

View File

@ -12,7 +12,7 @@
#include <vector>
class HypothesisTesting {
class MLPPHypothesisTesting {
public:
std::tuple<bool, double> chiSquareTest(std::vector<double> observed, std::vector<double> expected);

View File

@ -13,7 +13,7 @@
#include <random>
KMeans::KMeans(std::vector<std::vector<double>> inputSet, int k, std::string init_type) :
MLPPKMeans::MLPPKMeans(std::vector<std::vector<double>> inputSet, int k, std::string init_type) :
inputSet(inputSet), k(k), init_type(init_type) {
if (init_type == "KMeans++") {
kmeansppInitialization(k);
@ -22,7 +22,7 @@ KMeans::KMeans(std::vector<std::vector<double>> inputSet, int k, std::string ini
}
}
std::vector<std::vector<double>> KMeans::modelSetTest(std::vector<std::vector<double>> X) {
std::vector<std::vector<double>> MLPPKMeans::modelSetTest(std::vector<std::vector<double>> X) {
LinAlg alg;
std::vector<std::vector<double>> closestCentroids;
for (int i = 0; i < inputSet.size(); i++) {
@ -38,7 +38,7 @@ std::vector<std::vector<double>> KMeans::modelSetTest(std::vector<std::vector<do
return closestCentroids;
}
std::vector<double> KMeans::modelTest(std::vector<double> x) {
std::vector<double> MLPPKMeans::modelTest(std::vector<double> x) {
LinAlg alg;
std::vector<double> closestCentroid = mu[0];
for (int j = 0; j < mu.size(); j++) {
@ -49,7 +49,7 @@ std::vector<double> KMeans::modelTest(std::vector<double> x) {
return closestCentroid;
}
void KMeans::train(int epoch_num, bool UI) {
void MLPPKMeans::train(int epoch_num, bool UI) {
double cost_prev = 0;
int epoch = 1;
@ -80,11 +80,11 @@ void KMeans::train(int epoch_num, bool UI) {
}
}
double KMeans::score() {
double MLPPKMeans::score() {
return Cost();
}
std::vector<double> KMeans::silhouette_scores() {
std::vector<double> MLPPKMeans::silhouette_scores() {
LinAlg alg;
std::vector<std::vector<double>> closestCentroids = modelSetTest(inputSet);
std::vector<double> silhouette_scores;
@ -135,7 +135,7 @@ std::vector<double> KMeans::silhouette_scores() {
}
// This simply computes r_nk
void KMeans::Evaluate() {
void MLPPKMeans::Evaluate() {
LinAlg alg;
r.resize(inputSet.size());
@ -162,7 +162,7 @@ void KMeans::Evaluate() {
}
// This simply computes or re-computes mu_k
void KMeans::computeMu() {
void MLPPKMeans::computeMu() {
LinAlg alg;
for (int i = 0; i < mu.size(); i++) {
std::vector<double> num;
@ -183,7 +183,7 @@ void KMeans::computeMu() {
}
}
void KMeans::centroidInitialization(int k) {
void MLPPKMeans::centroidInitialization(int k) {
mu.resize(k);
for (int i = 0; i < k; i++) {
@ -196,7 +196,7 @@ void KMeans::centroidInitialization(int k) {
}
}
void KMeans::kmeansppInitialization(int k) {
void MLPPKMeans::kmeansppInitialization(int k) {
LinAlg alg;
std::random_device rd;
std::default_random_engine generator(rd());
@ -222,7 +222,7 @@ void KMeans::kmeansppInitialization(int k) {
}
}
double KMeans::Cost() {
double MLPPKMeans::Cost() {
LinAlg alg;
double sum = 0;
for (int i = 0; i < r.size(); i++) {

View File

@ -12,9 +12,9 @@
#include <vector>
class KMeans {
class MLPPKMeans {
public:
KMeans(std::vector<std::vector<double>> inputSet, int k, std::string init_type = "Default");
MLPPKMeans(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);

View File

@ -13,11 +13,11 @@
#include <map>
kNN::kNN(std::vector<std::vector<double>> inputSet, std::vector<double> outputSet, int k) :
MLPPKNN::MLPPKNN(std::vector<std::vector<double>> inputSet, std::vector<double> outputSet, int k) :
inputSet(inputSet), outputSet(outputSet), k(k) {
}
std::vector<double> kNN::modelSetTest(std::vector<std::vector<double>> X) {
std::vector<double> MLPPKNN::modelSetTest(std::vector<std::vector<double>> X) {
std::vector<double> y_hat;
for (int i = 0; i < X.size(); i++) {
y_hat.push_back(modelTest(X[i]));
@ -25,16 +25,16 @@ std::vector<double> kNN::modelSetTest(std::vector<std::vector<double>> X) {
return y_hat;
}
int kNN::modelTest(std::vector<double> x) {
int MLPPKNN::modelTest(std::vector<double> x) {
return determineClass(nearestNeighbors(x));
}
double kNN::score() {
double MLPPKNN::score() {
Utilities util;
return util.performance(modelSetTest(inputSet), outputSet);
}
int kNN::determineClass(std::vector<double> knn) {
int MLPPKNN::determineClass(std::vector<double> knn) {
std::map<int, int> class_nums;
for (int i = 0; i < outputSet.size(); i++) {
class_nums[outputSet[i]] = 0;
@ -62,7 +62,7 @@ int kNN::determineClass(std::vector<double> knn) {
return final_class;
}
std::vector<double> kNN::nearestNeighbors(std::vector<double> x) {
std::vector<double> MLPPKNN::nearestNeighbors(std::vector<double> x) {
LinAlg alg;
// The nearest neighbors
std::vector<double> knn;

View File

@ -11,9 +11,9 @@
#include <vector>
class kNN {
class MLPPKNN {
public:
kNN(std::vector<std::vector<double>> inputSet, std::vector<double> outputSet, int k);
MLPPKNN(std::vector<std::vector<double>> inputSet, std::vector<double> outputSet, int k);
std::vector<double> modelSetTest(std::vector<std::vector<double>> X);
int modelTest(std::vector<double> x);
double score();