OPTICS<T>
Models & Types · AiDotNet.Clustering.Density
OPTICS (Ordering Points To Identify the Clustering Structure) implementation.
Inheritance: ClusteringBase<T> → OPTICS<T>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
OPTICS creates a “profile” of your data’s cluster structure.
Imagine walking through a landscape:
- In dense areas (clusters), reachability is low
- At cluster boundaries, reachability spikes up
- This creates a “reachability plot” showing cluster structure
Benefits:
- No need to choose epsilon beforehand
- Can find clusters at multiple scales
- Better for clusters with varying densities
How It Works
OPTICS is a density-based clustering algorithm that creates an ordering of points based on their density-reachability. Unlike DBSCAN, it doesn’t require a fixed epsilon and can reveal hierarchical clustering structure.
Key concepts:
- Core distance: Minimum radius to include MinSamples points
- Reachability distance: max(core distance, distance to point)
- Cluster ordering: Sequence of points with reachability distances
Example
using AiDotNet;
using AiDotNet.Data.Loaders;
using AiDotNet.Clustering.Density;
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 OPTICS<double>())
.ConfigureDataLoader(DataLoaders.FromMatrix(data))
.BuildAsync();
var labels = result.Predict(data);
Console.WriteLine($"OPTICS: clustered {labels.Length} points.");
Constructors
| Constructor | Summary |
|---|---|
OPTICS(OPTICSOptions<T> options) |
Initializes a new OPTICS instance. |
Properties
| Property | Summary |
|---|---|
Vector<T> CoreDistances { get; } |
Gets the core distances for each point. |
Vector<T> ReachabilityDistances { get; } |
Gets the reachability distances in ordering. |
int[] Ordering { get; } |
Gets the cluster ordering. |
Methods
| Method | Summary |
|---|---|
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) |
|
ModelOptions GetOptions() |
|
ValueTuple<int, T>[] GetReachabilityPlot() |
Gets the reachability plot data. |
Vector<T> ExtractClustersAtEpsilon(double epsilon) |
Extracts clusters at a different epsilon value. |
Vector<T> FitPredict(Matrix<T> x) |
|
Vector<T> Predict(Matrix<T> x) |
|
void Train(Matrix<T> x, Vector<T> y) |
Fields
| Field | Summary |
|---|---|
int NoiseLabel |
Noise label for points not in any cluster. |