Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
sheaf
Partition, reconcile, predict. Clustering, community detection, and hierarchical conformal prediction in Rust.
Problem
Given a set of points or a graph, you want to find groups: k-means for embeddings, Leiden for networks, hierarchical clustering for dendrograms. When predictions have hierarchical structure (e.g., forecasts at country/region/city levels), they should be coherent -- the parts should sum to the whole. Conformal prediction can provide calibrated intervals that respect this structure.
This library provides the algorithms. It is domain-agnostic; the stable contract is in CONTRACT.md.
Examples
Embeddings to communities. Build a kNN graph from 2D points and detect clusters via Leiden:
Hierarchical conformal prediction. Given a tree of predictions, reconcile them so they are structurally coherent, then produce calibrated prediction intervals:
Used by flowmatch (behind --features sheaf-evals) to evaluate whether generated samples preserve the cluster structure of real data -- for example, whether generated earthquake locations form the same geographic clusters as the USGS catalog.
What it provides
- Clustering: k-means, DBSCAN, hierarchical clustering.
- Community detection: kNN graph construction (feature-gated), Leiden/Louvain/label propagation.
- Hierarchy + conformal: hierarchical reconciliation, split conformal prediction with coherence guarantees.
- Metrics: clustering evaluation helpers (used by
flowmatchsheaf-eval examples).
Custom distance metrics
K-means and DBSCAN accept a pluggable distance metric via with_metric. Built-in metrics
re-exported from clump: Euclidean, SquaredEuclidean, CosineDistance, InnerProductDistance.
Implement DistanceMetric for your own.
use ;
let km = with_metric
.with_seed
.with_seeding_alpha; // oversampling factor for k-means++
let result = km.fit?;
use ;
// epsilon is compared against cosine distance (range [0, 2])
let db = with_metric;
let labels = db.fit;
Usage
[]
= "0.1.1"
use ;
// Build hierarchy, get summing matrix
let h_tree = from_raptor;
let s = h_tree.summing_matrix;
// Calibrate on held-out data
let mut cp = new;
cp.calibrate?; // 90% coverage
// Coherent prediction intervals
let = cp.predict_intervals?;
References
- Principato et al. (2024). "Conformal Prediction for Hierarchical Data."
- Qiu & Li (2015). "IT-Dendrogram: A new representation for hierarchical clustering."
- Sarthi et al. (2024). "RAPTOR: Recursive Abstractive Processing for Tree-Organized Retrieval."
License
MIT OR Apache-2.0