BuildSysPro.IBPSA.Utilities.Clustering.KMeans

# .BuildSysPro.IBPSA.Utilities.Clustering.KMeans

k-means clustering algorithm

## Information

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)`.

#### Implementation

The seed for random number generation is constant. It can be changed by modifying the constant `seed`.

#### Interface

>     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;

## Revisions

- February 1, 2023, by Michael Wetter:
  Added `impure` declaration which is needed for compliance with the Modelica Language Specification, and is required by Optimica.
- June 9, 2022 by Massimo Cimmino:
  First Implementation

Generated at 2026-05-12T20:19:03Z by OpenModelicaOpenModelica 1.26.7 using GenerateDoc.mos