Buildings.Utilities.Clustering.Validation

Validation models for clustering functions.

Information

This package contains models for validation of clustering functions. The examples plot various outputs, which have been verified against comparative results. These model outputs are stored as reference data to allow continuous validation whenever models in the library change.

Extends from Modelica.Icons.ExamplesPackage (Icon for packages containing runnable examples).

Package Content

Name Description
Buildings.Utilities.Clustering.Validation.KMeans_1d KMeans_1d Model that verifies the k-means clustering function for 1d data
Buildings.Utilities.Clustering.Validation.KMeans_2d KMeans_2d Model that verifies the k-means clustering function for 2d data

Buildings.Utilities.Clustering.Validation.KMeans_1d Buildings.Utilities.Clustering.Validation.KMeans_1d

Model that verifies the k-means clustering function for 1d data

Information

This example tests the k-means clustering algorithm on 1d data.

Extends from Modelica.Icons.Example (Icon for runnable examples).

Parameters

TypeNameDefaultDescription
Integern_clusters3Number of clusters to be generated
Realdata[:, :][1; 2; 2; 3; 4]Test data to be clustered
IntegernDatsize(data, 1)Number of samples
IntegernDimsize(data, 2)Number of features
Realcentroids[n_clusters, nDim] Centroids of the clusters
Integerlabels[nDat] Cluster label associated with each data point
Integercluster_size[n_clusters] Size of the clusters
IntegerlabelsExp[nDat]{2,2,2,1,3}Expected cluster labels

Modelica definition

model KMeans_1d "Model that verifies the k-means clustering function for 1d data" extends Modelica.Icons.Example; parameter Integer n_clusters = 3 "Number of clusters to be generated"; parameter Real data[:,:] = [1;2;2;3;4] "Test data to be clustered"; parameter Integer nDat = size(data,1) "Number of samples"; parameter Integer nDim = size(data,2) "Number of features"; parameter Real[n_clusters,nDim] centroids(each fixed=false) "Centroids of the clusters"; parameter Integer[nDat] labels(each fixed=false) "Cluster label associated with each data point"; parameter Integer[n_clusters] cluster_size(each fixed=false) "Size of the clusters"; parameter Integer labelsExp[nDat]= {2,2,2,1,3} "Expected cluster labels"; // Comparison result Boolean cmp "Comparison result"; initial equation (centroids, labels, cluster_size) = Buildings.Utilities.Clustering.KMeans( data, n_clusters, nDat, nDim); equation cmp = Modelica.Math.Vectors.isEqual(labels, labelsExp); end KMeans_1d;

Buildings.Utilities.Clustering.Validation.KMeans_2d Buildings.Utilities.Clustering.Validation.KMeans_2d

Model that verifies the k-means clustering function for 2d data

Information

This example tests the k-means clustering algorithm on 2d data.

Extends from Modelica.Icons.Example (Icon for runnable examples).

Parameters

TypeNameDefaultDescription
Integern_clusters3Number of clusters to be generated
Realdata[:, :][1, 1; 1, 2; 2, 1; 2, 1.2; 3...Test data to be clustered
IntegernDatsize(data, 1)Number of samples
IntegernDimsize(data, 2)Number of features
Realcentroids[n_clusters, nDim] Centroids of the clusters
Integerlabels[nDat] Cluster label associated with each data point
Integercluster_size[n_clusters] Size of the clusters
IntegerlabelsExp[nDat]{2,2,1,2,1,3}Expected cluster labels

Modelica definition

model KMeans_2d "Model that verifies the k-means clustering function for 2d data" extends Modelica.Icons.Example; parameter Integer n_clusters = 3 "Number of clusters to be generated"; parameter Real data[:,:]= [ 1, 1; 1, 2; 2, 1; 2, 1.2; 3, 0; 4, 0] "Test data to be clustered"; parameter Integer nDat = size(data,1) "Number of samples"; parameter Integer nDim = size(data,2) "Number of features"; parameter Real[n_clusters,nDim] centroids(each fixed=false) "Centroids of the clusters"; parameter Integer[nDat] labels(each fixed=false) "Cluster label associated with each data point"; parameter Integer[n_clusters] cluster_size(each fixed=false) "Size of the clusters"; parameter Integer labelsExp[nDat]= {2,2,1,2,1,3} "Expected cluster labels"; // Comparison result Boolean cmp "Comparison result"; initial equation (centroids, labels, cluster_size) = Buildings.Utilities.Clustering.KMeans( data, n_clusters, nDat, nDim); equation cmp = Modelica.Math.Vectors.isEqual(labels, labelsExp); end KMeans_2d;