MLCore::DBSCANOperation
MLCore::DBSCANOperation
DBSCAN clustering wrapping mlpack::DBSCAN. More…
#include <DBSCANOperation.hpp>
Inherits from MLCore::MLModelOperation
Public Classes
| Name | |
|---|---|
| struct | Impl |
Public Functions
| Name | |
|---|---|
| DBSCANOperation() | |
| ~DBSCANOperation() override | |
| DBSCANOperation(DBSCANOperation const & ) =delete | |
| DBSCANOperation & | operator=(DBSCANOperation const & ) =delete |
| DBSCANOperation(DBSCANOperation && ) | |
| DBSCANOperation & | operator=(DBSCANOperation && ) |
| virtual std::string | getName() const override Unique human-readable name for this model (e.g., “Random Forest”). |
| virtual MLTaskType | getTaskType() const override The ML task type this operation supports. |
| virtual std::unique_ptr< MLModelParametersBase > | getDefaultParameters() const override Create a default parameter set for this model. |
| virtual bool | fit(arma::mat const & features, MLModelParametersBase const * params) override Fit the model to unlabeled data (unsupervised). |
| virtual bool | assignClusters(arma::mat const & features, arma::Row< std::size_t > & assignments) override Assign cluster labels to observations. |
| virtual bool | save(std::ostream & out) const override Save the trained model to a stream. |
| virtual bool | load(std::istream & in) override Load a previously saved model from a stream. |
| virtual bool | isTrained() const override Whether the model has been trained (supervised) or fit (unsupervised). |
| virtual std::size_t | numClasses() const override Number of classes (supervised) or clusters (unsupervised). |
| virtual std::size_t | numFeatures() const override Number of features the model was trained on. |
| arma::mat const & | centroids() const Get the fitted cluster centroids. |
| std::size_t | numNoisePoints() const Get the number of noise points from the last fit. |
| double | fittedEpsilon() const Get the epsilon used during fitting. |
Additional inherited members
Public Functions inherited from MLCore::MLModelOperation
| Name | |
|---|---|
| virtual | ~MLModelOperation() =default |
| virtual bool | train(arma::mat const & features, arma::Row< std::size_t > const & labels, MLModelParametersBase const * params) Train the model on labeled data. |
| virtual bool | predict(arma::mat const & features, arma::Row< std::size_t > & predictions) Predict class labels for new observations. |
| virtual bool | predictProbabilities(arma::mat const & features, arma::mat & probabilities) Predict class probabilities for new observations. |
| virtual bool | trainSequences(std::vector< arma::mat > const & featureSequences, std::vector< arma::Row< std::size_t > > const & labelSequences, MLModelParametersBase const * params) Train the model on pre-segmented temporal sequences. |
| virtual bool | predictSequences(std::vector< arma::mat > const & featureSequences, std::vector< arma::Row< std::size_t > > & predictionSequences) Predict labels for pre-segmented temporal sequences. |
| virtual bool | predictSequencesConstrained(std::vector< arma::mat > const & featureSequences, std::vector< arma::Row< std::size_t > > & predictionSequences, std::vector< std::optional< std::size_t > > const & initial_state_constraints) Predict labels with per-sequence initial state constraints. |
| virtual bool | predictSequencesBidirectionalConstrained(std::vector< arma::mat > const & featureSequences, std::vector< arma::Row< std::size_t > > & predictionSequences, std::vector< std::optional< std::size_t > > const & initial_state_constraints, std::vector< std::optional< std::size_t > > const & terminal_state_constraints) Predict labels with both initial and terminal state constraints. |
| virtual bool | predictProbabilitiesPerSequence(std::vector< arma::mat > const & featureSequences, std::vector< arma::mat > & probabilitySequences, std::vector< std::optional< std::size_t > > const & initial_state_constraints, std::vector< std::optional< std::size_t > > const & terminal_state_constraints) Compute per-sequence state probabilities with boundary constraints. |
| virtual bool | isSequenceModel() const Whether this model natively handles temporal sequences. |
Detailed Description
class MLCore::DBSCANOperation;DBSCAN clustering wrapping mlpack::DBSCAN.
Density-Based Spatial Clustering of Applications with Noise. Discovers clusters of arbitrary shape based on local density. Points in low-density regions are labeled as noise (SIZE_MAX).
Unlike K-Means, DBSCAN does not require specifying the number of clusters in advance — the algorithm discovers them from the data. However, it also does not produce a fitted model that can directly predict on new data.
After fitting, this implementation stores the cluster centroids and the epsilon radius. New data can be assigned to clusters via nearest-centroid lookup, with points farther than epsilon from all centroids marked as noise.
Usage
DBSCANOperation dbscan;
DBSCANParameters params;
params.epsilon = 1.0;
params.min_points = 5;
dbscan.fit(features, ¶ms);
dbscan.assignClusters(new_features, assignments);
// assignments may contain SIZE_MAX for noise pointsPublic Functions Documentation
function DBSCANOperation
DBSCANOperation()function ~DBSCANOperation
~DBSCANOperation() overridefunction DBSCANOperation
DBSCANOperation(
DBSCANOperation const &
) =deletefunction operator=
DBSCANOperation & operator=(
DBSCANOperation const &
) =deletefunction DBSCANOperation
DBSCANOperation(
DBSCANOperation &&
)function operator=
DBSCANOperation & operator=(
DBSCANOperation &&
)function getName
virtual std::string getName() const overrideUnique human-readable name for this model (e.g., “Random Forest”).
Reimplements: MLCore::MLModelOperation::getName
Used as the key in MLModelRegistry and displayed in the UI.
function getTaskType
virtual MLTaskType getTaskType() const overrideThe ML task type this operation supports.
Reimplements: MLCore::MLModelOperation::getTaskType
Enables the registry to filter models by task (classification vs clustering).
function getDefaultParameters
virtual std::unique_ptr< MLModelParametersBase > getDefaultParameters() const overrideCreate a default parameter set for this model.
Reimplements: MLCore::MLModelOperation::getDefaultParameters
Returns a new instance with algorithm-specific defaults. The caller owns the returned pointer.
function fit
virtual bool fit(
arma::mat const & features,
MLModelParametersBase const * params
) overrideFit the model to unlabeled data (unsupervised).
Parameters:
- features Feature matrix (features × observations)
- params Algorithm-specific parameters (K, epsilon, etc.)
Return: true if fitting succeeded
Precondition:
- features must not be empty (enforcement: runtime_check)
- features must not contain NaN or Inf values (enforcement: none) [IMPORTANT]
- Features are expected to be z-score normalized for distance-based clustering algorithms (K-Means, DBSCAN, GMM). (enforcement: none) [IMPORTANT]
Reimplements: MLCore::MLModelOperation::fit
After successful fitting, [isTrained()](/api_generated/Classes/classMLCore_1_1DBSCANOperation.md#function-istrained) returns true (the model is ready for [assignClusters()](/api_generated/Classes/classMLCore_1_1DBSCANOperation.md#function-assignclusters)), and [numClasses()](/api_generated/Classes/classMLCore_1_1DBSCANOperation.md#function-numclasses) returns the number of clusters found/requested.
The default implementation returns false (supervised models).
function assignClusters
virtual bool assignClusters(
arma::mat const & features,
arma::Row< std::size_t > & assignments
) overrideAssign cluster labels to observations.
Parameters:
- features Feature matrix (features × observations)
- assignments [out] Cluster assignment row vector (1 × observations). Each element is a cluster index in [0, K).
Return: true if assignment succeeded
Precondition:
- isTrained() must be true (enforcement: runtime_check)
- features.n_rows must equal numFeatures() (enforcement: none) [IMPORTANT]
- features must not contain NaN or Inf values (enforcement: none) [IMPORTANT]
- Features must be z-score normalized using the SAME parameters (mean/std) that were used for the training data passed to fit(). Use FeatureConverter::applyZscoreNormalization() with stored parameters. (enforcement: none) [IMPORTANT]
Reimplements: MLCore::MLModelOperation::assignClusters
The default implementation returns false (supervised models).
function save
virtual bool save(
std::ostream & out
) const overrideSave the trained model to a stream.
Parameters:
- out Output stream (binary or text, model-dependent)
Return: true if save succeeded
Reimplements: MLCore::MLModelOperation::save
The default implementation returns false (no persistence support).
function load
virtual bool load(
std::istream & in
) overrideLoad a previously saved model from a stream.
Parameters:
- in Input stream
Return: true if load succeeded
Reimplements: MLCore::MLModelOperation::load
After successful loading, [isTrained()](/api_generated/Classes/classMLCore_1_1DBSCANOperation.md#function-istrained) should return true. The default implementation returns false (no persistence support).
function isTrained
virtual bool isTrained() const overrideWhether the model has been trained (supervised) or fit (unsupervised).
Reimplements: MLCore::MLModelOperation::isTrained
Returns true after a successful [train()](/api_generated/Classes/classMLCore_1_1MLModelOperation.md#function-train) or [fit()](/api_generated/Classes/classMLCore_1_1DBSCANOperation.md#function-fit) call, or after a successful [load()](/api_generated/Classes/classMLCore_1_1DBSCANOperation.md#function-load).
function numClasses
virtual std::size_t numClasses() const overrideNumber of classes (supervised) or clusters (unsupervised).
Reimplements: MLCore::MLModelOperation::numClasses
Returns 0 if the model has not been trained/fit. For binary classification, returns 2.
function numFeatures
virtual std::size_t numFeatures() const overrideNumber of features the model was trained on.
Reimplements: MLCore::MLModelOperation::numFeatures
Returns 0 if the model has not been trained/fit. Used for validating that prediction data has the correct dimensionality.
function centroids
arma::mat const & centroids() constGet the fitted cluster centroids.
Return: Centroid matrix (features × num_clusters), or empty if not fitted. Each column is one centroid. Does not include noise.
function numNoisePoints
std::size_t numNoisePoints() constGet the number of noise points from the last fit.
Return: Number of points labeled as noise (SIZE_MAX), or 0 if not fitted.
function fittedEpsilon
double fittedEpsilon() constGet the epsilon used during fitting.
Used as the distance threshold for assigning new points to clusters.
Updated on 2026-11-13 at 20:25:42 +0000