AlgoPlus v0.1.0
Loading...
Searching...
No Matches
kmeans Class Reference

#include <kmeans.h>

Public Member Functions

 kmeans (std::vector< std::vector< double > > data, int K, int64_t MAX_ITER=1500)
 Constructor for the kmeans class.
 
 ~kmeans ()
 Destroy the kmeans object.
 
void assign_to_closest (std::vector< double > &x)
 
std::vector< double > get_centroid (std::vector< std::vector< double > > cluster)
 
std::pair< std::vector< std::vector< double > >, std::map< std::vector< double >, int64_t > > fit ()
 

Public Attributes

 data = fill_data()
 
int CLUSTERS = 3
 
dict data_dict
 
 json_object = json.dumps(data_dict)
 
 input_name = open("info.json", 'r')
 
 file = json.load(input_name)
 
 centroids = file['centroids']
 
 assignments = file['assignments']
 
list COLORS = ["red", "green", "orange", "blue", "black", "brown", "purple"]
 
 x
 
 y
 
 x_noise
 
 y_noise
 
int i = 0
 
 x_centroids
 
 y_centroids
 
 colors
 
 color
 

Detailed Description

@ brief Class for the kmeans clustering algorithm

Constructor & Destructor Documentation

◆ kmeans()

kmeans::kmeans ( std::vector< std::vector< double > > data,
int K,
int64_t MAX_ITER = 1500 )
inline

Constructor for the kmeans class.

Parameters
datathe input data(2D vector)
Kthe number of clusters
MAX_ITERdefault 500, maximum iterations till it converges

Member Function Documentation

◆ assign_to_closest()

void kmeans::assign_to_closest ( std::vector< double > & x)
inline

@ brief assign_to_closest function assigns the closest centroid to point x @ param x: the input vector

◆ fit()

std::pair< std::vector< std::vector< double > >, std::map< std::vector< double >, int64_t > > kmeans::fit ( )
inline

@ brief fit function @ return pair<vector<int64_t>, map<int64_t, int> >: the centroids and the assignments of the clustering algorithm

◆ get_centroid()

std::vector< double > kmeans::get_centroid ( std::vector< std::vector< double > > cluster)
inline

@ brief get_centroid function @ param cluster: the input cluster @ return vector<int>: the centroid of the cluster

Member Data Documentation

◆ data_dict

dict kmeans.data_dict
Initial value:
= {
"data":data
}

The documentation for this class was generated from the following files: