Skip to main content

Cluster

Base template class representing a cluster of data records.

Template parameters

DatasetT
typename
Dataset type that defines record_type member

Type definitions

dataset_type
DatasetT
Type of the dataset this cluster operates on
record_type
typename DatasetT::record_type
Type of individual records in the dataset

Methods

set_id
void
Sets the cluster identifierParameters:
  • id (std::size_t): Cluster identifier
id
std::size_t
Returns the cluster identifierReturns: The cluster’s ID as std::size_t

Protected members

id_
std::size_t
Cluster identifier (default: 0)
elements_
std::vector<std::shared_ptr<record_type>>
Vector of shared pointers to records belonging to this cluster

Example

#include "Clustering/cluster.hpp"
#include "Clustering/clustering_dataset.hpp"

using namespace mlpp::unsupervised::clustering;

// Define a dataset type
using MyDataset = Dataset<double>;
using MyCluster = Cluster<MyDataset>;

// Create and configure a cluster
MyCluster cluster;
cluster.set_id(1);

std::size_t cluster_id = cluster.id(); // Returns 1

CenterCluster

Template class representing a cluster with a center point, derived from Cluster.

Template parameters

DatasetT
typename
Dataset type that defines record_type member

Type definitions

dataset_type
DatasetT
Type of the dataset this cluster operates on
record_type
typename DatasetT::record_type
Type of individual records in the dataset

Constructors

CenterCluster()
constructor
Default constructor
CenterCluster(center)
constructor
Constructs a cluster with specified centerParameters:
  • center (const std::shared_ptr<record_type>&): Shared pointer to the center record

Methods

center() const
const std::shared_ptr<record_type>&
Returns a const reference to the center pointReturns: Const reference to shared pointer to the center record
center()
std::shared_ptr<record_type>&
Returns a mutable reference to the center pointReturns: Mutable reference to shared pointer to the center record

Protected members

center_
std::shared_ptr<record_type>
Shared pointer to the cluster’s center point

Example

#include "Clustering/cluster.hpp"
#include "Clustering/clustering_dataset.hpp"

using namespace mlpp::unsupervised::clustering;

// Create a center cluster for k-means
using MyDataset = Dataset<double>;
using MyCenterCluster = CenterCluster<MyDataset>;

auto schema = std::make_shared<Schema<double>>();
auto center_record = std::make_shared<Record<double>>(schema);

MyCenterCluster cluster(center_record);
cluster.set_id(0);

// Access the center
auto& center = cluster.center();

SubspaceCluster

Template class representing a subspace cluster with weighted dimensions, derived from CenterCluster.

Template parameters

DatasetT
typename
Dataset type that defines record_type and value_type members

Type definitions

dataset_type
DatasetT
Type of the dataset this cluster operates on
record_type
typename DatasetT::record_type
Type of individual records in the dataset
value_type
typename DatasetT::value_type
Numeric value type for dimension weights

Constructors

SubspaceCluster(center)
constructor
Constructs a subspace cluster with specified centerParameters:
  • center (const std::shared_ptr<record_type>&): Shared pointer to the center record

Methods

w()
std::vector<value_type>&
Returns mutable reference to the weight vectorReturns: Mutable reference to dimension weights
w() const
const std::vector<value_type>&
Returns const reference to the weight vectorReturns: Const reference to dimension weights
w(i)
value_type&
Returns mutable reference to weight at index iParameters:
  • i (std::size_t): Dimension index
Returns: Mutable reference to weight at dimension i
w(i) const
const value_type&
Returns const reference to weight at index iParameters:
  • i (std::size_t): Dimension index
Returns: Const reference to weight at dimension i

Protected members

w_
std::vector<value_type>
Vector of weights for each dimension in the subspace

Example

#include "Clustering/cluster.hpp"
#include "Clustering/clustering_dataset.hpp"

using namespace mlpp::unsupervised::clustering;

// Create a subspace cluster for subspace clustering algorithms
using MyDataset = Dataset<double>;
using MySubspaceCluster = SubspaceCluster<MyDataset>;

auto schema = std::make_shared<Schema<double>>();
auto center_record = std::make_shared<Record<double>>(schema);

MySubspaceCluster cluster(center_record);
cluster.set_id(2);

// Initialize dimension weights
cluster.w() = {0.8, 0.9, 0.1, 0.7};

// Access individual weight
double first_weight = cluster.w(0); // 0.8

Namespace

All cluster classes are defined in the mlpp::unsupervised::clustering namespace.

Build docs developers (and LLMs) love