This function applies k-means clustering to n-dimentional data and returns the centroid of the clusters, the cluster labels for each sample, and the size of each cluster.
The returned length of the cluster_size
vector is
max(n_clusters, n_cluster_size)
.
The seed for random number generation is constant. It can be changed by
modifying the constant seed
.
impure function KMeans extends Modelica.Icons.Function; input Real data[n_samples, n_features] "Data to be clustered"; input Integer n_clusters "Number of clusters to be generated"; input Integer n_samples "Number of samples"; input Integer n_features "Number of features"; input Real relTol = 1e-5 "Relative tolerance on cluster positions"; input Integer max_iter = 500 "Maximum number of k-means iterations"; input Integer n_init = 10 "Number of runs with randomized centroid seeds"; input Integer n_cluster_size = 0 "Length of the cluster_size output vector"; output Real centroids[n_clusters, n_features] "Centroids of the clusters"; output Integer labels[n_samples] "Cluster label associated with each data point"; output Integer cluster_size[max(n_clusters, n_cluster_size)] "Size of the clusters"; end KMeans;
impure
declaration which is needed for compliance with the Modelica Language Specification,
and is required by Optimica.