MLCore Library
Overview
MLCore is a static C++ library (src/MLCore/) that provides machine learning algorithms operating directly on WhiskerToolbox core data types. It has zero Qt dependency and is fully testable in isolation.
The library provides:
- Supervised classification: Random Forest, Naive Bayes, Logistic Regression
- Unsupervised clustering: K-Means, DBSCAN, Gaussian Mixture Model
- Dimensionality reduction: PCA (with MLDimReductionOperation base class)
- End-to-end pipelines that compose validation, conversion, training/fitting, prediction, metrics, and output writing into single entry points
- Feature validation and conversion from
TensorDatato armadillo matrices - Label assembly from multiple sources (intervals, entity groups, data-entity groups)
- Prediction output following the putative group pattern
Architecture
MLCore (static, no Qt)
├── features/ # TensorData validation, conversion, label assembly
├── metrics/ # Binary & multi-class classification metrics
├── preprocessing/ # Class balancing (subsample / oversample)
├── models/ # Abstract interface + concrete implementations
│ ├── supervised/ # Random Forest, Naive Bayes, Logistic Regression
│ └── unsupervised/ # K-Means, DBSCAN, Gaussian Mixture
├── output/ # PredictionWriter — putative group pattern output
├── entity_utils/ # Bulk TimeEntity registration & conversion
└── pipelines/ # ClassificationPipeline, ClusteringPipeline
Dependency Graph
MLCore
├── DataManager # Data storage & retrieval
│ ├── TensorData # Feature matrices
│ ├── AnalogTimeSeries # Probability output
│ └── DigitalTimeSeries# Interval output
├── Entity # EntityRegistry & EntityGroupManager
│ ├── EntityRegistry
│ └── EntityGroupManager
├── MLPack (header-only) # ML algorithms
└── Armadillo # Linear algebra backend
Key Design Decisions
TensorData as Feature Matrix
Feature assembly is not part of MLCore. Users build feature tensors using the TensorDesigner/TensorColumnBuilders infrastructure. MLCore validates, converts (float→double, NaN handling, z-score normalization), and consumes the result via FeatureConverter.
Pimpl Pattern for Model Isolation
All model operations (Random Forest, K-Means, etc.) use the pimpl idiom to isolate mlpack headers from consumers. This keeps compile times reasonable and prevents mlpack’s transitive includes from leaking.
Putative Group Output Pattern
Predictions never overwrite user labels. Output goes to groups prefixed with the configured prefix (e.g., "Predicted:Contact", "Cluster:0"). This follows the pattern established by LineKalmanGrouping elsewhere in the project.
Three Label Modes
Labels can come from:
- DigitalIntervalSeries — binary labeling (inside=positive, outside=negative)
- TimeEntity groups — multi-class from entity group membership at each frame
- Data-entity groups — multi-class from data object group membership
See Label Assembly for details.
Contents
- Model Interface & Registry —
MLModelOperation,MLModelRegistry, task types, parameters - Feature Processing — validation, conversion, label assembly
- Pipelines —
ClassificationPipelineandClusteringPipeline - Prediction Regions — bounding span, output filtering, constrained Viterbi
- Label Assembly — three labeling modes in detail
- Output & Entity Utils —
PredictionWriter,TimeEntityUtils
Built-in Models
| Model | Task Type | Key Parameters | Notes |
|---|---|---|---|
| Random Forest | MultiClassClassification | num_trees, minimum_leaf_size, maximum_depth |
Probability output via vote fraction |
| Naive Bayes | MultiClassClassification | epsilon (variance smoothing) |
Fast, works well with independent features |
| Logistic Regression | BinaryClassification | lambda (L2), max_iterations |
Well-calibrated probabilities via sigmoid |
| K-Means | Clustering | k, max_iterations, seed |
Centroid-based assignment for new data |
| DBSCAN | Clustering | epsilon, min_points |
Noise points labeled SIZE_MAX |
| Gaussian Mixture | Clustering | k, max_iterations, seed |
Soft assignments via clusterProbabilities() |
Test Coverage
295+ test cases across 20 test files in tests/MLCore/. Key test areas:
| Area | Files | Coverage |
|---|---|---|
| Model operations | 6 model test files | Training, prediction, probabilities, save/load, multi-class |
| Pipelines | ClassificationPipeline.test.cpp, ClusteringPipeline.test.cpp |
End-to-end with all models, error handling, balancing, prediction regions |
| Features | FeatureValidator.test.cpp, FeatureConverter.test.cpp |
RowDescriptor compatibility, NaN dropping, z-score |
| Labels | LabelAssembler.test.cpp |
All three labeling modes |
| Metrics | ClassificationMetrics.test.cpp |
Binary/multi-class metrics, formatting |
| Preprocessing | ClassBalancing.test.cpp |
Subsample/oversample, deterministic seeding |
| Output | PredictionWriter.test.cpp |
Interval output, probability series, putative groups |
| Entity utils | TimeEntityUtils.test.cpp |
Bulk registration, interval ↔︎ entity round-trip |