BIRCH<T>
Models & Types · AiDotNet.Clustering.Hierarchical
BIRCH (Balanced Iterative Reducing and Clustering using Hierarchies) clustering.
Inheritance: ClusteringBase<T> → BIRCH<T>
For Beginners
BIRCH creates a compressed summary of your data.
The process:
- Build a tree where each node summarizes nearby points
- The tree automatically adjusts to fit memory constraints
- Use the tree for fast approximate clustering
CF (Clustering Feature) = (N, LS, SS) where:
- N = count of points
- LS = sum of all point coordinates
- SS = sum of squared coordinates
From these, you can compute:
- Centroid = LS / N
- Radius = sqrt((SS/N) - (LS/N)²)
How It Works
BIRCH is designed for very large datasets. It builds a CF (Clustering Feature) tree that summarizes the data, then optionally applies a global clustering algorithm to the leaf entries.
Each node in the CF-tree stores:
- N: Number of points
- LS: Linear Sum (vector sum of points)
- SS: Squared Sum (sum of squared norms)
Example
using AiDotNet;
using AiDotNet.Data.Loaders;
using AiDotNet.Clustering.Hierarchical;
using AiDotNet.Tensors.LinearAlgebra;
var data = new Matrix<double>(6, 2);
double[][] rows = { new[] { 1.0, 1.0 }, new[] { 1.2, 0.9 }, new[] { 1.1, 1.1 },
new[] { 8.0, 8.0 }, new[] { 8.2, 7.9 }, new[] { 7.9, 8.1 } };
for (int i = 0; i < 6; i++) { data[i, 0] = rows[i][0]; data[i, 1] = rows[i][1]; }
var result = await new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(new BIRCH<double>())
.ConfigureDataLoader(DataLoaders.FromMatrix(data))
.BuildAsync();
var labels = result.Predict(data);
Console.WriteLine($"BIRCH: clustered {labels.Length} points.");
Constructors
| Constructor | Summary |
|---|---|
BIRCH(BIRCHOptions<T> options) |
Initializes a new BIRCH instance. |
Properties
| Property | Summary |
|---|---|
IReadOnlyList<CFEntry<T>> LeafEntries { get; } |
Gets the leaf entries from the CF-tree. |
Methods
| Method | Summary |
|---|---|
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) |
|
ModelOptions GetOptions() |
|
Vector<T> FitPredict(Matrix<T> x) |
|
Vector<T> Predict(Matrix<T> x) |
|
void Train(Matrix<T> x, Vector<T> y) |