hyp
Hyperbolic geometry primitives for representation learning in non-Euclidean spaces. Implements the Poincare ball and Lorentz (hyperboloid) models for embedding hierarchical data.
Dual-licensed under MIT or Apache-2.0.
Backend choices
This crate is split into:
hyp::core: backend-agnostic implementations that operate on slices (&[T]) and returnVec<T>. This is the “math substrate” layer.hyp’sndarrayAPI: kept behind thendarrayfeature (enabled by default) for a convenient concrete backend.
use PoincareBall;
use array;
let ball = new; // curvature c=1
let x = array!;
let y = array!;
// Hyperbolic distance
let dist = ball.distance;
// Mobius addition (hyperbolic translation)
let sum = ball.mobius_add;
Operations
| Operation | Poincare | Lorentz |
|---|---|---|
| Distance | distance() |
distance() |
| Addition | mobius_add() |
- |
| Exp map | exp_map_zero() |
exp_map() |
| Log map | log_map_zero() |
log_map() |
| Project | project() |
project() |
Examples
cargo run --example graph_diagnostics: build small graphs, compute all-pairs shortest-path distances, then measure:- δ-hyperbolicity (4-point, exact (O(n^4)) for small (n))
- ultrametric max violation
- defaults to
testdata/karate_club.edgelist - set
HYP_DATASET=lesmisorHYP_DATASET=florentinefor other bundled graphs - set
HYP_EDGELIST=/path/to/edges.txtto run on your own graph
Why Hyperbolic?
Hyperbolic space has exponentially growing volume with radius, matching how trees have exponentially growing nodes with depth. A 10-dim hyperbolic space embeds trees that would need thousands of Euclidean dimensions.
Curvature
c = 1.0— Standard hyperbolic spacec > 1.0— Stronger curvature (distances grow faster)c → 0— Approaches Euclidean
References (high-signal starting points)
- Nickel & Kiela (2017): Poincaré Embeddings for Learning Hierarchical Representations.
- Ganea, Bécigneul, Hofmann (2018): Hyperbolic Neural Networks (Poincaré + Lorentz tools).
- Gromov (1987): Hyperbolic groups (δ-hyperbolicity; four-point characterizations).