Manifolds API¶
This page documents the core manifold operations in Hyperbolix. Each manifold is a class that provides geometric operations and automatic dtype casting.
Overview¶
Hyperbolix provides seven base manifold classes plus a composition class:
- Euclidean: Flat Euclidean space (baseline)
- Poincaré Ball: Conformal model of hyperbolic space
- Hyperboloid: Lorentz/Minkowski model of hyperbolic space
- Proper Velocity: Unconstrained \(\mathbb{R}^n\) model from special relativity (Chen et al. 2026)
- κ-Stereographic: Signed-curvature model unifying hyperbolic, Euclidean, and spherical geometry in one manifold (Bachmann et al. 2020)
- Klein: Beltrami–Klein ball model — straight-chord geodesics and Einstein gyrovector operations (Mao et al. 2024; Zhang et al. 2026)
- HalfSpace: Poincaré upper half-space model — the height is the last coordinate, and the gyrovector operations are Möbius operations carried over from the ball by the Cayley transform
- Product Manifold: Heterogeneous-curvature product spaces \(M_1 \times M_2 \times \dots \times M_n\) (Gu et al. 2019)
All manifolds share a common interface defined by the Manifold protocol and support:
- Automatic dtype casting: Pass
dtype=jnp.float64for higher precision (needsjax_enable_x64) - vmap-native methods: Methods operate on single points; use
jax.vmapfor batching - JIT compatibility: All methods are JIT-compilable
- Learnable curvature: Use the
LearnableCurvaturemodule to add trainable curvature to any model (positivesoftplus/logor signedidentityreparameterization, clamped by default to[init_c/10, init_c·10], or[-10, 10]for identity)
Manifold Protocol¶
The Curvature type
Manifold methods take the curvature as a positional c: Curvature argument
(hyperbolix.manifolds.Curvature). It is the union
ScalarCurvature | Sequence[ScalarCurvature], where ScalarCurvature = float |
jax.Array: every single manifold (Poincare, Hyperboloid, ProperVelocity,
Klein, HalfSpace, Stereographic, Euclidean) takes a scalar c, while ProductManifold takes a sequence
of per-factor scalars. Passing a traced jax.Array (e.g. the value returned by a
LearnableCurvature call) makes the curvature differentiable.
hyperbolix.manifolds.protocol.Manifold ¶
Bases: Protocol
Structural protocol for manifold classes.
All concrete manifold classes (Poincare, Hyperboloid,
ProperVelocity, Klein, HalfSpace, Euclidean,
Stereographic, ProductManifold) satisfy this protocol without
modification.
c is typed ScalarCurvature -- this is the scalar-curvature
interface, which is what every single manifold accepts and what the
arithmetic inside them requires. ProductManifold declares the wider
Curvature union (scalar or per-factor sequence) and therefore still
satisfies the protocol: a parameter may always be wider than the one it
implements. Code that means to pass a per-factor sequence should annotate
the manifold as ProductManifold, not as Manifold.
The method signatures use the minimal common interface so that manifold-specific optional parameters do not break compatibility. Two such parameters are nevertheless uniform across every implementation, and are part of the protocol:
dist/dist_0take a trailingversion_idx: int. Manifolds with a single distance implementation accept and ignore it (documented on each), so a generic caller can always forward one.is_in_manifold/is_in_tangent_spacetake a trailingatol: float | None = None, resolved through :func:~hyperbolix.manifolds._base.default_atolwhenNone. No implementation floors, clamps, or silently drops an explicit value; unconstrained manifolds (Euclidean, ProperVelocity) document that a finiteness test has no tolerance to apply.
The two curvature types are exported from hyperbolix.manifolds:
hyperbolix.manifolds.protocol.ScalarCurvature
module-attribute
¶
hyperbolix.manifolds.protocol.Curvature
module-attribute
¶
Euclidean¶
Flat Euclidean space (identity operations).
hyperbolix.manifolds.euclidean.Euclidean ¶
Bases: ManifoldBase
Euclidean manifold with automatic dtype casting.
Provides all manifold operations with automatic casting of array inputs to the specified dtype. Curvature is always fixed at 0.0.
Args: dtype: Target JAX dtype for computations (default: jnp.float32)
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds.euclidean import Euclidean >>> >>> manifold = Euclidean(dtype=jnp.float64) >>> x = jnp.array([1.0, 2.0]) >>> y = jnp.array([3.0, 4.0]) >>> d = manifold.dist(x, y)
Source code in hyperbolix/manifolds/euclidean.py
proj ¶
addition ¶
scalar_mul ¶
scalar_mul(
r: float | Float[Array, ""],
x: Float[Array, dim],
c: ScalarCurvature = 0.0,
) -> Float[Array, dim]
Scalar multiplication.
Source code in hyperbolix/manifolds/euclidean.py
dist ¶
dist(
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature = 0.0,
version_idx: int = VERSION_DEFAULT,
) -> Float[Array, ""]
Compute distance (version_idx accepted and ignored — see the module docstring).
Source code in hyperbolix/manifolds/euclidean.py
dist_0 ¶
dist_0(
x: Float[Array, dim],
c: ScalarCurvature = 0.0,
version_idx: int = VERSION_DEFAULT,
) -> Float[Array, ""]
Distance from origin (version_idx accepted and ignored).
Source code in hyperbolix/manifolds/euclidean.py
expmap ¶
expmap_0 ¶
retraction ¶
logmap ¶
logmap_0 ¶
ptransp ¶
ptransp(
v: Float[Array, dim],
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature = 0.0,
) -> Float[Array, dim]
Parallel transport.
Source code in hyperbolix/manifolds/euclidean.py
ptransp_0 ¶
ptransp_0(
v: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature = 0.0,
) -> Float[Array, dim]
Parallel transport from origin.
tangent_inner ¶
tangent_inner(
u: Float[Array, dim],
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature = 0.0,
) -> Float[Array, ""]
Tangent inner product.
Source code in hyperbolix/manifolds/euclidean.py
tangent_norm ¶
egrad2rgrad ¶
egrad2rgrad(
grad: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature = 0.0,
) -> Float[Array, dim]
Euclidean to Riemannian gradient.
tangent_proj ¶
tangent_proj(
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature = 0.0,
) -> Float[Array, dim]
Project onto tangent space.
is_in_manifold ¶
is_in_manifold(
x: Float[Array, dim],
c: ScalarCurvature = 0.0,
atol: float | None = None,
) -> Array
Check that all entries are finite (Euclidean space has no other constraint).
Source code in hyperbolix/manifolds/euclidean.py
is_in_tangent_space ¶
is_in_tangent_space(
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature = 0.0,
atol: float | None = None,
) -> Array
Check that all entries are finite (T_x R^n = R^n has no other constraint).
Source code in hyperbolix/manifolds/euclidean.py
Poincaré Ball¶
The Poincaré ball model with Möbius operations.
Distance Versions
The Poincaré dist method has a version_idx parameter selecting between 3 formulations:
VERSION_MOBIUS_DIRECT(0): direct Möbius distance formula (default)VERSION_MOBIUS(1): Möbius via additionVERSION_METRIC_TENSOR(2): Direct metric tensor integration
Constants are available as poincare.VERSION_MOBIUS_DIRECT etc., or from
hyperbolix.manifolds.poincare.
Slots 0 and 2 compute the same asinh distance, accurate to the ball chart's ceiling; slot 1
saturates there:
Measured values: Which Version to Use?.
Apollonian weak metric
apollonian_dist(x, y, c) is the non-symmetric Apollonian weak metric \(\delta\)
(Papadopoulos & Troyanov, Weak metrics on Euclidean domains, Thm 2) — a weak metric,
not a geodesic distance:
It satisfies \(\delta(x,x)=0\), \(\delta\ge 0\) and the triangle inequality, but
\(\delta(x,y) \neq \delta(y,x)\) in general. Its symmetrization recovers the geodesic distance:
\(\delta(x,y) + \delta(y,x) = \sqrt{c}\cdot\) dist(x, y, c).
Warning
The antisymmetric part of \(\delta\) is an exact coboundary (a difference of a per-point
potential), so it carries no circulation and is useless as an asymmetric quasimetric energy.
For that, use the busemann coordinate below with an external quasimetric combinator.
Busemann function (Chen et al. 2026)
busemann(x, v, c) is the closed-form point-to-horosphere coordinate \(B^v(x)\) for a unit
ideal direction \(v\in\mathbb{S}^{n-1}\) — the horospherical analog of the point-to-hyperplane
compute_mlr/compute_mlr_pp. v must be unit-norm (not normalized internally). It is an
intrinsic quantity, so Poincare.busemann and Hyperboloid.busemann agree under
poincare_to_hyperboloid, and \(B^v(\text{origin})=0\). Backs the *Busemann MLR/FC layers.
hyperbolix.manifolds.poincare.Poincare ¶
Bases: ManifoldBase
Poincaré ball manifold with automatic dtype casting.
Provides all manifold operations with automatic casting of array inputs to the specified dtype. This eliminates the need for manual casting and provides better numerical stability control.
Args: dtype: Target JAX dtype for computations (default: jnp.float32) c: Curvature value (default: 1.0). Must be positive.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds.poincare import Poincare, VERSION_MOBIUS_DIRECT >>> >>> # Create manifold with float64 for better precision >>> manifold = Poincare(dtype=jnp.float64) >>> >>> # Static curvature >>> manifold = Poincare(c=0.1) >>> c = manifold.c # returns 0.1
Source code in hyperbolix/manifolds/_base.py
proj ¶
proj_batch ¶
Project batched points onto the ball (handles arbitrary leading dimensions).
Batched sibling of :meth:proj, matching Hyperboloid.proj_batch. Equivalent to
jax.vmap(proj, in_axes=(0, None)) on a 2D input, without materializing the vmap.
Source code in hyperbolix/manifolds/poincare.py
gyration ¶
gyration(
x: Float[Array, dim],
y: Float[Array, dim],
z: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Compute gyration gyr[x,y]z to restore commutativity.
Source code in hyperbolix/manifolds/poincare.py
addition ¶
Möbius gyrovector addition x ⊕ y.
scalar_mul ¶
scalar_mul(
r: float | Float[Array, ""],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Scalar multiplication r ⊗ x on Poincaré ball.
Source code in hyperbolix/manifolds/poincare.py
dist ¶
dist(
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
version_idx: int = VERSION_MOBIUS_DIRECT,
) -> Float[Array, ""]
Compute geodesic distance between Poincaré ball points.
Source code in hyperbolix/manifolds/poincare.py
dist_0 ¶
dist_0(
x: Float[Array, dim],
c: ScalarCurvature,
version_idx: int = VERSION_MOBIUS_DIRECT,
) -> Float[Array, ""]
Compute geodesic distance from Poincaré ball origin.
Source code in hyperbolix/manifolds/poincare.py
apollonian_dist ¶
apollonian_dist(
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, ""]
Apollonian weak metric δ(x, y) — non-symmetric; symmetrizes to √c·dist(x, y).
.. warning::
Although δ is non-symmetric, its antisymmetric part is an exact coboundary
(δ(x, y) - δ(y, x) is a difference of a per-point potential), so it carries
no circulation and is useless as a quasimetric energy. Do not reach for this
expecting genuine asymmetry — use a :meth:busemann coordinate fed to an external
quasimetric combinator (IQE/MRN) instead.
Source code in hyperbolix/manifolds/poincare.py
expmap ¶
Exponential map: map tangent vector v at point x to manifold.
Source code in hyperbolix/manifolds/poincare.py
expmap_0 ¶
Exponential map from origin: map tangent vector v at origin to manifold.
retraction ¶
Retraction: first-order approximation of exponential map.
Source code in hyperbolix/manifolds/poincare.py
logmap ¶
Logarithmic map: map point y to tangent space at point x.
logmap_0 ¶
Logarithmic map from origin: map point y to tangent space at origin.
ptransp ¶
ptransp(
v: Float[Array, dim],
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Parallel transport tangent vector v from point x to point y.
Source code in hyperbolix/manifolds/poincare.py
ptransp_0 ¶
Parallel transport tangent vector v from origin to point y.
Source code in hyperbolix/manifolds/poincare.py
tangent_inner ¶
tangent_inner(
u: Float[Array, dim],
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, ""]
Compute inner product of tangent vectors u and v at point x.
Source code in hyperbolix/manifolds/poincare.py
tangent_norm ¶
Compute norm of tangent vector v at point x.
egrad2rgrad ¶
egrad2rgrad(
grad: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Convert Euclidean gradient to Riemannian gradient.
Source code in hyperbolix/manifolds/poincare.py
tangent_proj ¶
tangent_proj(
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Project vector v onto tangent space at point x.
is_in_manifold ¶
Check if point x lies in Poincaré ball (atol default: :func:default_atol).
Source code in hyperbolix/manifolds/poincare.py
is_in_tangent_space ¶
is_in_tangent_space(
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
atol: float | None = None,
) -> Array
Check that v has finite entries (T_x B = R^d, so there is no other constraint).
Source code in hyperbolix/manifolds/poincare.py
conformal_factor ¶
Numerically stable conformal factor lambda(x) = 2 / (1 - c||x||^2).
Batch-compatible version that handles arbitrary leading dimensions.
Source code in hyperbolix/manifolds/poincare.py
embed_spatial_0 ¶
Identity embedding (the ball has no time coordinate). Kept for API parity.
compute_mlr_pp ¶
compute_mlr_pp(
x: Float[Array, "batch in_dim"],
z: Float[Array, "out_dim in_dim"],
r: Float[Array, "out_dim 1"],
c: ScalarCurvature,
min_enorm: float = 1e-15,
) -> Float[Array, "batch out_dim"]
Compute HNN++ multinomial linear regression on the Poincare ball.
Source code in hyperbolix/manifolds/poincare.py
beta_concat ¶
Beta-concatenation of M equal-dimensional Poincaré ball points.
busemann ¶
Closed-form Poincaré Busemann function B^v(x) = (1/√c)·log(‖v - √c·x‖²/(1 - c‖x‖²)).
Point-to-horosphere coordinate (Chen et al. 2026, Eq. 3). v must be a unit
direction — it is not normalized internally. Single point (d,) → scalar; use
:func:jax.vmap for batching and over a direction set. B^v(origin) = 0, and it
matches :meth:Hyperboloid.busemann under the Poincaré↔Hyperboloid isometry.
See Also
For an asymmetric quasimetric energy, compose this Busemann coordinate with an
external Euclidean quasimetric (e.g. IQE/MRN). Do not reach for
:meth:apollonian_dist expecting asymmetry — it is a coboundary (symmetrizes to
√c·dist) and cannot deliver circulation.
Source code in hyperbolix/manifolds/poincare.py
κ-Stereographic¶
A single constant-curvature manifold spanning hyperbolic, Euclidean, and spherical geometry via a signed curvature c (Bachmann et al. 2020). It generalizes the Poincaré ball across zero curvature using curvature-generalized ("\(\kappa\)-") trigonometric functions (\(\tan_\kappa\), \(\tan_\kappa^{-1}\)), enabling a network to learn the sign of curvature from data.
Signed-curvature convention (sectional curvature \(= -c\))
Unlike the other manifolds (which require \(c > 0\)), Stereographic takes a signed \(c\):
c |
sectional curvature | geometry |
|---|---|---|
| \(> 0\) | \(< 0\) | hyperbolic — the Poincare(c) geometry (see below) |
| \(= 0\) | \(0\) | Euclidean (factor-2 limit; see below) |
| \(< 0\) | \(> 0\) | spherical (stereographic projection of the sphere) |
Internally the paper's \(\kappa = -c\). This is sign-flipped from the paper/geoopt \(\kappa\) (their \(\kappa > 0\) = spherical), chosen so c matches every other hyperbolix manifold and so Stereographic(c) matches Poincare(c) for \(c > 0\). Most ops return Poincare's bits; dist, logmap, expmap, expmap_0, logmap_0 and scalar_mul agree only to rounding (see κ-Stereographic numerics).
The Euclidean limit carries a factor of 2
The conformal factor is \(\lambda^\kappa_x = 2/(1 - c\lVert x\rVert^2)\), so \(\lambda^\kappa_0 = 2\) and the metric at \(c = 0\) is \(4\cdot I\), not \(I\). As \(c \to 0\): addition/expmap/logmap reduce to the bare Euclidean \(x{+}y\) / \(x{+}v\) / \(y{-}x\), but dist \(\to 2\lVert x-y\rVert\) and tangent_norm \(\to 2\lVert v\rVert\) (paper Thm. 3). This matches Poincaré's own dist_0 \(\to 2\lVert x\rVert\), and therefore does not equal the separate Euclidean manifold's dist (bare metric \(I\)). Use Euclidean for un-scaled flat geometry; use Stereographic at \(c=0\) only as the continuous limit of the curved family.
Curvature derivatives at zero
The shared Möbius denominator evaluates separate signed factorizations on the
\(c>0\) and \(c\le0\) sides. For nonzero operands they match the literal
polynomial value and curvature derivative at \(c=0\); an exactly zero operand
retains only the bounded residual from the existing MIN_NORM radial floor.
Scope
Provides the complete core Riemannian manifold — the Manifold protocol plus conformal_factor, gyration, geodesic, geodesic_unit, and antipode. The \(\kappa\)-GCN neural-network layers and building blocks (mobius_matvec, weighted gyromidpoint, dist2plane, sproj/inv_sproj) are not yet included. Signed learnable curvature — spanning hyperbolic/Euclidean/spherical — is available via LearnableCurvature(parameterization="identity") (with a symmetric default clamp around zero); the softplus/log parameterizations remain positive-only. Double precision (dtype=jnp.float64) is strongly recommended, per Bachmann et al.
hyperbolix.manifolds.stereographic.Stereographic ¶
Bases: ManifoldBase
κ-Stereographic manifold (Bachmann et al. 2020) with automatic dtype casting.
A single constant-curvature manifold spanning hyperbolic, Euclidean, and spherical geometry via a
signed curvature c (sectional curvature = -c): c > 0 hyperbolic (the geometry of
:class:~hyperbolix.manifolds.Poincare; some ops agree with it only to rounding), c = 0 Euclidean
(with the gyrovector factor-2 metric — see the module docstring), c < 0 spherical. See the module
docstring for the full convention table, which ops match Poincare bit for bit, the Euclidean-limit
factor-2 gotcha, and precision notes.
Args:
dtype: Target JAX dtype for computations (default: jnp.float32; float64 recommended).
c: Default (signed) curvature stored on the instance (default: 1.0, i.e. hyperbolic). The
geometry methods take c explicitly per call, so this is metadata only.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import Stereographic >>> m = Stereographic(dtype=jnp.float64) >>> x, y = jnp.array([0.1, 0.2]), jnp.array([0.3, 0.4]) >>> m.dist(x, y, c=1.0) # hyperbolic >>> m.dist(x, y, c=-1.0) # spherical
Source code in hyperbolix/manifolds/stereographic.py
proj ¶
Project point onto the manifold (identity for c ≤ 0).
conformal_factor ¶
Conformal factor λ^κ_x = 2/(1 - c‖x‖²), batch-compatible over arbitrary leading dims.
Source code in hyperbolix/manifolds/stereographic.py
gyration ¶
gyration(
x: Float[Array, dim],
y: Float[Array, dim],
z: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Gyration gyr[x, y]z.
Source code in hyperbolix/manifolds/stereographic.py
addition ¶
κ-Möbius gyrovector addition x ⊕_κ y (paper Eq. 2).
Source code in hyperbolix/manifolds/stereographic.py
scalar_mul ¶
scalar_mul(
r: float | Float[Array, ""],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
κ-scalar multiplication r ⊗_κ x (paper Eq. 3).
Source code in hyperbolix/manifolds/stereographic.py
dist ¶
dist(
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
version_idx: int = VERSION_DEFAULT,
) -> Float[Array, ""]
Geodesic distance d_κ(x, y) (paper Eq. 4). Note → 2‖x - y‖ as c → 0.
version_idx is accepted and ignored — there is a single κ-stereographic distance.
It exists so manifold-generic callers that always forward one (e.g.
hyperbolix.utils.helpers.compute_pairwise_distances) work here too.
Source code in hyperbolix/manifolds/stereographic.py
dist_0 ¶
dist_0(
x: Float[Array, dim],
c: ScalarCurvature,
version_idx: int = VERSION_DEFAULT,
) -> Float[Array, ""]
Geodesic distance to the origin d_κ(0, x) (version_idx accepted and ignored).
Note → 2‖x‖ as c → 0.
Source code in hyperbolix/manifolds/stereographic.py
expmap ¶
Exponential map exp^κ_x(v) (paper Eq. 6).
expmap_0 ¶
retraction ¶
First-order retraction proj(x + v).
logmap ¶
Logarithmic map log^κ_x(y) (paper Eq. 7).
logmap_0 ¶
ptransp ¶
ptransp(
v: Float[Array, dim],
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Parallel transport v from x to y.
Source code in hyperbolix/manifolds/stereographic.py
ptransp_0 ¶
Parallel transport v from the origin to y.
tangent_inner ¶
tangent_inner(
u: Float[Array, dim],
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, ""]
Riemannian inner product ⟨u, v⟩_x.
Source code in hyperbolix/manifolds/stereographic.py
tangent_norm ¶
egrad2rgrad ¶
egrad2rgrad(
grad: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Euclidean → Riemannian gradient.
tangent_proj ¶
tangent_proj(
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Project v onto the tangent space at x (identity).
Source code in hyperbolix/manifolds/stereographic.py
is_in_manifold ¶
Check whether x lies on the manifold (atol default: :func:default_atol).
Source code in hyperbolix/manifolds/stereographic.py
is_in_tangent_space ¶
is_in_tangent_space(
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
atol: float | None = None,
) -> Array
Check that v has finite entries (the tangent space is all of R^d).
Source code in hyperbolix/manifolds/stereographic.py
geodesic ¶
geodesic(
t: Float[Array, ""],
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Point at time t on the geodesic through x and y (paper Eq. 5).
Source code in hyperbolix/manifolds/stereographic.py
geodesic_unit ¶
geodesic_unit(
t: Float[Array, ""],
x: Float[Array, dim],
u: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Point at time t on the unit-speed geodesic from x in direction u.
Source code in hyperbolix/manifolds/stereographic.py
antipode ¶
Antipode of x (diametrically-opposite point for c < 0; -x otherwise).
Hyperboloid¶
The hyperboloid (Lorentz) model with Minkowski geometry.
Distance Versions
The Hyperboloid dist method has a version_idx parameter selecting between 2 formulations:
VERSION_DEFAULT(0): cancellation-free hyperbolic-haversine distance (default; see the measured range and remaining input-representation limits in the numerical-stability guide)VERSION_SMOOTHENED(1): same evaluation, with a strictly-positive floor at coincidence
The same two slots select an arm of dist_0, which is a separate implementation:
VERSION_DEFAULT(0):arcsinh(√c·‖x_s‖)/√c, read off the spatial part (default, with no domain clamp)VERSION_SMOOTHENED(1): the same with‖x_s‖floored in quadrature, giving a floor ofarcsinh(20·eps)/√c(≈2.4e-6/√c float32, ≈4.4e-15/√c float64)
A version_idx outside {0, 1} raises ValueError.
Constants are available as hyperboloid.VERSION_DEFAULT etc., or from
hyperbolix.manifolds.hyperboloid. See the numerical-stability guide for when to use each, the
cancellation failure mode VERSION_DEFAULT fixes, and the origin-chart rewrite behind the dist_0 arms.
Lorentz Operations
The Hyperboloid class includes specialized operations for convolutional layers:
lorentz_boost: Lorentz boost transformationhcat: Lorentz direct concatenation for convolutionslog_radius_concat: log-radius–preserving concatenation (digamma-scaledhcat; Shi et al. 2026, Sec. 4.3)
Origin derivatives
gyro_difference and ptransp use Cartesian formulas when either endpoint's
scaled spatial radius is at most 1e-1, and retain the stable polar frame
otherwise. logmap uses the regular Cartesian expression at an exact origin
endpoint and the stable polar frame otherwise. Ordinary autodiff preserves derivatives with respect to
an origin endpoint. busemann uses a projected-coordinate
branch whose value and constrained first derivative agree at its branch surface.
See Origin derivatives and the Cartesian chart.
hyperbolix.manifolds.hyperboloid.Hyperboloid ¶
Bases: ManifoldBase
Hyperboloid manifold with automatic dtype casting.
Provides all manifold operations with automatic casting of array inputs to the specified dtype. This eliminates the need for manual casting and provides better numerical stability control.
Args: dtype: Target JAX dtype for computations (default: jnp.float32) c: Curvature value (default: 1.0). Must be positive.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds.hyperboloid import Hyperboloid, VERSION_DEFAULT >>> >>> # Create manifold with float64 for better precision >>> manifold = Hyperboloid(dtype=jnp.float64) >>> >>> # Custom curvature >>> manifold = Hyperboloid(c=0.5) >>> c = manifold.c # returns 0.5
Source code in hyperbolix/manifolds/_base.py
create_origin ¶
Create hyperboloid origin [1/√c, 0, ..., 0].
minkowski_inner ¶
Compute Minkowski inner product ⟨x, y⟩_L = -x₀y₀ + ⟨x_rest, y_rest⟩.
This is the literal form -x₀·y₀ + ⟨x_s, y_s⟩, whose two terms are each
O(cosh²(a)/c) and cancel, so the absolute rounding error is about eps·cosh²(a)/c
(float32: 0.26 at a = 8, reaching 1 at a ≈ 8.7 for c = 1). Nothing inside the library calls it; do not
use it to recover ⟨x, x⟩_L = -1/c, to check manifold membership, or to form distances —
use dist/sqdist/tangent_inner/is_in_manifold, which are cancellation-free
(see docs/user-guide/numerical-stability.md).
Source code in hyperbolix/manifolds/hyperboloid.py
proj ¶
proj_batch ¶
proj_batch(
x: Float[Array, "... dim_plus_1"], c: ScalarCurvature
) -> Float[Array, "... dim_plus_1"]
Project batched points onto hyperboloid (handles arbitrary leading dimensions).
Source code in hyperbolix/manifolds/hyperboloid.py
addition ¶
addition(
x: Float[Array, dim_plus_1],
y: Float[Array, dim_plus_1],
c: ScalarCurvature,
) -> Float[Array, dim_plus_1]
Lorentz gyrovector addition x ⊕ y = Exp_x(PT_{0→x}(Log_0(y))).
The intrinsic Lorentz addition of Chen et al. (2025b) / Shi et al. (2026, Eq. 1).
Forms a gyrocommutative gyrogroup with identity = origin and inverse
⊖x = (-1) ⊙ x = [x₀, -x_s]; matches Poincaré Möbius addition under the
stereographic isometry. scalar_mul provides the companion gyro scaling (Eq. 2).
Source code in hyperbolix/manifolds/hyperboloid.py
gyro_difference ¶
gyro_difference(
x: Float[Array, dim_plus_1],
y: Float[Array, dim_plus_1],
c: ScalarCurvature,
) -> Float[Array, dim_plus_1]
Gyro-difference (⊖x) ⊕ y, evaluated without the ambient cancellation.
Mathematically identical to addition(scalar_mul(-1, x), y); use this whenever the
result is expected much closer to the origin than the operands (centering a batch,
differences, distances between far points). See :func:_gyro_difference.
Source code in hyperbolix/manifolds/hyperboloid.py
scalar_mul ¶
scalar_mul(
r: float | Float[Array, ""],
x: Float[Array, dim_plus_1],
c: ScalarCurvature,
) -> Float[Array, dim_plus_1]
Scalar multiplication on hyperboloid.
Source code in hyperbolix/manifolds/hyperboloid.py
dist ¶
dist(
x: Float[Array, dim_plus_1],
y: Float[Array, dim_plus_1],
c: ScalarCurvature,
version_idx: int = VERSION_DEFAULT,
) -> Float[Array, ""]
Compute geodesic distance between hyperboloid points.
Source code in hyperbolix/manifolds/hyperboloid.py
dist_0 ¶
dist_0(
x: Float[Array, dim_plus_1],
c: ScalarCurvature,
version_idx: int = VERSION_DEFAULT,
) -> Float[Array, ""]
Geodesic distance from the origin, arcsinh(√c·‖x_s‖)/√c.
Read off the spatial part; x₀ is ignored, so an off-sheet input gets the radius of
its :meth:proj projection (the same convention proj itself follows). A raw
jax.grad of this therefore has its support on x_s rather than x₀; the two
differ by a multiple of the constraint normal, so the Riemannian gradient after
:meth:egrad2rgrad / :meth:tangent_proj is identical and optimizers are unaffected.
Source code in hyperbolix/manifolds/hyperboloid.py
sqdist ¶
sqdist(
x: Float[Array, dim_plus_1],
y: Float[Array, dim_plus_1],
c: ScalarCurvature,
) -> Float[Array, ""]
Squared Lorentzian distance d_L²(x, y) = -2/c - 2⟨x,y⟩_L (Law et al. 2019).
That is the mathematical definition; it is now evaluated cancellation-free as
d_L² = 4·sinh²(√c·d(x,y)/2)/c off the :func:_polar_frame decomposition instead of the
literal -2/c - 2⟨x,y⟩_L subtraction, which loses precision the same way the old
acosh form did (see :func:_sqdist's docstring for the full derivation).
A fast, acosh-free dissimilarity that is monotone in the geodesic :meth:dist
(d_L² = (2/c)(cosh(√c·d) - 1)) but is not the squared geodesic distance and not
a true metric. Prefer it where a smooth monotone distance proxy suffices (contrastive /
commitment / attention scores); use :meth:dist when the geodesic length is required.
Source code in hyperbolix/manifolds/hyperboloid.py
expmap ¶
expmap(
v: Float[Array, dim_plus_1],
x: Float[Array, dim_plus_1],
c: ScalarCurvature,
) -> Float[Array, dim_plus_1]
Exponential map: map tangent vector v at point x to manifold.
Source code in hyperbolix/manifolds/hyperboloid.py
expmap_0 ¶
retraction ¶
retraction(
v: Float[Array, dim_plus_1],
x: Float[Array, dim_plus_1],
c: ScalarCurvature,
) -> Float[Array, dim_plus_1]
Retraction: first-order approximation of exponential map.
Source code in hyperbolix/manifolds/hyperboloid.py
logmap ¶
logmap(
y: Float[Array, dim_plus_1],
x: Float[Array, dim_plus_1],
c: ScalarCurvature,
) -> Float[Array, dim_plus_1]
Logarithmic map: map point y to tangent space at point x.
Source code in hyperbolix/manifolds/hyperboloid.py
logmap_0 ¶
Logarithmic map from the origin, [0, arcsinh(√c‖y_s‖)/(√c‖y_s‖) · y_s].
Like :meth:dist_0 it reads the radius off the spatial part and ignores y₀, so an
off-sheet input is treated as its :meth:proj projection. ‖log_0(y)‖ = dist_0(y) holds
by construction at every radius.
Source code in hyperbolix/manifolds/hyperboloid.py
ptransp ¶
ptransp(
v: Float[Array, dim_plus_1],
x: Float[Array, dim_plus_1],
y: Float[Array, dim_plus_1],
c: ScalarCurvature,
) -> Float[Array, dim_plus_1]
Parallel transport tangent vector v from point x to point y.
Source code in hyperbolix/manifolds/hyperboloid.py
ptransp_0 ¶
ptransp_0(
v: Float[Array, dim_plus_1],
y: Float[Array, dim_plus_1],
c: ScalarCurvature,
) -> Float[Array, dim_plus_1]
Parallel transport tangent vector v from origin to point y.
Source code in hyperbolix/manifolds/hyperboloid.py
tangent_inner ¶
tangent_inner(
u: Float[Array, dim_plus_1],
v: Float[Array, dim_plus_1],
x: Float[Array, dim_plus_1],
c: ScalarCurvature,
) -> Float[Array, ""]
Compute inner product of tangent vectors u and v at point x.
Source code in hyperbolix/manifolds/hyperboloid.py
tangent_norm ¶
tangent_norm(
v: Float[Array, dim_plus_1],
x: Float[Array, dim_plus_1],
c: ScalarCurvature,
) -> Float[Array, ""]
Compute norm of tangent vector v at point x.
Source code in hyperbolix/manifolds/hyperboloid.py
egrad2rgrad ¶
egrad2rgrad(
grad: Float[Array, dim_plus_1],
x: Float[Array, dim_plus_1],
c: ScalarCurvature,
) -> Float[Array, dim_plus_1]
Convert Euclidean gradient to Riemannian gradient.
Source code in hyperbolix/manifolds/hyperboloid.py
tangent_proj ¶
tangent_proj(
v: Float[Array, dim_plus_1],
x: Float[Array, dim_plus_1],
c: ScalarCurvature,
) -> Float[Array, dim_plus_1]
Project vector v onto tangent space at point x.
Source code in hyperbolix/manifolds/hyperboloid.py
is_in_manifold ¶
is_in_manifold(
x: Float[Array, dim_plus_1],
c: ScalarCurvature,
atol: float | None = None,
) -> Array
Check if point x lies on hyperboloid (atol default: :func:default_atol).
Source code in hyperbolix/manifolds/hyperboloid.py
is_in_tangent_space ¶
is_in_tangent_space(
v: Float[Array, dim_plus_1],
x: Float[Array, dim_plus_1],
c: ScalarCurvature,
atol: float | None = None,
) -> Array
Check if vector v lies in tangent space at point x (atol default: :func:default_atol).
Source code in hyperbolix/manifolds/hyperboloid.py
hcat ¶
Hyperbolic concatenation of N points into one point.
log_radius_concat ¶
log_radius_concat(
points: Float[Array, "N n"], c: ScalarCurvature = 1.0
) -> Float[Array, dN_plus_1]
Log-radius-preserving concatenation of N points (Shi et al. 2026, Sec. 4.3).
Like :meth:hcat, but shrinks each block's spatial part by the digamma factor
s = exp(½·(ψ(d/2) - ψ(N·d/2))) ≈ 1/√N so the expected log spatial radius is
invariant to the number of concatenated blocks. Reduces to :meth:hcat when
N == 1.
Source code in hyperbolix/manifolds/hyperboloid.py
embed_spatial_0 ¶
Embed spatial vector as tangent vector at origin.
compute_mlr ¶
compute_mlr(
x: Float[Array, "batch in_dim"],
z: Float[Array, "out_dim in_dim_minus_1"],
r: Float[Array, "out_dim 1"],
c: ScalarCurvature,
min_enorm: float = 1e-15,
) -> Float[Array, "batch out_dim"]
Compute multinomial linear regression on hyperboloid.
Source code in hyperbolix/manifolds/hyperboloid.py
busemann ¶
busemann(
x: Float[Array, dim_plus_1],
v: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, ""]
Closed-form Lorentz Busemann function B^v(x) = (1/√c)·log(√c·(x_t - ⟨x_s, v⟩)).
Point-to-horosphere coordinate (Chen et al. 2026, Eq. 4). v must be a unit
spatial direction (dim d) — it is not normalized internally. Single point
(d+1,) → scalar; use :func:jax.vmap for batching and over a direction set.
B^v(origin) = 0.
See Also
For an asymmetric quasimetric energy, compose this Busemann coordinate with an
external Euclidean quasimetric (e.g. IQE/MRN). Do not reach for
:meth:Poincare.apollonian_dist expecting asymmetry — it is a coboundary
(symmetrizes to √c·dist) and cannot deliver circulation.
Source code in hyperbolix/manifolds/hyperboloid.py
lorentz_boost ¶
lorentz_boost(
mu: Float[Array, dim_plus_1], c: ScalarCurvature
) -> Float[Array, "dim_plus_1 dim_plus_1"]
Lorentz boost matrix B with B @ mu = origin (sends mu to the origin).
Symmetric, proper, orthochronous Lorentz transformation. Boost a batch of
row-vector points with x_NA @ B.T followed by :meth:proj_batch; the inverse
boost is the boost of [mu₀, -mu_s]. Used to Fréchet-mean-center data for
HoroPCA (Chami et al. 2021). See :func:_lorentz_boost.
Source code in hyperbolix/manifolds/hyperboloid.py
Proper Velocity¶
The Proper Velocity (PV) model — an unconstrained \(\mathbb{R}^n\) representation of hyperbolic geometry rooted in special relativity's proper velocity (Ungar 2022, Ch. 10). PV is algebraically a gyrovector space isomorphic to the Poincaré ball via \(\pi(x) = (\beta_x / (1 + \beta_x)) \cdot x\), and carries a Riemannian metric making that isomorphism an isometry.
Why Proper Velocity?
Unlike the bounded Poincaré ball (points must stay in the open unit ball) and the constrained hyperboloid (points must satisfy \(\langle x, x \rangle_L = -1/c\)), PV points live in all of \(\mathbb{R}^n\) with no constraint. This gives:
- No projection step after updates — the manifold is \(\mathbb{R}^n\)
- No boundary and no constraint to drift from; accuracy equals the hyperboloid's, since the pairwise ops go through it
- Drop-in with Euclidean optimizers — the retraction reduces to \(x + v\)
The metric \(g_x(u,v) = \langle u, v\rangle - c\beta_x^2\langle x,u\rangle\langle x,v\rangle\) still gives sectional curvature \(-c\); only the coordinates change.
Convention
The paper uses curvature \(K < 0\) with \(\beta_x = 1/\sqrt{1 - K\|x\|^2}\). Hyperbolix keeps the \(c > 0\) convention (sectional curvature \(-c\)), substituting \(K = -c\), so \(\beta_x = 1/\sqrt{1 + c\|x\|^2}\).
Exact hyperboloid bridges
dist, logmap, expmap, gyro addition, gyro_difference, and ptransp
evaluate through the direct isometry
\(x\mapsto(\sqrt{1/c+\lVert x\rVert^2},x)\). For tangent operations,
\(v\in T_x\) lifts to \((\langle x,v\rangle/X_0,v)\). The PV result is the
spatial part of the hyperboloid result; no Poincaré chart conversion is used.
gyro_difference, ptransp, and logmap inherit the hyperboloid's exact-origin
Cartesian branch and its origin derivatives.
ProperVelocityGyroBatchNorm centers with gyro_difference. See
ProperVelocity operation bridges.
hyperbolix.manifolds.proper_velocity.ProperVelocity ¶
Bases: ManifoldBase
Proper Velocity (PV) manifold with automatic dtype casting.
PV is an unconstrained representation of hyperbolic geometry rooted in special relativity's proper velocity (Ungar 2022, Ch. 10). Points live in R^n without any manifold constraint, which gives better numerical stability for large radii than the bounded Poincaré ball or the constrained hyperboloid (Chen et al. 2026, Tables 1-3).
Args:
dtype: Target JAX dtype for computations (default: jnp.float32).
c: Curvature value (default: 1.0). Must be positive.
Examples: >>> import jax >>> import jax.numpy as jnp >>> from hyperbolix.manifolds.proper_velocity import ProperVelocity >>> >>> manifold = ProperVelocity(dtype=jnp.float64) >>> x = jnp.array([0.1, 0.2], dtype=jnp.float32) >>> y = jnp.array([0.3, 0.4], dtype=jnp.float32) >>> with jax.enable_x64(True): # float64 needs x64 enabled ... d = manifold.dist(x, y, c=1.0) >>> d.dtype dtype('float64')
Source code in hyperbolix/manifolds/_base.py
create_origin ¶
beta ¶
proj ¶
Projection onto PV: the identity (PV is R^n; non-finite entries pass through).
addition ¶
gyro_difference ¶
gyro_difference(
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
PV gyro-difference (⊖x) ⊕ y, evaluated without the ambient cancellation.
Mathematically identical to addition(scalar_mul(-1, x), y); use this whenever the
result is expected much closer to the origin than the operands (centering a batch,
differences of two far points). The exact hyperboloid lift uses a Cartesian
inverse boost when either endpoint's scaled spatial radius is at most 1e-1
and the stable polar frame otherwise. See :func:_gyro_difference.
Source code in hyperbolix/manifolds/proper_velocity.py
scalar_mul ¶
scalar_mul(
r: float | Float[Array, ""],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
PV scalar multiplication r ⊗_U x.
Source code in hyperbolix/manifolds/proper_velocity.py
dist ¶
dist(
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
version_idx: int = VERSION_DEFAULT,
) -> Float[Array, ""]
Geodesic distance between PV points.
Source code in hyperbolix/manifolds/proper_velocity.py
dist_0 ¶
dist_0(
x: Float[Array, dim],
c: ScalarCurvature,
version_idx: int = VERSION_DEFAULT,
) -> Float[Array, ""]
Geodesic distance from the PV origin.
expmap ¶
expmap_0 ¶
logmap ¶
Logarithmic map at x through the exact hyperboloid lift.
A regular Cartesian expression is used when either endpoint is exactly the origin; otherwise the stable polar frame is used. Ordinary autodiff preserves the base-point derivative at the origin.
Source code in hyperbolix/manifolds/proper_velocity.py
logmap_0 ¶
retraction ¶
Euclidean retraction (exact for PV).
ptransp ¶
ptransp(
v: Float[Array, dim],
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Parallel transport v from T_x PV to T_y PV through the exact lift.
The lifted hyperboloid transport uses its Cartesian closed form when either endpoint's scaled spatial radius is at most 1e-1 and the stable polar frame otherwise.
Source code in hyperbolix/manifolds/proper_velocity.py
ptransp_0 ¶
Parallel transport v from T_0 PV to T_y PV.
tangent_inner ¶
tangent_inner(
u: Float[Array, dim],
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, ""]
Riemannian inner product ⟨u, v⟩_x.
Source code in hyperbolix/manifolds/proper_velocity.py
tangent_norm ¶
Riemannian norm ||v||_x.
tangent_proj ¶
tangent_proj(
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Tangent-space projection (identity for PV).
egrad2rgrad ¶
egrad2rgrad(
grad: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Convert Euclidean gradient to Riemannian gradient.
Source code in hyperbolix/manifolds/proper_velocity.py
is_in_manifold ¶
Check that all entries are finite (PV has no constraint, so atol is unused).
Source code in hyperbolix/manifolds/proper_velocity.py
is_in_tangent_space ¶
is_in_tangent_space(
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
atol: float | None = None,
) -> Array
Check that v has finite entries (T_x PV = R^n, so atol is unused).
Source code in hyperbolix/manifolds/proper_velocity.py
embed_spatial_0 ¶
Identity embedding (no time coordinate). Kept for API parity.
compute_mlr ¶
compute_mlr(
x: Float[Array, "batch in_dim"],
z: Float[Array, "out_dim in_dim"],
r: Float[Array, "out_dim 1"],
c: ScalarCurvature,
min_enorm: float = 1e-15,
) -> Float[Array, "batch out_dim"]
PV multinomial logistic regression (paper Thm 5.2).
Source code in hyperbolix/manifolds/proper_velocity.py
Klein¶
The Beltrami–Klein model (the Klein model) uses the same open ball \(\lVert x\rVert < 1/\sqrt{c}\) as the Poincaré ball, with sectional curvature \(-c\), but its geodesics are the straight chords of the ball. The metric is not conformal:
The gyrovector structure is Ungar's Einstein gyrovector space (Ungar 2009): addition is Einstein addition \(\oplus_E\) and scalar_mul is Einstein scalar multiplication \(\otimes_E\). Klein conforms to the scalar-c Manifold protocol.
Relation to the Poincaré ball and the hyperboloid
A Klein point at geodesic distance \(d_0\) from the origin has \(\sqrt{c}\,\lVert x\rVert = \tanh(\sqrt{c}\,d_0)\), where a Poincaré point has \(\tanh(\sqrt{c}\,d_0/2)\). The isometries in isometry_mappings are the Einstein half and the Möbius double:
klein_to_poincare(k)\(= k/(1 + \sqrt{g_k})\), which is \(\tfrac12 \otimes_E k\)poincare_to_klein(p)\(= 2p/(1 + c\lVert p\rVert^2)\), which is \(2 \otimes_M p\)klein_to_hyperboloid(k)\(= \big(1/(\sqrt{c}\sqrt{g_k}),\ k/\sqrt{g_k}\big)\),hyperboloid_to_klein(x)\(= x_s/(\sqrt{c}\,x_0)\)klein_to_pv(k)\(= k/\sqrt{g_k}\),pv_to_klein(x)\(= x/\sqrt{1 + c\lVert x\rVert^2}\)
Under the first pair, Einstein addition corresponds to Möbius addition. Einstein and Möbius scalar multiplication have the same formula, and so do the two models' expmap_0; Klein reuses Poincaré's code for both.
Distance: one formulation, cancellation-free
dist has a single implementation; version_idx is accepted and ignored, as for ProperVelocity. With \(w = y - x\),
whose numerator is a sum of non-negative terms. It never forms \(1 - c\langle x, y\rangle\) and needs no acosh/atanh near 1. logmap and ptransp are built from the same quantity. The derivation and measured errors are in the numerical-stability guide.
Einstein extras
Beyond the protocol, Klein provides:
gyro_difference(x, y, c): \((\ominus x) \oplus_E y\), evaluated without the \(1 - c\langle x, y\rangle\) cancellationlorentz_factor(x, c): \(\gamma_x = 1/\sqrt{g_x}\), which is the hyperboloid's \(\sqrt{c}\,X_0\)einstein_midpoint(x_ND, weights_N, c): \(\sum_i w_i \gamma_i x_i / \sum_i w_i \gamma_i\) (weights_N=Nonefor uniform weights), equal to the normalized weighted Lorentz centroid mapped to the Klein ball
Half the Poincaré ball's radius range
proj uses the Poincaré ball's eps**0.75 boundary margin, but a Klein point sits at \(\tanh(a)\) rather than \(\tanh(a/2)\) (\(a = \sqrt{c}\,d_0\), the scaled radius), so the projection ceiling at \(c = 1\) is \(a = \operatorname{atanh}(1 - \varepsilon^{0.75})\) = 6.32 in float32 and 13.86 in float64, half of Poincaré's 12.65 / 27.7. The maps into Klein (poincare_to_klein, hyperboloid_to_klein, pv_to_klein) do not project; call proj after mapping far points in. See the chart ceiling and floor.
hyperbolix.manifolds.klein.Klein ¶
Bases: ManifoldBase
Beltrami-Klein ball manifold (curvature -c, radius 1/√c) with automatic dtype casting.
Points are Euclidean ball points c‖x‖² < 1 as for :class:~hyperbolix.manifolds.Poincare,
but geodesics are straight chords and the metric
g_x(u, v) = (u·v)/g_x + c(x·u)(x·v)/g_x² (g_x = 1 - c‖x‖²) is not conformal. The
gyrovector structure is Einstein addition; scalar_mul and expmap_0 coincide with
Poincaré's formulas.
Precision: the chart shares Poincaré's eps**0.75 boundary margin, but a Klein point at
scaled radius a = √c·d has √c‖x‖ = tanh(a) where a Poincaré point has tanh(a/2),
so the projection ceiling is half Poincaré's: a ≈ 6.3 in float32 and ≈ 13.9 in
float64 (at c = 1). Inside it the pairwise ops (dist, logmap, ptransp,
gyro_difference) are cancellation-free; what remains is the storage floor of the gap,
1 - c‖x‖² known to relative eps·cosh²(a).
Args: dtype: Target JAX dtype for computations (default: jnp.float32) c: Curvature value (default: 1.0). Must be positive.
Examples: >>> import jax >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import Klein >>> >>> manifold = Klein(dtype=jnp.float64) >>> x = jnp.array([0.1, 0.2]) >>> y = jnp.array([0.3, 0.4]) >>> d = manifold.dist(x, y, c=1.0) >>> dists = jax.vmap(manifold.dist, in_axes=(0, 0, None))(jnp.stack([x, y]), jnp.stack([y, x]), 1.0)
References: Zhang et al. "Klein Hyperbolic Metric Learning." ICML 2026. Mao et al. "Klein Model for Hyperbolic Neural Networks." arXiv:2410.16813 (2024). Ungar. "A Gyrovector Space Approach to Hyperbolic Geometry." 2009.
Source code in hyperbolix/manifolds/_base.py
proj ¶
Project a point onto the Klein ball by clipping its norm (same clamp as Poincaré).
proj_batch ¶
Project batched points onto the ball (arbitrary leading dimensions).
addition ¶
Einstein gyrovector addition x ⊕_E y.
gyro_difference ¶
gyro_difference(
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Einstein gyro-difference (⊖x) ⊕_E y, evaluated without the 1 - c x·y cancellation.
Mathematically identical to addition(-x, y); use it when the result is expected much
closer to the origin than the operands (centering, differences of two close points).
Source code in hyperbolix/manifolds/klein.py
scalar_mul ¶
scalar_mul(
r: float | Float[Array, ""],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Einstein scalar multiplication r ⊗ x = tanh(r·artanh(√c‖x‖))·x/(√c‖x‖).
The same formula as Möbius scalar multiplication (Ungar 2009): both scale the origin
distance by r, and each model's radial coordinate is tanh of its own multiple of
that distance.
Source code in hyperbolix/manifolds/klein.py
dist ¶
dist(
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
version_idx: int = VERSION_DEFAULT,
) -> Float[Array, ""]
Geodesic distance arsinh(S)/√c between Klein points (single implementation).
Source code in hyperbolix/manifolds/klein.py
dist_0 ¶
dist_0(
x: Float[Array, dim],
c: ScalarCurvature,
version_idx: int = VERSION_DEFAULT,
) -> Float[Array, ""]
Geodesic distance from the origin.
expmap ¶
Exponential map: tangent vector v at x to the manifold.
expmap_0 ¶
Exponential map from the origin (the Poincaré formula; see :func:_expmap_0).
retraction ¶
logmap ¶
Logarithmic map: point y to the tangent space at x.
logmap_0 ¶
ptransp ¶
ptransp(
v: Float[Array, dim],
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Parallel transport of v from x to y.
Source code in hyperbolix/manifolds/klein.py
ptransp_0 ¶
Parallel transport of v from the origin to y.
tangent_inner ¶
tangent_inner(
u: Float[Array, dim],
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, ""]
Klein metric g_x(u, v).
Source code in hyperbolix/manifolds/klein.py
tangent_norm ¶
egrad2rgrad ¶
egrad2rgrad(
grad: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Convert a Euclidean gradient to the Riemannian gradient (inverse Klein metric).
Source code in hyperbolix/manifolds/klein.py
tangent_proj ¶
tangent_proj(
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Project v onto the tangent space at x (identity).
is_in_manifold ¶
Check c‖x‖² < 1 + atol (atol default: :func:default_atol).
is_in_tangent_space ¶
is_in_tangent_space(
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
atol: float | None = None,
) -> Array
Check that v has finite entries (T_x K = R^d, so there is no other constraint).
Source code in hyperbolix/manifolds/klein.py
lorentz_factor ¶
Einstein Lorentz factor gamma_x = 1/√(1 - c‖x‖²), scalar.
einstein_midpoint ¶
einstein_midpoint(
x_ND: Float[Array, "N dim"],
weights_N: Float[Array, N] | None,
c: ScalarCurvature,
) -> Float[Array, dim]
Weighted Einstein midpoint Σ wᵢ·gammaᵢ·xᵢ / Σ wᵢ·gammaᵢ of N points.
Args:
x_ND: Klein points, shape (N, dim)
weights_N: Non-negative weights, shape (N,); None for uniform weights
c: Curvature (positive)
Returns: Midpoint, shape (dim,) — the normalized weighted Lorentz centroid mapped to Klein.
Source code in hyperbolix/manifolds/klein.py
HalfSpace¶
The Poincaré upper half-space model stores a point as \(x = (x_s, x_n)\) with the height \(x_n > 0\) in the last coordinate. The sectional curvature is \(-c\) and the metric is conformal:
The origin is \(o = e_n/\sqrt{c}\), not 0, and every _0 method is the general method evaluated at \(o\). Geodesics are vertical lines and half-circles orthogonal to the boundary \(x_n = 0\). In chart coordinates expmap, logmap and ptransp do not depend on \(c\), because a constant factor on the metric leaves the Christoffel symbols unchanged; only the origin, distances, norms and inner products carry \(c\). The convention follows HTorch (github.com/ydtydr/HTorch, manifolds/halfspace.py). HalfSpace conforms to the scalar-c Manifold protocol.
Relation to the Poincaré ball and the hyperboloid
The Cayley transform halfspace_to_poincare maps \(o\) to the ball origin with differential \(\tfrac12 I\), the vertical axis through \(o\) onto the \(e_n\) diameter, \(x_n \to \infty\) to the north pole \(e_n/\sqrt{c}\), and \(x_n \to 0\) to the boundary sphere. The isometries in isometry_mappings, with \(g_k = 1 - c\lVert k\rVert^2\):
halfspace_to_poincare(x)\(= \big(2x_s,\ (c\lVert x\rVert^2 - 1)/\sqrt{c}\big)\big/\big(c\lVert x_s\rVert^2 + (1 + \sqrt{c}\,x_n)^2\big)\),poincare_to_halfspace(p)\(= \big(2p_s,\ (1 - c\lVert p\rVert^2)/\sqrt{c}\big)\big/\big(c\lVert p_s\rVert^2 + (\sqrt{c}\,p_n - 1)^2\big)\)halfspace_to_hyperboloid(x)\(= \big(c\lVert x\rVert^2 + 1,\ 2\sqrt{c}\,x_s,\ c\lVert x\rVert^2 - 1\big)/(2c\,x_n)\) (time coordinate first),hyperboloid_to_halfspace(X)\(= \big(X_{\mathrm{mid}},\ 1/\sqrt{c}\big)\big/\big(\sqrt{c}\,(X_0 - X_n)\big)\)halfspace_to_klein(x)\(= \big(2x_s,\ (c\lVert x\rVert^2 - 1)/\sqrt{c}\big)/(1 + c\lVert x\rVert^2)\),klein_to_halfspace(k)\(= \big(k_s,\ \sqrt{g_k}/\sqrt{c}\big)/(1 - \sqrt{c}\,k_n)\)halfspace_to_pv(x)\(= \big(2\sqrt{c}\,x_s,\ c\lVert x\rVert^2 - 1\big)/(2c\,x_n)\), the spatial part of the hyperboloid point;pv_to_halfspace(u)\(= \big(u_s,\ 1/\sqrt{c}\big)\big/\big(\sqrt{c}\,(\sqrt{1/c + \lVert u\rVert^2} - u_n)\big)\)
These are the formulas; the code rearranges the differences that cancel. For example, \(c\lVert x\rVert^2 - 1\) is evaluated as \(c\lVert x_s\rVert^2 + (\sqrt{c}\,x_n - 1)(\sqrt{c}\,x_n + 1)\), and for \(X_n \ge 0\) the gap \(X_0 - X_n\) as \((1/c + \lVert X_{\mathrm{mid}}\rVert^2)/(X_0 + X_n)\). None of the maps projects its output.
Gyrovector structure: Möbius operations through the Cayley transform
addition(x, y)\(= x \oplus y = \exp_x\!\big(P_{o\to x}(\log_o y)\big)\)gyro_difference(x, y)\(= (\ominus x) \oplus y = \exp_o\!\big(P_{x\to o}(\log_x y)\big)\), built from \(\log_x y\), so two close points give a point close to \(o\) without cancellationscalar_mul(r, x)\(= r \otimes x = \exp_o(r\,\log_o x)\)- the gyro-inverse is \(\ominus x = (-x_s,\ x_n)/(c\lVert x\rVert^2)\)
Each equals the Möbius operation of the Poincaré ball conjugated by halfspace_to_poincare. Unlike Poincare, the identity element is \(o = e_n/\sqrt{c}\), and \(\ominus x \ne -x\).
Pairwise operations: cancellation-free
dist has a single implementation; version_idx is accepted and ignored. With \(r = \big((y - x)/\sqrt{x_n}\big)/\sqrt{y_n}\), divided in sequence so that \(x_n y_n\) is never formed,
This is the same function as the textbook \(\operatorname{arcosh}\!\big(1 + \lVert y - x\rVert^2/(2x_n y_n)\big)/\sqrt{c}\), without its acosh of a number close to 1 for close pairs. logmap builds \(\theta/\sinh\theta\) from the same \(r\). expmap evaluates its denominator in a second, non-cancelling form for near-vertical upward steps. ptransp is a rational formula with no transcendental functions. The derivations and measured errors are in the numerical-stability guide.
Storage floor and the float ceilings
The error that remains is a stored point's own rounding, about \(0.4\,(\varepsilon/2)\cosh(\sqrt{c}\,\delta)/\sqrt{c}\) as a distance, where \(\delta\) is the distance to the vertical geodesic through \(o\) and \(\cosh(\sqrt{c}\,\delta) = \lVert x\rVert/x_n\). On that axis the floor does not grow with the height. Two cases return inf/NaN at a finite radius: the pairwise operations past a scaled distance \(\sqrt{c}\,d = 88.72\) in float32 (709.78 in float64), where \(\lVert r\rVert^2\) overflows, and expmap for an exactly vertical upward step longer than \(\theta = 87.34\) in float32 (708.40 in float64), where \(e^{-\theta}\) underflows. See the half-space numerics.
Projection, retraction and membership
proj floors the height at the dtype's smallest normal number, jnp.finfo(dtype).tiny, so a valid point is returned unchanged. retraction is proj((x_s + v_s, x_n·exp(v_n/x_n))): first order, exact for vertical steps, and never outside the half-space, where the plain x + v leaves it for large downward steps. is_in_manifold checks that x is finite with x_n > 0; atol is accepted and unused, as for ProperVelocity.
hyperbolix.manifolds.halfspace.HalfSpace ¶
Bases: ManifoldBase
Poincaré upper half-space manifold (curvature -c) with automatic dtype casting.
Points are x = (x_s, x_n) with height x_n > 0 in the last coordinate, metric
‖dx‖²/(c·x_n²) and origin o = e_n/√c. The gyrovector structure is Möbius addition carried
over from the Poincaré ball by the Cayley transform.
Precision: the pairwise ops (dist, logmap, ptransp, gyro_difference) are built from
w = y - x and are cancellation-free; expmap is cancellation-free for every step direction.
What remains is the storage floor, a stored point's own rounding ≈ 0.4·(eps/2)·cosh(√c·δ)/√c
as a distance, with cosh(√c·δ) = ‖x‖/x_n and δ the distance to the vertical geodesic
through o. Points on that axis are stored exactly across the dtype's normal range of heights;
the pairwise ops return inf/NaN past a scaled distance √c·d ≈ 88.7 (float32; float64 709.8),
where the squared chord overflows.
Args: dtype: Target JAX dtype for computations (default: jnp.float32) c: Curvature value (default: 1.0). Must be positive.
Examples: >>> import jax >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import HalfSpace >>> >>> manifold = HalfSpace(dtype=jnp.float64) >>> x = jnp.array([0.1, 1.0]) >>> y = jnp.array([0.3, 0.5]) >>> d = manifold.dist(x, y, c=1.0) >>> dists = jax.vmap(manifold.dist, in_axes=(0, 0, None))(jnp.stack([x, y]), jnp.stack([y, x]), 1.0)
References:
Cannon, Floyd, Kenyon, Parry. "Hyperbolic Geometry." Flavors of Geometry, MSRI Publ. 31, 1997.
Yu & De Sa. HTorch (github.com/ydtydr/HTorch), manifolds/halfspace.py.
Source code in hyperbolix/manifolds/_base.py
proj ¶
Floor the height at the dtype's smallest normal number; valid points never move.
proj_batch ¶
Project batched points (arbitrary leading dimensions); the same op as :meth:proj.
addition ¶
Gyro addition x ⊕ y = exp_x(PT_{o→x}(log_o y)) (Möbius addition via the Cayley map).
Source code in hyperbolix/manifolds/halfspace.py
gyro_difference ¶
gyro_difference(
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Gyro difference (⊖x) ⊕ y, evaluated from log_x y without cancellation.
Mathematically identical to addition(⊖x, y) with ⊖x = (-x_s, x_n)/(c‖x‖²); use it when
the result is expected much closer to the origin than the operands (centering, differences
of two close points).
Source code in hyperbolix/manifolds/halfspace.py
scalar_mul ¶
scalar_mul(
r: float | Float[Array, ""],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Gyro scalar multiplication r ⊗ x = exp_o(r·log_o x) (scales the distance to o by r).
Source code in hyperbolix/manifolds/halfspace.py
dist ¶
dist(
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
version_idx: int = VERSION_DEFAULT,
) -> Float[Array, ""]
Geodesic distance (2/√c)·arsinh(‖r‖/2) (single implementation).
Source code in hyperbolix/manifolds/halfspace.py
dist_0 ¶
dist_0(
x: Float[Array, dim],
c: ScalarCurvature,
version_idx: int = VERSION_DEFAULT,
) -> Float[Array, ""]
Geodesic distance from the origin o = e_n/√c.
Source code in hyperbolix/manifolds/halfspace.py
expmap ¶
Exponential map: tangent vector v at x to the manifold.
expmap_0 ¶
retraction ¶
Retraction proj((x_s + v_s, x_n·exp(v_n/x_n))).
logmap ¶
Logarithmic map: point y to the tangent space at x.
logmap_0 ¶
ptransp ¶
ptransp(
v: Float[Array, dim],
x: Float[Array, dim],
y: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Parallel transport of v from x to y.
Source code in hyperbolix/manifolds/halfspace.py
ptransp_0 ¶
Parallel transport of v from the origin to y.
tangent_inner ¶
tangent_inner(
u: Float[Array, dim],
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, ""]
Metric g_x(u, v) = (u·v)/(c·x_n²).
Source code in hyperbolix/manifolds/halfspace.py
tangent_norm ¶
Riemannian norm ‖v‖_x = ‖v‖/(√c·x_n).
egrad2rgrad ¶
egrad2rgrad(
grad: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Convert a Euclidean gradient to the Riemannian gradient, c·x_n²·grad.
Source code in hyperbolix/manifolds/halfspace.py
tangent_proj ¶
tangent_proj(
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
) -> Float[Array, dim]
Project v onto the tangent space at x (identity).
is_in_manifold ¶
Check that x is finite with x_n > 0 (atol accepted and unused: the constraint is exact).
Source code in hyperbolix/manifolds/halfspace.py
is_in_tangent_space ¶
is_in_tangent_space(
v: Float[Array, dim],
x: Float[Array, dim],
c: ScalarCurvature,
atol: float | None = None,
) -> Array
Check that v has finite entries (T_x H = R^n, so there is no other constraint).
Source code in hyperbolix/manifolds/halfspace.py
Product Manifold¶
Heterogeneous-curvature product space \(P = M_1 \times M_2 \times \dots \times M_n\) where each factor \(M_i\) can be any single manifold (Poincaré, Hyperboloid, Proper Velocity, Klein, HalfSpace, Stereographic, Euclidean) with its own curvature \(c_i\). Points are represented as flat concatenated arrays of shape (total_dim,).
The geodesic distance on a product Riemannian manifold is Pythagorean over component distances:
where \(x_i\), \(y_i\) are the per-factor slices of the flat points.
Per-factor c argument
Every geometry method takes a positional c that must be a sequence of length n_factors: pass product.curvatures for static curvatures, or a tuple of LearnableCurvature calls for trainable ones. isinstance(product, Manifold) is True, but Manifold is typed with a scalar c; annotate code that passes a per-factor sequence as ProductManifold. See the Manifolds User Guide — Curvature in ProductManifold for the full pattern.
hyperbolix.manifolds.product.ProductManifold ¶
Product manifold P = M1 x M2 x ... x Mn.
Each factor is specified as (manifold_instance, dim) where dim is
the point dimension (array slice width): ambient for Hyperboloid (d+1),
spatial for Poincaré/Euclidean/ProperVelocity (d).
Curvature is supplied at call time as a per-factor sequence:
product.dist(x, y, (c0, c1, ...)) # explicit tuple
product.dist(x, y, product.curvatures) # use factor-stored values
Factor instances may carry an initial curvature value (Hyperboloid(c=1.0)),
but that value is not consulted by ProductManifold's methods — it is
only useful as a static default to read off via product.curvatures.
ProductManifold satisfies the Manifold protocol with c typed as
Curvature (a union of scalar and sequence-of-scalars), so generic code
written against Manifold accepts product instances too. The product
itself has no c attribute — there is no single scalar curvature.
Args:
*factors: Tuples of (manifold_instance, dim). At least one required.
dtype: Target JAX dtype for computations (default: jnp.float32). Every factor must have
been built with this dtype; a mismatch raises ValueError.
Examples: >>> product = ProductManifold((Hyperboloid(c=1.0), 5), (Poincare(c=0.1), 3)) >>> c = product.curvatures # (1.0, 0.1) >>> x = product.origin(c) >>> parts = product.split(x) >>> d = product.dist(x, y, c)
From a signature (repeated factors):
>>> product = ProductManifold.from_signature(
... (Hyperboloid, 3, 8, 1.0), # 8 copies of 3D-ambient Hyperboloid
... (Poincare, 2, 4, 0.1), # 4 copies of 2D Poincaré
... )
Source code in hyperbolix/manifolds/product.py
curvatures
property
¶
Per-factor curvatures stored on the factor instances.
Useful as the c argument when curvature is static, e.g.
product.dist(x, y, product.curvatures). For learnable curvature,
build the tuple from LearnableCurvature calls instead.
split ¶
combine ¶
Combine per-factor components into a product point.
Source code in hyperbolix/manifolds/product.py
origin ¶
Construct the product origin point under per-factor curvatures.
Uses expmap_0(zeros, c[i]) per factor, which returns the manifold
origin for all manifold types without isinstance checks.
Source code in hyperbolix/manifolds/product.py
proj ¶
Project point onto product manifold (per-factor projection).
Source code in hyperbolix/manifolds/product.py
addition ¶
addition(
x: Float[Array, total_dim],
y: Float[Array, total_dim],
c: Curvature,
) -> Float[Array, total_dim]
Manifold addition (per-factor).
Source code in hyperbolix/manifolds/product.py
scalar_mul ¶
scalar_mul(
r: float | Float[Array, ""],
x: Float[Array, total_dim],
c: Curvature,
) -> Float[Array, total_dim]
Scalar multiplication (same scalar r applied to all factors).
Source code in hyperbolix/manifolds/product.py
expmap ¶
expmap(
v: Float[Array, total_dim],
x: Float[Array, total_dim],
c: Curvature,
) -> Float[Array, total_dim]
Exponential map (per-factor).
Source code in hyperbolix/manifolds/product.py
expmap_0 ¶
Exponential map from origin (per-factor).
Source code in hyperbolix/manifolds/product.py
logmap ¶
logmap(
y: Float[Array, total_dim],
x: Float[Array, total_dim],
c: Curvature,
) -> Float[Array, total_dim]
Logarithmic map (per-factor).
Source code in hyperbolix/manifolds/product.py
logmap_0 ¶
Logarithmic map to origin (per-factor).
Source code in hyperbolix/manifolds/product.py
retraction ¶
retraction(
v: Float[Array, total_dim],
x: Float[Array, total_dim],
c: Curvature,
) -> Float[Array, total_dim]
Retraction (per-factor).
Source code in hyperbolix/manifolds/product.py
ptransp ¶
ptransp(
v: Float[Array, total_dim],
x: Float[Array, total_dim],
y: Float[Array, total_dim],
c: Curvature,
) -> Float[Array, total_dim]
Parallel transport of v from x to y (per-factor).
Source code in hyperbolix/manifolds/product.py
ptransp_0 ¶
ptransp_0(
v: Float[Array, total_dim],
y: Float[Array, total_dim],
c: Curvature,
) -> Float[Array, total_dim]
Parallel transport from origin to y (per-factor).
Source code in hyperbolix/manifolds/product.py
tangent_inner ¶
tangent_inner(
u: Float[Array, total_dim],
v: Float[Array, total_dim],
x: Float[Array, total_dim],
c: Curvature,
) -> Float[Array, ""]
Riemannian inner product (sum of per-factor inner products).
Source code in hyperbolix/manifolds/product.py
tangent_norm ¶
tangent_norm(
v: Float[Array, total_dim],
x: Float[Array, total_dim],
c: Curvature,
) -> Float[Array, ""]
Riemannian norm (sqrt of tangent inner product with itself).
safe_sqrt, not a bare jnp.sqrt: at v = 0 the inner product is exactly 0, where
sqrt' is infinite and reverse-mode AD forms 0 * inf = NaN for the whole row.
Source code in hyperbolix/manifolds/product.py
egrad2rgrad ¶
egrad2rgrad(
grad: Float[Array, total_dim],
x: Float[Array, total_dim],
c: Curvature,
) -> Float[Array, total_dim]
Convert Euclidean gradient to Riemannian gradient (per-factor).
Source code in hyperbolix/manifolds/product.py
tangent_proj ¶
tangent_proj(
v: Float[Array, total_dim],
x: Float[Array, total_dim],
c: Curvature,
) -> Float[Array, total_dim]
Project vector onto tangent space (per-factor).
Source code in hyperbolix/manifolds/product.py
component_dist ¶
component_dist(
x: Float[Array, total_dim],
y: Float[Array, total_dim],
c: Curvature,
) -> Float[Array, n_factors]
Per-factor geodesic distances as a vector.
Source code in hyperbolix/manifolds/product.py
dist ¶
dist(
x: Float[Array, total_dim],
y: Float[Array, total_dim],
c: Curvature,
version_idx: int = VERSION_DEFAULT,
) -> Float[Array, ""]
Product distance (L2/Riemannian): d = sqrt(sum d_i^2).
version_idx is accepted and ignored: it is a per-manifold index (Poincaré's 2
means the metric-tensor form, the Hyperboloid has no such variant), so one value cannot
be forwarded to a heterogeneous product. Each factor uses its own default. The argument
exists so manifold-generic callers that always forward one (e.g.
hyperbolix.utils.helpers.compute_pairwise_distances) work with product manifolds;
call component_dist directly if you need per-factor control.
Source code in hyperbolix/manifolds/product.py
dist_0 ¶
dist_0(
x: Float[Array, total_dim],
c: Curvature,
version_idx: int = VERSION_DEFAULT,
) -> Float[Array, ""]
Distance from origin (L2/Riemannian). version_idx accepted and ignored (see dist).
Source code in hyperbolix/manifolds/product.py
dist_l1 ¶
dist_l1(
x: Float[Array, total_dim],
y: Float[Array, total_dim],
c: Curvature,
) -> Float[Array, ""]
L1 product distance: d = sum d_i.
dist_min ¶
dist_min(
x: Float[Array, total_dim],
y: Float[Array, total_dim],
c: Curvature,
) -> Float[Array, ""]
Min product distance: d = min d_i.
Warning:
This is NOT a true metric: positive-definiteness fails. Two
distinct points x != y that agree on any single factor
(x_i == y_i) yield d = 0. Use only when the
"closest-factor" interpretation is semantically intended;
for an actual distance use dist (L2) or dist_l1.
Source code in hyperbolix/manifolds/product.py
is_in_manifold ¶
Check if point is on product manifold (all factors valid).
atol is forwarded unchanged to every factor, so None lets each factor resolve
its own dtype-aware default (:func:~hyperbolix.manifolds._base.default_atol).
Source code in hyperbolix/manifolds/product.py
is_in_tangent_space ¶
is_in_tangent_space(
v: Float[Array, total_dim],
x: Float[Array, total_dim],
c: Curvature,
atol: float | None = None,
) -> Array
Check if vector is in tangent space at x (all factors valid); atol forwarded per factor.
Source code in hyperbolix/manifolds/product.py
from_signature
classmethod
¶
Create product manifold from a signature specification.
Each spec is one of:
- (ManifoldClass, dim, count) — uses c=1.0 as factor init.
- (ManifoldClass, dim, count, curvature) — sets factor init c.
The curvature here is an initial / default value stored on the
factor; it is only consulted via product.curvatures. Geometry
methods take c at call time.
Euclidean factors silently ignore the curvature field
(Euclidean has fixed c=0; see Euclidean.__init__).
Args: *specs: Signature tuples (3- or 4-tuple as described above). dtype: Target JAX dtype.
Returns: ProductManifold instance.
Examples: >>> pm = ProductManifold.from_signature( ... (Hyperboloid, 3, 8, 1.0), ... (Poincare, 2, 4, 0.1), ... (Euclidean, 8, 1), ... )
Source code in hyperbolix/manifolds/product.py
Isometry Mappings¶
Distance-preserving maps between the Poincaré ball, hyperboloid, Proper
Velocity (PV), Klein, and half-space models — all coordinate models of the same hyperbolic space.
Provides Poincaré ↔ Hyperboloid, Poincaré ↔ PV (PVNN Eq. 4), the direct
Hyperboloid ↔ PV map (PV coordinates are the space-like part of the 4-velocity),
Klein ↔ Poincaré / Hyperboloid / PV (klein_to_poincare, poincare_to_klein,
klein_to_hyperboloid, hyperboloid_to_klein, klein_to_pv, pv_to_klein; a Klein
point is an Einstein velocity, and its proper velocity is k/√g_k), and half-space ↔
Poincaré / Hyperboloid / Klein / PV (halfspace_to_poincare, poincare_to_halfspace,
halfspace_to_hyperboloid, hyperboloid_to_halfspace, halfspace_to_klein,
klein_to_halfspace, halfspace_to_pv, pv_to_halfspace; the first pair is the Cayley
transform, and halfspace_to_pv is the spatial part of halfspace_to_hyperboloid).
None of the half-space maps projects its output. poincare_to_halfspace and
klein_to_halfspace floor the ball's gap \(1 - c\lVert\cdot\rVert^2\), as the other maps out
of a ball do, so the height they return is positive. klein_to_halfspace maps every point
of the closed Klein ball, the north pole included, to a finite point;
poincare_to_halfspace returns inf/NaN at the north pole \(e_n/\sqrt{c}\), the half-space's
point at infinity, which a Poincare.proj-projected point never reaches.
hyperboloid_to_halfspace and pv_to_halfspace do not floor \(x_n\). klein_to_halfspace
is limited by the Klein chart's own rounding, relative error \(\varepsilon\cosh^2(a)\) at
scaled radius \(a\), in every spelling (see
the Klein chart's floor).
hyperbolix.manifolds.isometry_mappings ¶
Isometry mappings between hyperbolic manifold models.
This module implements distance-preserving transformations (isometries) between different models of hyperbolic geometry. All functions operate on single points and use JAX's vmap for batch operations.
Supported Models (curvature c > 0, sectional curvature -c):
- Hyperboloid model (Lorentz model): Points in R^(d+1) satisfying ⟨x,x⟩_L = -1/c
- Poincaré ball model: Points in R^d with ||y||² < 1/c
- Proper Velocity (PV) model: Unconstrained points in R^d (Chen et al. 2026)
- Beltrami-Klein model: Points in R^d with ||k||² < 1/c (geodesics are straight chords)
- Poincaré half-space model: Points in R^d with last coordinate x_n > 0 (origin e_n/√c)
Provided maps (all exact, distance-preserving, mutually consistent):
- Poincaré ↔ Hyperboloid: poincare_to_hyperboloid / hyperboloid_to_poincare
(curvature-aware stereographic projection through [-1/√c, 0, ..., 0]).
- Poincaré ↔ PV: poincare_to_pv / pv_to_poincare
(the gyro-isomorphism of PVNN Eq. 4, an isometry by their Thm 4.2).
- Hyperboloid ↔ PV: hyperboloid_to_pv / pv_to_hyperboloid
(direct map — PV coordinates are the space-like part of the 4-velocity;
the projection Π of Ferreira 2017, Sec. 2, built on the PV gyrogroup of
Ungar 2005, Def. 3.40).
- Klein ↔ Poincaré: klein_to_poincare / poincare_to_klein
(the Einstein half / Möbius double maps, k = 2 ⊗ p).
- Klein ↔ Hyperboloid: klein_to_hyperboloid / hyperboloid_to_klein
(central projection from the ambient origin onto the plane x₀ = 1/√c).
- Klein ↔ PV: klein_to_pv / pv_to_klein
(PV = Einstein velocity scaled by its Lorentz factor, x = gamma_k·k).
- Half-space ↔ Poincaré: halfspace_to_poincare / poincare_to_halfspace
(the Cayley transform, origin e_n/√c ↦ 0 with differential ½·I).
- Half-space ↔ Hyperboloid: halfspace_to_hyperboloid / hyperboloid_to_halfspace.
- Half-space ↔ Klein: halfspace_to_klein / klein_to_halfspace.
- Half-space ↔ PV: halfspace_to_pv / pv_to_halfspace.
Klein chart precision: with scaled radius a = √c·d(0, ·) a Klein point has
√c·||k|| = tanh(a) where a Poincaré point has tanh(a/2), so 1 - c·||k||²
reaches the _boundary_floor value at half the Poincaré radius — scaled radius
≈ 6.3 in float32 and ≈ 13.9 in float64 at c = 1 (Poincaré: 12.6 / 27.7). The maps
into Klein (poincare_to_klein, hyperboloid_to_klein, pv_to_klein) do not
project. A point farther out than that lands between the proj margin and the
boundary (float32, c = 1: ||k|| = 0.9999983 at a = 7 against the margin
0.99999356), and from a ≈ 10 on ||k|| rounds to exactly 1/√c (at a = 12 for all
three maps). Klein operations floor 1 - c·||k||² at half the _boundary_floor
value (_boundary_divisor_floor, below the rounding band of a capped point), so such a
point reads at its own radius up to a ≈ 6.67 and as a ≈ 6.67 beyond (float32, c = 1;
float64: 14.21). Call Klein.proj after mapping far points into Klein.
JIT Compilation & Batching
All functions work with single points and return single points. Use jax.vmap for batch operations:
>>> import jax
>>> import jax.numpy as jnp
>>> from hyperbolix.manifolds import isometry_mappings
>>>
>>> # Single point conversion
>>> x_hyp = jnp.array([1.0, 0.1, 0.2]) # Hyperboloid point
>>> y_poinc = isometry_mappings.hyperboloid_to_poincare(x_hyp, c=1.0)
>>>
>>> # Batch conversion with vmap
>>> x_batch = jnp.array([[1.0, 0.1, 0.2], [1.1, 0.15, 0.25]])
>>> convert_batch = jax.vmap(isometry_mappings.hyperboloid_to_poincare, in_axes=(0, None))
>>> y_batch = convert_batch(x_batch, 1.0)
References: Wikipedia: Hyperboloid model https://en.wikipedia.org/wiki/Hyperboloid_model#Relation_to_other_models Chen et al. "Proper Velocity Neural Networks." ICLR 2026 (PV ↔ Poincaré, Eq. 4). Ferreira. "Harmonic Analysis on the Proper Velocity Gyrogroup." Banach J. Math. Anal. 11(1), 21-49, 2017 (PV ↔ Hyperboloid projection Π, Sec. 2). Ungar. "Analytic Hyperbolic Geometry: Mathematical Foundations and Applications." World Scientific, 2005 (PV gyrogroup, Def. 3.40; the Einstein ↔ Möbius gyrovector-space isomorphism behind Klein ↔ Poincaré).
hyperboloid_to_poincare ¶
Convert hyperboloid point to Poincaré ball via stereographic projection.
Projects the hyperboloid point onto the hyperplane t = 0 by intersecting with a line through [-1/√c, 0, ..., 0]. This implements the canonical isometry between the two models (radius-1/√c Poincaré ball).
Formula: y_i = x_i / (√c·t + 1) where x = [t, x_1, ..., x_n] on hyperboloid (t = x₀ ≥ 1/√c)
Args: x: Point on hyperboloid, shape (dim+1,). Should satisfy ⟨x,x⟩_L = -1/c. c: Curvature (positive)
Returns: Point in Poincaré ball, shape (dim,). Satisfies ||y||² < 1/c.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Convert hyperboloid origin to Poincaré origin >>> x_origin = jnp.array([1.0, 0.0, 0.0]) # c=1.0 origin >>> y = isometry_mappings.hyperboloid_to_poincare(x_origin, c=1.0) >>> bool(jnp.allclose(y, jnp.zeros(2))) True
References: Wikipedia: Hyperboloid model - Relation to other models
Source code in hyperbolix/manifolds/isometry_mappings.py
poincare_to_hyperboloid ¶
Convert Poincaré ball point to hyperboloid via inverse stereographic projection.
Inverts the stereographic projection to map points from the Poincaré ball back to the hyperboloid. This implements the canonical isometry between the two models (radius-1/√c Poincaré ball).
Formula: t = (1 + c·||y||²) / ((1 - c·||y||²)·√c) x_i = 2·y_i / (1 - c·||y||²) where y = [y_1, ..., y_n] in Poincaré ball (||y||² < 1/c)
Args: y: Point in Poincaré ball, shape (dim,). Should satisfy ||y||² < 1/c. c: Curvature (positive)
Returns: Point on hyperboloid, shape (dim+1,). Satisfies ⟨x,x⟩_L = -1/c.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Convert Poincaré origin to hyperboloid origin >>> y_origin = jnp.array([0.0, 0.0]) >>> x = isometry_mappings.poincare_to_hyperboloid(y_origin, c=1.0) >>> bool(jnp.allclose(x, jnp.array([1.0, 0.0, 0.0]))) True
References: Wikipedia: Hyperboloid model - Relation to other models
Source code in hyperbolix/manifolds/isometry_mappings.py
pv_to_poincare ¶
Convert a Proper Velocity point to the Poincaré ball.
Implements the gyro-isomorphism π_{PV→P} of the PVNN paper (Chen et al. 2026, Eq. 4), proven to be a Riemannian isometry (their Thm 4.2). With hyperbolix's c > 0 convention (K = -c):
Formula: y = x / (1 + √(1 + c·||x||²))
This is the numerically stable form of y = β_x/(1 + β_x)·x with the PV
beta factor β_x = 1/√(1 + c·||x||²): dividing numerator and denominator
by β_x turns it into x / (1 + 1/β_x). The denominator is ≥ 2, so the map
never blows up — every finite PV point lands strictly inside the radius-1/√c
ball.
Args: x: Point in PV space (unconstrained R^n), shape (dim,). c: Curvature (positive).
Returns: Point in the Poincaré ball, shape (dim,). Satisfies ||y||² < 1/c.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # PV origin (0) maps to Poincaré origin (0) >>> y = isometry_mappings.pv_to_poincare(jnp.zeros(2), c=1.0) >>> bool(jnp.allclose(y, jnp.zeros(2))) True
References: Chen et al. "Proper Velocity Neural Networks." ICLR 2026, Eq. 4.
Source code in hyperbolix/manifolds/isometry_mappings.py
poincare_to_pv ¶
Convert a Poincaré ball point to Proper Velocity space.
Inverse of :func:pv_to_poincare — the map π_{P→PV} of the PVNN paper
(Chen et al. 2026, Eq. 4). With hyperbolix's c > 0 convention (K = -c):
Formula: x = 2·y / (1 - c·||y||²) = λ(y)·y
where λ(y) = 2/(1 - c·||y||²) is the Poincaré conformal factor. As y
approaches the ball boundary (||y||² → 1/c) the image grows without bound —
expected, since PV is the unconstrained R^n model. The denominator is
floored at _boundary_divisor_floor(y, c) — half the smallest value it can
take on a projected ball point, below the rounding band of a capped one (see
:func:poincare_to_hyperboloid) — to avoid division by zero at the boundary.
Args: y: Point in the Poincaré ball, shape (dim,). Should satisfy ||y||² < 1/c. c: Curvature (positive).
Returns: Point in PV space (unconstrained R^n), shape (dim,).
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Poincaré origin (0) maps to PV origin (0) >>> x = isometry_mappings.poincare_to_pv(jnp.zeros(2), c=1.0) >>> bool(jnp.allclose(x, jnp.zeros(2))) True
References: Chen et al. "Proper Velocity Neural Networks." ICLR 2026, Eq. 4.
Source code in hyperbolix/manifolds/isometry_mappings.py
pv_to_hyperboloid ¶
Convert a Proper Velocity point to the hyperboloid model.
Uses the direct relation "proper velocity is the spatial part of the (dimensionless) 4-velocity": the PV coordinates are exactly the space-like hyperboloid components, and the time component is reconstructed from the Lorentz constraint ⟨z,z⟩_L = -1/c.
Formula: z = [√(1/c + ||x||²), x_1, ..., x_n]
This is an exact isometry (it equals
poincare_to_hyperboloid(pv_to_poincare(x, c), c)) but avoids the
near-boundary 1/(1 - c·||y||²) blow-up of the composed route — it is just a
concatenation. The time component is ≥ 1/√c > 0, so the result is always a
valid, numerically stable hyperboloid point.
Args: x: Point in PV space (unconstrained R^n), shape (dim,). c: Curvature (positive).
Returns: Point on the hyperboloid, shape (dim+1,). Satisfies ⟨z,z⟩_L = -1/c, z₀ > 0.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # PV origin maps to the hyperboloid origin [1/√c, 0, ...] >>> z = isometry_mappings.pv_to_hyperboloid(jnp.zeros(2), c=1.0) >>> bool(jnp.allclose(z, jnp.array([1.0, 0.0, 0.0]))) True
References: Ferreira. "Harmonic Analysis on the Proper Velocity Gyrogroup." Banach J. Math. Anal. 11(1), 21-49, 2017 — Sec. 2, the projection Π(x, √(t²+‖x‖²)) = x between the hyperboloid of radius t = 1/√c and PV space (t → 1/√c here). Ungar. "Analytic Hyperbolic Geometry: Mathematical Foundations and Applications." World Scientific, 2005 — Def. 3.40, the PV gyrogroup.
Source code in hyperbolix/manifolds/isometry_mappings.py
hyperboloid_to_pv ¶
Convert a hyperboloid point to Proper Velocity space.
Inverse of :func:pv_to_hyperboloid: the PV coordinates are exactly the
space-like components of the hyperboloid point, so the map simply drops the
time component.
Formula: x = [z_1, ..., z_n] (drop the time component z₀)
The curvature c is unused (the relation is curvature-independent) but is
kept in the signature for API symmetry with the other mappings.
Args: x: Point on the hyperboloid, shape (dim+1,). Should satisfy ⟨x,x⟩_L = -1/c. c: Curvature (positive). Unused.
Returns: Point in PV space (unconstrained R^n), shape (dim,).
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Hyperboloid origin [1/√c, 0, ...] maps to the PV origin (0) >>> x = isometry_mappings.hyperboloid_to_pv(jnp.array([1.0, 0.0, 0.0]), c=1.0) >>> bool(jnp.allclose(x, jnp.zeros(2))) True
References: Ferreira. "Harmonic Analysis on the Proper Velocity Gyrogroup." Banach J. Math. Anal. 11(1), 21-49, 2017 — Sec. 2, the projection Π(x, √(t²+‖x‖²)) = x between the hyperboloid of radius t = 1/√c and PV space (t → 1/√c here). Ungar. "Analytic Hyperbolic Geometry: Mathematical Foundations and Applications." World Scientific, 2005 — Def. 3.40, the PV gyrogroup.
Source code in hyperbolix/manifolds/isometry_mappings.py
klein_to_poincare ¶
Convert a Beltrami-Klein point to the Poincaré ball.
The Einstein half map p = (1/2) ⊗_E k: with the Einstein Lorentz factor
gamma_k = 1/√(1 - c·||k||²),
Formula: p = gamma_k/(1 + gamma_k)·k = k / (1 + √(1 - c·||k||²))
Both models use the radius-1/√c ball (curvature -c). The denominator is in
[1, 2], so the map is well-conditioned; 1 - c·||k||² is floored at
_boundary_divisor_floor(k, c) (see :func:_klein_gap). A Klein point has
√c·||k|| = tanh(a) at scaled radius a = √c·d(0, k) where a Poincaré
point has tanh(a/2), so the Klein chart runs out of float precision at
half the Poincaré radius (a ≈ 6.3 float32, 13.9 float64 at c = 1).
Args: k: Point in the Klein ball, shape (dim,). Should satisfy ||k||² < 1/c. c: Curvature (positive).
Returns: Point in the Poincaré ball, shape (dim,). Satisfies ||p||² < 1/c.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Klein origin maps to Poincaré origin >>> p = isometry_mappings.klein_to_poincare(jnp.zeros(2), c=1.0) >>> bool(jnp.allclose(p, jnp.zeros(2))) True
References: Ungar. "Analytic Hyperbolic Geometry: Mathematical Foundations and Applications." World Scientific, 2005 — Einstein ↔ Möbius isomorphism.
Source code in hyperbolix/manifolds/isometry_mappings.py
poincare_to_klein ¶
Convert a Poincaré ball point to the Beltrami-Klein model.
Inverse of :func:klein_to_poincare: the Möbius doubling k = 2 ⊗_M p.
Formula: k = 2·p / (1 + c·||p||²)
The denominator is in [1, 2], so no floor is needed. The result is not
projected. Since √c·||k|| = tanh(a) with a = √c·d(0, p), a Poincaré point
beyond scaled radius ≈ 6.3 (float32) / 13.9 (float64) at c = 1 lands past the
Klein.proj margin, and Klein operations read it at radius ≤ 6.67 / 14.21 (see
the module docstring). Call Klein.proj on the result for such points.
Args: p: Point in the Poincaré ball, shape (dim,). Should satisfy ||p||² < 1/c. c: Curvature (positive).
Returns:
Point in the closed Klein ball, shape (dim,). In float32, ||k|| can round
to 1/√c beyond a ≈ 10; call Klein.proj before using such points.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Poincaré origin maps to Klein origin >>> k = isometry_mappings.poincare_to_klein(jnp.zeros(2), c=1.0) >>> bool(jnp.allclose(k, jnp.zeros(2))) True
References: Ungar. "Analytic Hyperbolic Geometry: Mathematical Foundations and Applications." World Scientific, 2005 — Einstein ↔ Möbius isomorphism.
Source code in hyperbolix/manifolds/isometry_mappings.py
klein_to_hyperboloid ¶
Convert a Beltrami-Klein point to the hyperboloid model.
Inverse of the central projection from the ambient origin onto the plane
x₀ = 1/√c (scaled by √c so the Klein ball has radius 1/√c).
Formula: x_s = k / √(1 - c·||k||²) = gamma_k·k x₀ = 1 / (√c·√(1 - c·||k||²)) = √(1/c + ||x_s||²)
The spatial part is :func:klein_to_pv; the time component is rebuilt from it
with safe_hypot_norm exactly as :func:pv_to_hyperboloid does, so the
result satisfies ⟨x,x⟩_L = -1/c to rounding even where 1 - c·||k||² is
floored. The two time formulas agree in exact arithmetic.
Args: k: Point in the Klein ball, shape (dim,). Should satisfy ||k||² < 1/c. c: Curvature (positive).
Returns: Point on the hyperboloid, shape (dim+1,). Satisfies ⟨x,x⟩_L = -1/c, x₀ > 0.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Klein origin maps to the hyperboloid origin [1/√c, 0, ...] >>> x = isometry_mappings.klein_to_hyperboloid(jnp.zeros(2), c=1.0) >>> bool(jnp.allclose(x, jnp.array([1.0, 0.0, 0.0]))) True
References: Wikipedia: Hyperboloid model - Relation to other models
Source code in hyperbolix/manifolds/isometry_mappings.py
hyperboloid_to_klein ¶
Convert a hyperboloid point to the Beltrami-Klein model.
Central projection from the ambient origin onto the plane x₀ = 1/√c.
Formula: k = x_s / (√c·x₀) where x = [x₀, x_s] on the hyperboloid (x₀ ≥ 1/√c)
hyperboloid_core.lorentz_scale writes the same map as φ_K(x) = x_s/x₀:
that is the unit-ball Klein coordinate √c·k. Since √c·||k|| =
||x_s||/x₀ = tanh(a) at scaled radius a = √c·d(0, x), points beyond
a ≈ 6.3 (float32) / 13.9 (float64) at c = 1 land past the Klein.proj
margin (the result is not projected), and Klein operations read them at radius
≤ 6.67 / 14.21 (see the module docstring). Call Klein.proj on the result for
such points.
Args: x: Point on the hyperboloid, shape (dim+1,). Should satisfy ⟨x,x⟩_L = -1/c. c: Curvature (positive).
Returns:
Point in the closed Klein ball, shape (dim,). In float32, ||k|| can round
to 1/√c beyond a ≈ 10; call Klein.proj before using such points.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Hyperboloid origin maps to the Klein origin >>> k = isometry_mappings.hyperboloid_to_klein(jnp.array([1.0, 0.0, 0.0]), c=1.0) >>> bool(jnp.allclose(k, jnp.zeros(2))) True
References: Wikipedia: Hyperboloid model - Relation to other models
Source code in hyperbolix/manifolds/isometry_mappings.py
klein_to_pv ¶
Convert a Beltrami-Klein point to Proper Velocity space.
A Klein point is an Einstein (coordinate) velocity; its proper velocity is the velocity times its Lorentz factor.
Formula: x = gamma_k·k = k / √(1 - c·||k||²)
The image grows without bound as k approaches the boundary (PV is the
unconstrained model); 1 - c·||k||² is floored at _boundary_divisor_floor(k, c)
(see :func:_klein_gap), reached at scaled radius a ≈ 6.7 (float32) /
14.2 (float64) at c = 1.
Args: k: Point in the Klein ball, shape (dim,). Should satisfy ||k||² < 1/c. c: Curvature (positive).
Returns: Point in PV space (unconstrained R^n), shape (dim,).
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Klein origin maps to the PV origin >>> x = isometry_mappings.klein_to_pv(jnp.zeros(2), c=1.0) >>> bool(jnp.allclose(x, jnp.zeros(2))) True
References: Ungar. "Analytic Hyperbolic Geometry: Mathematical Foundations and Applications." World Scientific, 2005 — Einstein and PV gyrogroups.
Source code in hyperbolix/manifolds/isometry_mappings.py
pv_to_klein ¶
Convert a Proper Velocity point to the Beltrami-Klein model.
Inverse of :func:klein_to_pv: the Einstein velocity is the proper velocity
times the PV beta factor β_x = 1/√(1 + c·||x||²).
Formula: k = β_x·x = x / √(1 + c·||x||²)
Every finite PV point lands inside the Klein ball in exact arithmetic. The
result is not projected: in floating point a point beyond scaled radius ≈ 6.3
(float32) / 13.9 (float64) at c = 1 lands past the Klein.proj margin, and
Klein operations read it at radius ≤ 6.67 / 14.21 (see the module docstring).
Call Klein.proj on the result for such points.
Args: x: Point in PV space (unconstrained R^n), shape (dim,). c: Curvature (positive).
Returns:
Point in the closed Klein ball, shape (dim,). In float32, ||k|| can round
to 1/√c beyond a ≈ 10; call Klein.proj before using such points.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # PV origin maps to the Klein origin >>> k = isometry_mappings.pv_to_klein(jnp.zeros(2), c=1.0) >>> bool(jnp.allclose(k, jnp.zeros(2))) True
References: Ungar. "Analytic Hyperbolic Geometry: Mathematical Foundations and Applications." World Scientific, 2005 — Einstein and PV gyrogroups.
Source code in hyperbolix/manifolds/isometry_mappings.py
halfspace_to_poincare ¶
Convert a Poincaré half-space point to the Poincaré ball (the Cayley transform).
With x = (x_s, x_n), x_n > 0 (last coordinate), scaled coordinates
s = √c·x and
Formula: q = c·||x_s||² + (√c·x_n - 1)(√c·x_n + 1) (= c·||x||² - 1) den = ||s_s||² + (1 + s_n)² p = (2·s_s, q) / (√c·den)
The half-space origin e_n/√c maps to the ball origin with differential
exactly ½·I (no reflection); the positive x_n axis maps onto the
e_n diameter, x_n → ∞ to the north pole e_n/√c and x_n → 0 to
the boundary sphere.
Numerics: den is a sum of non-negative terms, at least 1 on the half-space,
so no floor is needed. q is written as a product so it does not cancel
near the sphere c·||x||² = 1 (the ball's equatorial plane p_n = 0). The
result is not projected: past the ball chart's ceiling (scaled radius
a ≈ 12.6 float32 / 27.7 float64 at c = 1) ||p|| lands beyond the
proj margin, and in float32 from a ≈ 18 on at 1/√c up to rounding,
as for every map into the ball — call Poincare.proj for such points. Past
float32 |s| ≈ 1.8e19 the squares overflow and the output is NaN, not a
saturated point.
Args: x: Point in the half-space, shape (dim,). Should satisfy x_n > 0. c: Curvature (positive).
Returns: Point in the Poincaré ball, shape (dim,). Satisfies ||p||² < 1/c.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Half-space origin e_n/√c maps to the Poincaré origin >>> p = isometry_mappings.halfspace_to_poincare(jnp.array([0.0, 0.0, 2.0]), c=0.25) >>> bool(jnp.allclose(p, jnp.zeros(3))) True
References:
HTorch (github.com/ydtydr/HTorch), manifolds/halfspace.py — HalfSpace.to_poincare.
Source code in hyperbolix/manifolds/isometry_mappings.py
poincare_to_halfspace ¶
Convert a Poincaré ball point to the Poincaré half-space (inverse Cayley transform).
Inverse of :func:halfspace_to_poincare. With scaled coordinates s = √c·p,
Formula: g = 1 - ||s||² (= 1 - c·||p||²) den = ||s_s||² + (s_n - 1)² (= ||s - e_n||²) x = (2·s_s, g) / (√c·den)
The ball origin maps to the half-space origin e_n/√c; the north pole
e_n/√c is the half-space's point at infinity and every other boundary
point lands on x_n = 0.
Numerics: g is floored at _boundary_divisor_floor(p, c) exactly as
:func:poincare_to_hyperboloid floors 1 - c·||y||² — half the analytic
minimum on a Poincare.proj-projected point, below the rounding band of a
capped one — which keeps x_n > 0 for an unprojected point outside the ball.
At the minimum itself the floor bound for 12-76 % of the capped points and
zeroed ∂x_n/∂p = -2c·p/(√c·den) + … there (relative error 1.0).
The ball chart ends at the proj margin, scaled radius a ≈ 12.6
(float32) / 27.7 (float64) at c = 1; a point past it is wherever
Poincare.proj put it, and its image is the half-space point at that
capped radius. den is not floored: it vanishes only at the north pole,
a point the half-space cannot hold, so the output there is inf/NaN —
loud, not a clamped finite point. On a projected point
den ≥ (1 - ||s||)², about c·eps**1.5 at the margin (√c·eps**0.75
in the scaled s, squared), so the division is finite everywhere the
ball is.
Args: p: Point in the Poincaré ball, shape (dim,). Should satisfy ||p||² < 1/c. c: Curvature (positive).
Returns: Point in the half-space, shape (dim,). Satisfies x_n > 0.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Poincaré origin maps to the half-space origin e_n/√c >>> x = isometry_mappings.poincare_to_halfspace(jnp.zeros(3), c=0.25) >>> bool(jnp.allclose(x, jnp.array([0.0, 0.0, 2.0]))) True
References:
HTorch (github.com/ydtydr/HTorch), manifolds/halfspace.py — the inverse of
HalfSpace.to_poincare.
Source code in hyperbolix/manifolds/isometry_mappings.py
halfspace_to_hyperboloid ¶
Convert a Poincaré half-space point to the hyperboloid model.
With x = (x_s, x_n), x_n > 0 (last coordinate), metric ||dx||²/(c·x_n²) and
origin e_n/√c, the map sends the origin to the hyperboloid origin [1/√c, 0, ..., 0]
and the vertical axis to the (X₀, X_n) plane. Let u_n = √c·x_n.
Formula: X_mid = x_s / (√c·x_n) (n-1 entries) X_n = (c·||x||² - 1) / (2c·x_n) = ||x_s||²/(2·x_n) + (u_n - 1)(u_n + 1)/(2c·x_n) X₀ = (c·||x||² + 1) / (2c·x_n) = √(1/c + ||X_mid||² + X_n²) X = [X₀, X_mid, X_n]
Numerics: the spatial part X_s = (X_mid, X_n) carries the point, and X₀ is rebuilt
from it with safe_hypot_norm exactly as :func:pv_to_hyperboloid and
:func:klein_to_hyperboloid do, so ⟨X,X⟩_L = -1/c holds to one rounding of X₀.
X_n keeps c·x_n² - 1 in the factored form (u_n - 1)(u_n + 1): the literal
c·||x||² - 1 rounds c·x_n² before subtracting and loses the relative accuracy of
X_n near the origin (float32, 1e-3/√c around it, c ∈ {1, 4}: median relative error 3.5e-8
against 1.6e-5 for the literal; at other c the rounding of √c bounds both). Where
c·||x||² ≈ 1 away from the axis (the hemisphere that maps to X_n = 0) the subtraction
cancels in every spelling; the absolute error there is ~eps·X₀, the hyperboloid's own
storage floor. ||x_s||²/(2·x_n) carries no factor of
c, and it overflows float32 only once ||x_s|| passes 1.8e19, where X_n ≥ ||x_s||
is already past the hyperboloid's float32 coordinate ceiling, so the overflow is where the
hyperboloid itself returns inf. x_n is not floored: every x_n > 0 is a valid point,
and x_n ≤ 0 is off the model and returns inf/NaN. The result is not projected.
Args: x: Point in the half-space, shape (dim,). Should satisfy x_n = x[-1] > 0. c: Curvature (positive).
Returns: Point on the hyperboloid, shape (dim+1,). Satisfies ⟨X,X⟩_L = -1/c, X₀ > 0.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Half-space origin e_n/√c maps to the hyperboloid origin [1/√c, 0, ...] >>> X = isometry_mappings.halfspace_to_hyperboloid(jnp.array([0.0, 2.0]), c=0.25) >>> bool(jnp.allclose(X, jnp.array([2.0, 0.0, 0.0]))) True
References:
HTorch (github.com/ydtydr/HTorch), manifolds/halfspace.py — HalfSpace.to_lorentz
(time coordinate last there; first here).
Source code in hyperbolix/manifolds/isometry_mappings.py
hyperboloid_to_halfspace ¶
Convert a hyperboloid point to the Poincaré half-space model.
Inverse of :func:halfspace_to_hyperboloid. With X = [X₀, X_mid, X_n] and
Δ = X₀ - X_n > 0:
Formula: x_s = X_mid / (√c·Δ) x_n = 1 / (c·Δ)
Numerics: written literally, Δ is a difference of two O(sinh a) numbers whose result
is O(e^{-a}) for points far up the vertical axis or out along the horosphere through the
origin (X_n ≈ X₀). For X_n ≥ 0 the sheet constraint gives the cancellation-free form
Δ = (1/c + ||X_mid||²) / (X₀ + X_n),
and for X_n < 0 the literal X₀ - X_n is a sum of positive values. This is the spelling
of hyperboloid._busemann_arg with v = e_n: the numerator is built from the spatial
part, and the stored X₀ enters only the denominator (and the X_n < 0 branch). The unused
denominator is X₀ + where(X_n ≥ 0, X_n, 0), positive in both branches, so neither branch
produces a NaN cotangent under reverse mode. Δ is positive on the sheet, so no floor is
needed. The result is not projected. Measured in float32 against a 60-digit oracle, c ∈ {0.3,
1, 4, 10}: median relative error 5e-8 far up the axis (√c·x_n up to 1e6) and ≤ 7e-8 in
every other family. The literal X₀ - X_n gives 0.2 far up the axis, first returns inf
at √c·x_n ≈ 6e3, and returns it for almost every point past 1e4.
Args: x: Point on the hyperboloid, shape (dim+1,). Should satisfy ⟨x,x⟩_L = -1/c. c: Curvature (positive).
Returns: Point in the half-space, shape (dim,). Satisfies x_n > 0.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Hyperboloid origin [1/√c, 0, ...] maps to the half-space origin e_n/√c >>> x = isometry_mappings.hyperboloid_to_halfspace(jnp.array([2.0, 0.0, 0.0]), c=0.25) >>> bool(jnp.allclose(x, jnp.array([0.0, 2.0]))) True
References:
HTorch (github.com/ydtydr/HTorch), manifolds/halfspace.py — the inverse of
HalfSpace.to_lorentz.
Source code in hyperbolix/manifolds/isometry_mappings.py
halfspace_to_klein ¶
Convert a Poincaré half-space point to the Beltrami-Klein model.
The hyperboloid lift X = ((||x||² + 1/c)/(2·x_n), x_s/(√c·x_n), (||x||² - 1/c)/(2·x_n))
followed by the central projection k = X_s/(√c·X₀) of :func:hyperboloid_to_klein,
collapsed into one rational map. With x = (x_s, x_n), x_n > 0:
Formula: k = (2·x_s, (c·||x||² - 1)/√c) / (1 + c·||x||²)
The half-space origin e_n/√c maps to the Klein origin, and the axis x_s = 0 to the
Klein diameter along e_n: x_n → ∞ reaches the north pole e_n/√c, x_n → 0 the
south pole. The numerator c·||x||² - 1 vanishes at the origin; it is evaluated as
c·||x_s||² + (√c·x_n - 1)(√c·x_n + 1), exact near the origin whenever √c·x_n is (c a
power of 4, c = 1 included: float32 relative error of k_n at √c·x_n = 1 + 1e-4 is
0.2 eps against 840 eps for the literal c·||x||² - 1). At other c the rounding of √c
limits both spellings alike, to a sub-eps absolute error on √c·k_n.
The result is not projected. Since √c·||k|| = tanh(a) with a = √c·d(o, x), a point
beyond scaled radius ≈ 6.3 (float32) / 13.9 (float64) at c = 1 lands past the Klein.proj
margin, and Klein operations read it at radius ≤ 6.67 / 14.21 (see the module docstring). Call
Klein.proj on the result for such points. Past √c·||x|| ≈ 1.8e19 (float32, scaled
radius ≈ 44) c·||x||² overflows and k_n is NaN.
Args: x: Point in the half-space, shape (dim,). Should satisfy x_n = x[-1] > 0. c: Curvature (positive).
Returns:
Point in the closed Klein ball, shape (dim,). In float32, ||k|| can round
to 1/√c beyond a ≈ 10; call Klein.proj before using such points.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Half-space origin e_n/√c maps to the Klein origin >>> k = isometry_mappings.halfspace_to_klein(jnp.array([0.0, 1.0]), c=1.0) >>> bool(jnp.allclose(k, jnp.zeros(2))) True
References: Wikipedia: Poincaré half-plane model / Beltrami-Klein model - Relation to other models
Source code in hyperbolix/manifolds/isometry_mappings.py
klein_to_halfspace ¶
Convert a Beltrami-Klein point to the Poincaré half-space model.
Inverse of :func:halfspace_to_klein. With k = (k_s, k_n) and the Klein gap
g_k = 1 - c·||k||²:
Formula: Δ = 1 - √c·k_n x = (k_s/Δ, √g_k/(√c·Δ))
Δ vanishes at the north pole e_n/√c (far up the half-space axis). For k_n > 0 it is
evaluated as Δ = (1 - c·k_n²)/(1 + √c·k_n) with 1 - c·k_n² = g_k + c·||k_s||², so
the only cancellation left is that of g_k (:func:_klein_gap), the Klein chart's own
floor eps·cosh²(a) at scaled radius a = √c·d(0, k), and the rounded √c never enters a
difference. Every spelling of Δ is limited by that same eps·cosh²(a) floor; the
gap-based form above only removes the extra rounding that the literal 1 - √c·k_n adds on
top of it.
g_k is floored at _boundary_divisor_floor(k, c), so every point of the closed ball maps
to a finite half-space point with x_n > 0: a Klein point past the floor's radius, the north
pole itself included, lands at the scaled radius ≈ 6.67 (float32) / 14.21 (float64) at c = 1
that the Klein operations read it at.
Args: k: Point in the Klein ball, shape (dim,). Should satisfy ||k||² < 1/c. c: Curvature (positive).
Returns: Point in the half-space, shape (dim,). Satisfies x_n = x[-1] > 0.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Klein origin maps to the half-space origin e_n/√c >>> x = isometry_mappings.klein_to_halfspace(jnp.zeros(2), c=1.0) >>> bool(jnp.allclose(x, jnp.array([0.0, 1.0]))) True
References: Wikipedia: Poincaré half-plane model / Beltrami-Klein model - Relation to other models
Source code in hyperbolix/manifolds/isometry_mappings.py
halfspace_to_pv ¶
Convert a Poincaré half-space point to Proper Velocity space.
PV coordinates are the space-like part of the hyperboloid point, so this is the
spatial part of the half-space → hyperboloid lift. With x = (x_s, x_n),
x_n > 0 the last coordinate:
Formula: u_s = x_s / (√c·x_n) u_n = (c·||x||² - 1) / (2c·x_n) = ½·(||x_s||²/x_n + (x_n - 1/√c)·(x_n + 1/√c)/x_n)
The second spelling of u_n is the one evaluated. The factor
(x_n - 1/√c)(x_n + 1/√c) is x_n² - 1/c without cancellation near the
origin x_n = 1/√c (u_n keeps its relative accuracy as it passes through
0), and ||x_s||²/x_n is formed as (x_s/x_n)·x_s, a sum of non-negative
terms. Nothing is squared before a division by x_n, so no intermediate
overflows where u itself is representable: float32 c·||x||² would overflow
at x_n = 1.8e19/√c (scaled radius ≈ 44), where u_n ≈ x_n/2 is still
finite. The input is not floored: x_n = 0 is off the model and returns
inf.
Args: x: Point in the half-space, shape (dim,). Should satisfy x_n > 0. c: Curvature (positive).
Returns: Point in PV space (unconstrained R^n), shape (dim,).
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # Half-space origin e_n/√c maps to the PV origin (0) >>> u = isometry_mappings.halfspace_to_pv(jnp.array([0.0, 2.0]), c=0.25) >>> bool(jnp.allclose(u, jnp.zeros(2))) True
References: Wikipedia: Poincaré half-plane model / Hyperboloid model — the half-space ↔ hyperboloid relation (unit curvature, rescaled by 1/√c here).
Source code in hyperbolix/manifolds/isometry_mappings.py
pv_to_halfspace ¶
Convert a Proper Velocity point to the Poincaré half-space.
Inverse of :func:halfspace_to_pv. With u = (u_s, u_n) and the hyperboloid
time slot X₀ = √(1/c + ||u||²):
Formula: Δ = X₀ - u_n (> 0) x = (u_s / (√c·Δ), 1 / (c·Δ))
Δ is evaluated without cancellation: for u_n > 0 (the upper half of the
model, towards x_n → ∞) the literal X₀ - u_n subtracts two nearly equal
numbers, so it is rewritten as
Δ = (1/c + ||u_s||²)/(X₀ + u_n) = (1/c)/s + (u_s/s)·u_s, s = X₀ + u_n,
while for u_n ≤ 0 the literal form is a sum and is used as is. Each factor
u_s/s is at most 1 in magnitude and every term is non-negative, so the
||u_s||² that would overflow float32 past ||u_s|| = 1.8e19 is never formed;
X₀ comes from safe_hypot_norm for the same reason. The result is finite
wherever it is representable. Measured in float32 far up the axis
(u = (0.3, 0, u_n), c = 1, against a 150-digit reference): the literal
X₀ - u_n gives x_n with relative error 7.9e-3 at u_n = 1e3, 0.26 at
3e3, and inf from u_n ≈ 4.1e3 (scaled radius ≈ 9) on; this form stays
below 7e-8 out to u_n = 1e30, and at ||u_s|| = 3e19 (where the literal form
returns x = 0) within 5e-8.
Args: u: Point in PV space (unconstrained R^n), shape (dim,). c: Curvature (positive).
Returns: Point in the half-space, shape (dim,). Satisfies x_n > 0.
Examples: >>> import jax.numpy as jnp >>> from hyperbolix.manifolds import isometry_mappings >>> >>> # PV origin maps to the half-space origin e_n/√c >>> x = isometry_mappings.pv_to_halfspace(jnp.zeros(2), c=0.25) >>> bool(jnp.allclose(x, jnp.array([0.0, 2.0]))) True
References: Wikipedia: Poincaré half-plane model / Hyperboloid model — the half-space ↔ hyperboloid relation (unit curvature, rescaled by 1/√c here).
Source code in hyperbolix/manifolds/isometry_mappings.py
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 | |
Usage Examples¶
Basic Distance Computation¶
import jax.numpy as jnp
from hyperbolix.manifolds import Poincare
poincare = Poincare()
x = jnp.array([0.1, 0.2])
y = jnp.array([0.3, -0.1])
c = 1.0
# Compute distance (default: VERSION_MOBIUS_DIRECT)
distance = poincare.dist(x, y, c)
Float64 Precision¶
import jax
jax.config.update("jax_enable_x64", True) # float64 needs x64 enabled
from hyperbolix.manifolds import Poincare
import jax.numpy as jnp
# High-precision manifold
poincare_f64 = Poincare(dtype=jnp.float64)
x = jnp.array([0.1, 0.2], dtype=jnp.float32) # float32 input
y = jnp.array([0.3, -0.1], dtype=jnp.float32)
distance = poincare_f64.dist(x, y, c=1.0) # automatically cast to float64
print(distance.dtype) # float64
Batched Operations with vmap¶
import jax
from hyperbolix.manifolds import Hyperboloid
hyperboloid = Hyperboloid()
c = 1.0
# Batch of ambient points (d+1 dimensions)
x_batch = jax.random.normal(jax.random.PRNGKey(0), (100, 4))
y_batch = jax.random.normal(jax.random.PRNGKey(1), (100, 4))
# Project to hyperboloid
x_proj = jax.vmap(hyperboloid.proj, in_axes=(0, None))(x_batch, c)
y_proj = jax.vmap(hyperboloid.proj, in_axes=(0, None))(y_batch, c)
# Compute distances
distances = jax.vmap(hyperboloid.dist, in_axes=(0, 0, None))(x_proj, y_proj, c)
Exponential and Logarithmic Maps¶
from hyperbolix.manifolds import Poincare
import jax.numpy as jnp
poincare = Poincare()
# Point on manifold
x = poincare.proj(jnp.array([0.2, 0.3]), c=1.0)
# Tangent vector
v = jnp.array([0.1, -0.05])
# Exponential map (move along geodesic)
y = poincare.expmap(v, x, c=1.0)
# Logarithmic map (inverse operation)
v_recovered = poincare.logmap(y, x, c=1.0)
Proper Velocity Operations¶
import jax
import jax.numpy as jnp
from hyperbolix.manifolds import ProperVelocity
pv = ProperVelocity()
c = 1.0
# Points live in unconstrained R^n — no projection step needed
x = jnp.array([0.3, 0.5])
y = jnp.array([-0.2, 0.4])
# Geodesic distance (asinh form — stable over all of R^n)
d = pv.dist(x, y, c)
# Exp/log maps at the origin
v = jnp.array([0.1, -0.2])
y_moved = pv.expmap_0(v, c)
v_recovered = pv.logmap_0(y_moved, c)
# Euclidean gradient -> Riemannian gradient under the PV metric
grad_euc = jnp.array([1.0, 0.0])
grad_riem = pv.egrad2rgrad(grad_euc, x, c)
# Retraction is exact Euclidean addition (PV is unconstrained)
x_next = pv.retraction(v, x, c)
assert jnp.allclose(x_next, x + v)
Klein Operations¶
import jax.numpy as jnp
from hyperbolix.manifolds import Klein, isometry_mappings
klein = Klein()
c = 1.0
x = jnp.array([0.3, 0.5]) # points in the ball c‖x‖² < 1
y = jnp.array([-0.2, 0.4])
d = klein.dist(x, y, c) # cancellation-free arsinh form
v = klein.logmap(y, x, c) # parallel to the chord y - x
y_rec = klein.expmap(v, x, c) # back to y
gamma = klein.lorentz_factor(x, c) # 1/√(1 - c‖x‖²)
m = klein.einstein_midpoint(jnp.stack([x, y]), None, c) # = Lorentz centroid
# Einstein addition in Klein = Möbius addition in Poincaré, through the isometry
p = isometry_mappings.klein_to_poincare(x, c)
x_back = isometry_mappings.poincare_to_klein(p, c)
HalfSpace Operations¶
import jax.numpy as jnp
from hyperbolix.manifolds import HalfSpace, Poincare, isometry_mappings
halfspace = HalfSpace()
c = 1.0
x = jnp.array([0.1, 1.0]) # (x_s, x_n): the height x_n > 0 is the last coordinate
y = jnp.array([0.3, 0.5])
d = halfspace.dist(x, y, c) # (2/√c)·asinh(‖r‖/2), cancellation-free
v = halfspace.logmap(y, x, c) # tangent_norm(v, x, c) equals d
y_rec = halfspace.expmap(v, x, c) # back to y
o = halfspace.expmap_0(jnp.zeros(2), c) # the origin e_n/√c = [0, 1]
# The Cayley transform to the Poincaré ball preserves the distance
p_x = isometry_mappings.halfspace_to_poincare(x, c)
p_y = isometry_mappings.halfspace_to_poincare(y, c)
d_ball = Poincare().dist(p_x, p_y, c) # equals d
x_back = isometry_mappings.poincare_to_halfspace(p_x, c) # round trip to x
Product Manifolds (Mixed Curvature)¶
import jax
import jax.numpy as jnp
from hyperbolix.manifolds import (
ProductManifold, Hyperboloid, Poincare, Euclidean,
)
# Build P = H^5(c=1.0) x P^3(c=0.1) x E^4
product = ProductManifold(
(Hyperboloid(c=1.0), 5), # 5 = ambient dim (d+1) for hyperboloid
(Poincare(c=0.1), 3), # 3 = spatial dim for poincaré
(Euclidean(), 4), # 4 = standard euclidean dim
)
# Per-factor curvatures must be passed at call time as a sequence.
c = product.curvatures # (1.0, 0.1, 0.0) — static default
o = product.origin(c) # shape (12,)
# Pythagorean product distance: d_P = sqrt(sum d_i^2)
x = product.origin(c)
y = product.origin(c) # generated elsewhere; here we use o for illustration
d_l2 = product.dist(x, y, c) # scalar
d_per_factor = product.component_dist(x, y, c) # shape (3,) per-factor distances
# Batch with vmap: broadcast c with None across the batch.
dist_batch = jax.vmap(product.dist, in_axes=(0, 0, None))
# distances = dist_batch(xs, ys, c)
# Repeated-factor construction via from_signature
mixed = ProductManifold.from_signature(
(Hyperboloid, 5, 4, 1.0), # 4 copies of H^4(c=1.0)
(Poincare, 3, 2, 0.1), # 2 copies of P^3(c=0.1)
(Euclidean, 4, 1), # 1 copy of E^4
)
# For learnable curvature, build the sequence from LearnableCurvature calls on
# your nnx.Module:
# c = (self.curv_h(), self.curv_p(), 0.0)
# d = product.dist(x, y, c)
Isometry Mappings¶
from hyperbolix.manifolds import isometry_mappings
import jax.numpy as jnp
# Hyperboloid point (ambient coordinates, d+1 dims)
x_hyperboloid = isometry_mappings.pv_to_hyperboloid(jnp.array([0.5, 0.3]), c=1.0) # on the hyperboloid
# Map to Poincaré ball (intrinsic coordinates, d dims)
x_poincare = isometry_mappings.hyperboloid_to_poincare(x_hyperboloid, c=1.0)
# Map back (round-trip)
x_hyperboloid_recovered = isometry_mappings.poincare_to_hyperboloid(x_poincare, c=1.0)
Numerical Considerations¶
Float32 Precision
The Poincaré and Klein charts hold pairwise ops to a fixed scaled radius \(\sqrt{c}\,d\) in float32 (Poincaré 12.6, Klein 6.32 at \(c = 1\)). The hyperboloid has no fixed radius: its float32 error grows as \(\varepsilon\sinh(\sqrt{c}\,d)\) and loses its last digit between about 16.6 and 18. Past these, use float64 (jax_enable_x64 plus dtype=jnp.float64).
See the Numerical Stability guide for details.