... | @@ -2,6 +2,14 @@ |
... | @@ -2,6 +2,14 @@ |
|
|
|
|
|
An implementation of several strategies for efficient k-means clustering. Given a dataset and a value of k, this computes and returns a k-means clustering on that data.
|
|
An implementation of several strategies for efficient k-means clustering. Given a dataset and a value of k, this computes and returns a k-means clustering on that data.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
:- use_module('path/to/.../src/methods/kmeans/kmeans.pl').
|
|
|
|
|
|
|
|
%% usage example
|
|
|
|
TrainData = [5.1,3.5,1.4, 4.9,3.0,1.4, 4.7,3.2,1.3, 4.6,3.1,1.5],
|
|
|
|
naiveKMeans(1000, randomPartition, maxVarianceNewCluster, TrainData, 3, 2, AssignmentsList, CentroidsList, _).
|
|
|
|
```
|
|
|
|
|
|
# Available Predicates
|
|
# Available Predicates
|
|
|
|
|
|
* [naiveKMeans/9](/PrologMethods/Clustering/kmeans#naivekmeans9)
|
|
* [naiveKMeans/9](/PrologMethods/Clustering/kmeans#naivekmeans9)
|
... | @@ -19,14 +27,21 @@ An implementation of several strategies for efficient k-means clustering. Given |
... | @@ -19,14 +27,21 @@ An implementation of several strategies for efficient k-means clustering. Given |
|
Runs kmeans with naive as the algorithm for the Lloyd iteration.
|
|
Runs kmeans with naive as the algorithm for the Lloyd iteration.
|
|
|
|
|
|
```prolog
|
|
```prolog
|
|
%% part of the predicate definition
|
|
%% predicate definition
|
|
naiveKMeans( +integer,
|
|
naiveKMeans(MaxIterations, InitialPartition, EmptyCluster, DataList, DataRows, Clusters, AssignmentsList, CentroidsList, ZCols) :-
|
|
+string,
|
|
MaxIterations >= 0,
|
|
+string,
|
|
Clusters > 0,
|
|
|
|
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrows, X)),
|
|
|
|
naiveKMeansI(MaxIterations, InitialPartition, EmptyCluster, X, Xsize, Xrows, Clusters, Y, Ysize, Z, ZCols, ZRows),
|
|
|
|
convert_float_array_to_list(Y, Ysize, AssignmentsList),
|
|
|
|
convert_float_array_to_2d_list(Z, ZCols, ZRows, CentroidsList).
|
|
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
|
foreign(naiveKMeans, c, naiveKMeansI( +integer, +string, +string,
|
|
+pointer(float_array), +integer, +integer,
|
|
+pointer(float_array), +integer, +integer,
|
|
+integer,
|
|
+integer,
|
|
-pointer(float_array), -integer,
|
|
-pointer(float_array), -integer,
|
|
-pointer(float_array), -integer, -integer).
|
|
-pointer(float_array), -integer, -integer)).
|
|
```
|
|
```
|
|
|
|
|
|
### Parameters
|
|
### Parameters
|
... | @@ -48,14 +63,21 @@ naiveKMeans( +integer, |
... | @@ -48,14 +63,21 @@ naiveKMeans( +integer, |
|
Runs kmeans with dualtree as the algorithm for the Lloyd iteration.
|
|
Runs kmeans with dualtree as the algorithm for the Lloyd iteration.
|
|
|
|
|
|
```prolog
|
|
```prolog
|
|
%% part of the predicate definition
|
|
%% predicate definition
|
|
dualTreeKMeans( +integer,
|
|
dualTreeKMeans(MaxIterations, InitialPartition, EmptyCluster, DataList, DataRows, Clusters, AssignmentsList, CentroidsList, ZCols) :-
|
|
+string,
|
|
MaxIterations >= 0,
|
|
+string,
|
|
Clusters > 0,
|
|
|
|
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrows, X)),
|
|
|
|
dualTreeKMeansI(MaxIterations, InitialPartition, EmptyCluster, X, Xsize, Xrows, Clusters, Y, Ysize, Z, ZCols, ZRows),
|
|
|
|
convert_float_array_to_list(Y, Ysize, AssignmentsList),
|
|
|
|
convert_float_array_to_2d_list(Z, ZCols, ZRows, CentroidsList).
|
|
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
|
foreign(dualTreeKMeans, c, dualTreeKMeansI( +integer, +string, +string,
|
|
+pointer(float_array), +integer, +integer,
|
|
+pointer(float_array), +integer, +integer,
|
|
+integer,
|
|
+integer,
|
|
-pointer(float_array), -integer,
|
|
-pointer(float_array), -integer,
|
|
-pointer(float_array), -integer, -integer).
|
|
-pointer(float_array), -integer, -integer)).
|
|
```
|
|
```
|
|
|
|
|
|
### Parameters
|
|
### Parameters
|
... | @@ -77,14 +99,21 @@ dualTreeKMeans( +integer, |
... | @@ -77,14 +99,21 @@ dualTreeKMeans( +integer, |
|
Runs kmeans with elkan as the algorithm for the Lloyd iteration.
|
|
Runs kmeans with elkan as the algorithm for the Lloyd iteration.
|
|
|
|
|
|
```prolog
|
|
```prolog
|
|
%% part of the predicate definition
|
|
%% predicate definition
|
|
elkanKMeans( +integer,
|
|
elkanKMeans(MaxIterations, InitialPartition, EmptyCluster, DataList, DataRows, Clusters, AssignmentsList, CentroidsList, ZCols) :-
|
|
+string,
|
|
MaxIterations >= 0,
|
|
+string,
|
|
Clusters > 0,
|
|
|
|
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrows, X)),
|
|
|
|
elkanKMeansI(MaxIterations, InitialPartition, EmptyCluster, X, Xsize, Xrows, Clusters, Y, Ysize, Z, ZCols, ZRows),
|
|
|
|
convert_float_array_to_list(Y, Ysize, AssignmentsList),
|
|
|
|
convert_float_array_to_2d_list(Z, ZCols, ZRows, CentroidsList).
|
|
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
|
foreign(elkanKMeans, c, elkanKMeansI( +integer, +string, +string,
|
|
+pointer(float_array), +integer, +integer,
|
|
+pointer(float_array), +integer, +integer,
|
|
+integer,
|
|
+integer,
|
|
-pointer(float_array), -integer,
|
|
-pointer(float_array), -integer,
|
|
-pointer(float_array), -integer, -integer).
|
|
-pointer(float_array), -integer, -integer)).
|
|
```
|
|
```
|
|
|
|
|
|
### Parameters
|
|
### Parameters
|
... | @@ -106,14 +135,21 @@ elkanKMeans( +integer, |
... | @@ -106,14 +135,21 @@ elkanKMeans( +integer, |
|
Runs kmeans with hamerly as the algorithm for the Lloyd iteration.
|
|
Runs kmeans with hamerly as the algorithm for the Lloyd iteration.
|
|
|
|
|
|
```prolog
|
|
```prolog
|
|
%% part of the predicate definition
|
|
%% predicate definition
|
|
hamerlyKMeans( +integer,
|
|
hamerlyKMeans(MaxIterations, InitialPartition, EmptyCluster, DataList, DataRows, Clusters, AssignmentsList, CentroidsList, ZCols) :-
|
|
+string,
|
|
MaxIterations >= 0,
|
|
+string,
|
|
Clusters > 0,
|
|
|
|
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrows, X)),
|
|
|
|
hamerlyKMeansI(MaxIterations, InitialPartition, EmptyCluster, X, Xsize, Xrows, Clusters, Y, Ysize, Z, ZCols, ZRows),
|
|
|
|
convert_float_array_to_list(Y, Ysize, AssignmentsList),
|
|
|
|
convert_float_array_to_2d_list(Z, ZCols, ZRows, CentroidsList).
|
|
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
|
foreign(hamerlyKMeans, c, hamerlyKMeansI( +integer, +string, +string,
|
|
+pointer(float_array), +integer, +integer,
|
|
+pointer(float_array), +integer, +integer,
|
|
+integer,
|
|
+integer,
|
|
-pointer(float_array), -integer,
|
|
-pointer(float_array), -integer,
|
|
-pointer(float_array), -integer, -integer).
|
|
-pointer(float_array), -integer, -integer)).
|
|
```
|
|
```
|
|
|
|
|
|
### Parameters
|
|
### Parameters
|
... | @@ -135,14 +171,21 @@ hamerlyKMeans( +integer, |
... | @@ -135,14 +171,21 @@ hamerlyKMeans( +integer, |
|
Runs kmeans with pelleg morre as the algorithm for the Lloyd iteration.
|
|
Runs kmeans with pelleg morre as the algorithm for the Lloyd iteration.
|
|
|
|
|
|
```prolog
|
|
```prolog
|
|
%% part of the predicate definition
|
|
%% predicate definition
|
|
pellegMooreKMeans( +integer,
|
|
pellegMooreKMeans(MaxIterations, InitialPartition, EmptyCluster, DataList, DataRows, Clusters, AssignmentsList, CentroidsList, ZCols) :-
|
|
+string,
|
|
MaxIterations >= 0,
|
|
+string,
|
|
Clusters > 0,
|
|
|
|
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrows, X)),
|
|
|
|
pellegMooreKMeansI(MaxIterations, InitialPartition, EmptyCluster, X, Xsize, Xrows, Clusters, Y, Ysize, Z, ZCols, ZRows),
|
|
|
|
convert_float_array_to_list(Y, Ysize, AssignmentsList),
|
|
|
|
convert_float_array_to_2d_list(Z, ZCols, ZRows, CentroidsList).
|
|
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
|
foreign(pellegMooreKMeans, c, pellegMooreKMeansI( +integer, +string, +string,
|
|
+pointer(float_array), +integer, +integer,
|
|
+pointer(float_array), +integer, +integer,
|
|
+integer,
|
|
+integer,
|
|
-pointer(float_array), -integer,
|
|
-pointer(float_array), -integer,
|
|
-pointer(float_array), -integer, -integer).
|
|
-pointer(float_array), -integer, -integer)).
|
|
```
|
|
```
|
|
|
|
|
|
### Parameters
|
|
### Parameters
|
... | @@ -163,8 +206,8 @@ pellegMooreKMeans( +integer, |
... | @@ -163,8 +206,8 @@ pellegMooreKMeans( +integer, |
|
|
|
|
|
If you want a more detailed explanation, then go to the python documentation. There is most of the time a good explanation on how the methods work and what the parameters do.
|
|
If you want a more detailed explanation, then go to the python documentation. There is most of the time a good explanation on how the methods work and what the parameters do.
|
|
|
|
|
|
* [**MLpack::kmeans_C++\_documentation**](https://www.mlpack.org/doc/stable/doxygen/classmlpack_1_1kmeans_1_1KMeans.html)
|
|
* [**MLpack::kmeans_C++\_documentation**](https://www.mlpack.org/doc/mlpack-3.4.2/doxygen/classmlpack_1_1kmeans_1_1KMeans.html)
|
|
* [**MLpack::kmeans_Python_documentation**](https://www.mlpack.org/doc/stable/python_documentation.html#kmeans)
|
|
* [**MLpack::kmeans_Python_documentation**](https://www.mlpack.org/doc/mlpack-3.4.2/python_documentation.html#kmeans)
|
|
|
|
|
|
added some of the links from the python documentation
|
|
added some of the links from the python documentation
|
|
|
|
|
... | | ... | |