OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
kmeans.h
Go to the documentation of this file.
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// K - M E A N S H E A D E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#pragma once
10
11#include "tensor_utilities.h"
12
13namespace opennn
14{
15
17class KMeans
18{
19
20public:
21
23 KMeans(Index clusters = 3, Index = 100);
24
28
31 VectorR elbow_method(const MatrixR&, Index = 10);
32
34 Index find_optimal_clusters(const VectorR&) const;
35
38
41
43 Index get_clusters_number() const;
44
46 void fit(const MatrixR&);
47
49 void set_cluster_number(const Index);
50
53
54private:
55
56 Index clusters_number;
57 Index maximum_iterations;
58 //string metric;
59
60 MatrixR cluster_centers;
61 VectorI rows_cluster_labels;
62};
63
64}
65
66// OpenNN: Open Neural Networks Library.
67// Copyright(C) 2005-2026 Artificial Intelligence Techniques, SL.
68// Licensed under the GNU Lesser General Public License v2.1 or later.
Index find_optimal_clusters(const VectorR &) const
Returns the cluster count located at the elbow of the supplied distortion curve.
VectorR elbow_method(const MatrixR &, Index=10)
Runs the elbow method on the supplied data over a range of cluster counts.
void set_centers_random(const MatrixR &)
Initializes cluster centres by sampling at random from the supplied data.
void fit(const MatrixR &)
Fits the K-means model on the supplied data matrix.
KMeans(Index clusters=3, Index=100)
Builds a K-means instance with the given cluster count and maximum number of iterations.
MatrixR get_cluster_centers() const
Returns the centroid of each cluster as rows of the returned matrix.
VectorI get_cluster_labels() const
Returns the cluster label assigned to each fitted sample.
Index get_clusters_number() const
Returns the number of clusters configured for the algorithm.
void set_cluster_number(const Index)
Sets the desired number of clusters.
VectorI calculate_outputs(const MatrixR &)
Assigns each row of the input matrix to its nearest cluster.
Definition adaptive_moment_estimation.h:14
Matrix< float, Dynamic, 1 > VectorR
Definition pch.h:181
Matrix< float, Dynamic, Dynamic, Layout > MatrixR
Definition pch.h:177
Matrix< Index, Dynamic, 1 > VectorI
Definition pch.h:182