Skip to main content

Riemannian geometry and Bayesian inference for diffusion model latent spaces

Project description

latent-riemannian-world

PyPI Python License: BSL-1.1

Riemannian geometry + Bayesian inference + world models for diffusion model latent spaces.

Existing tools treat latent space as Euclidean. This library treats it as a Riemannian manifold — computing geodesics (true shortest paths on curved space), parallel transport, and curvature. Bayesian extensions add uncertainty quantification. World model extensions add temporal state transitions.

Why this library?

latent-geometry Diffusion-Pullback lrw
Pullback metric
Fisher-Rao metric
Bayesian (uncertain) metric
Geodesic solver
Parallel transport
SVGD / Riemannian SGLD
World model / temporal
Python 3.12+ / PyTorch 2.4+
pip installable

Installation

pip install latent-riemannian-world

Quick Start

import torch
from lrw.metric import PullbackMetric, BayesianMetric
from lrw.geodesic import GeodesicSolver
from lrw.transport import SchildsLadder
from lrw.bayes import SVGD, RiemannianSGLD
from lrw.world import LatentStateSpace, RiemannianRSSM

# Your diffusion model decoder
decoder = your_model.decode   # (B, D) -> (B, C, H, W)

# Pullback metric: G(z) = J(z)^T J(z)
metric = PullbackMetric(decoder=decoder)
z = torch.randn(4, 16)
G = metric.metric_tensor(z)   # (4, 16, 16) Riemannian metric matrices

# Geodesic interpolation between two latent points
solver = GeodesicSolver(metric=metric)
path = solver.interpolate(z[0:1], z[1:2], n_points=10)

# Parallel transport of a style vector along the geodesic
ladder = SchildsLadder(metric=metric)
v_transported = ladder.transport(z[0:1], z[1:2], style_vector)

# Bayesian metric with MC-Dropout ensemble
decoders = [decoder_with_dropout() for _ in range(8)]
bayes_metric = BayesianMetric(decoder_ensemble=decoders)
G_bayes = bayes_metric.metric_tensor(z)
G_var   = bayes_metric.metric_variance(z)

# World model: temporal transitions as geodesic flows
state_space = LatentStateSpace(metric=metric, dt=0.1)
z_next, v_next = state_space.step(z, velocity)
states, velocities = state_space.rollout(z, velocity, n_steps=20)

Module Structure

lrw/
├── metric/      PullbackMetric, FisherMetric, BayesianMetric
├── geodesic/    GeodesicSolver, slerp, slerp_path
├── transport/   SchildsLadder
├── bayes/       SVGD, RiemannianSGLD
├── world/       LatentStateSpace, RiemannianRSSM
└── utils/       sym_inv, sym_sqrt, riemannian_norm, batch_jacobian

References

  • Shao et al. (2018) The Riemannian Geometry of Deep Generative Models. CVPR.
  • Arvanitidis et al. (2018) Latent Space Oddity: on the Curvature of Deep Generative Models. ICLR.
  • Park et al. (2023) Understanding the Latent Space of Diffusion Models through the Lens of Riemannian Geometry. NeurIPS.
  • Liu et al. (2016) Stein Variational Gradient Descent. NeurIPS.
  • Hafner et al. (2020) Dream to Control: Learning Behaviors by Latent Imagination. ICLR.

License

This project is licensed under the Business Source License 1.1 (BSL-1.1). Non-production use (research, personal projects, evaluation) is free. For commercial/production use, contact the author.

(c) 2025 lajjadred

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

latent_riemannian_world-0.1.0.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

latent_riemannian_world-0.1.0-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file latent_riemannian_world-0.1.0.tar.gz.

File metadata

  • Download URL: latent_riemannian_world-0.1.0.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for latent_riemannian_world-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ffdf6e3fbf720ada9e79ed4a66bb515b267e28a4ceb8ee299d9595442dcf2966
MD5 7b5afa28affe82875cf5da9ce38b3daa
BLAKE2b-256 f217de9503f4fa77d3f529a1824b9851fff3e321b8928c0014f3fbc2cc2e1896

See more details on using hashes here.

File details

Details for the file latent_riemannian_world-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for latent_riemannian_world-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a95c7659d2a64f5f62c906671ec8aae1932798d0db5c313a0e49d914dc6b497
MD5 adbff51babd81b47cf99c451db2bf8c2
BLAKE2b-256 6a6686fc4aaa49069617e42413f41c20ac8a8c98b41ad2c1d8a3c58a3aebb785

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page