HelperA.h 2.26 KB
 Sascha Niklas Schneiders committed Jan 07, 2018 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 ``````#ifndef HELPERA_H #define HELPERA_H #define _GLIBCXX_USE_CXX11_ABI 0 #include #include "armadillo.h" #include #include using namespace arma; class HelperA{ public: static mat getEigenVectors(mat A){ vec eigenValues; mat eigenVectors; eig_sym(eigenValues,eigenVectors,A); return eigenVectors; } static vec getEigenValues(mat A){ vec eigenValues; mat eigenVectors; eig_sym(eigenValues,eigenVectors,A); return eigenValues; } static mat getKMeansClusters(mat A, int k){ mat clusters; kmeans(clusters,A.t(),k,random_subset,20,true); printf("cluster centroid calculation done\n"); std::ofstream myfile; myfile.open("data after cluster.txt"); myfile << A; myfile.close(); std::ofstream myfile2; myfile2.open("cluster centroids.txt"); myfile2 << clusters; myfile2.close(); mat indexedData=getKMeansClustersIndexData(A.t(), clusters); std::ofstream myfile3; myfile3.open("data after index.txt"); myfile3 << indexedData; myfile3.close(); return indexedData; } static mat getKMeansClustersIndexData(mat A, mat centroids){ mat result=mat(A.n_cols, 1); for(int i=0;i