Manifold-valued learning#
GeoJAX separates the geometry of observations from the statistical method applied to them. A geometry defines point validity, distance, logarithmic and exponential maps, and optional equivariant embeddings. The learning layer validates a collection once and then consumes those operations without making assumptions about whether a point is a vector, matrix, or Product pytree. This follows the metric-statistics view of random objects while retaining JAX transformations for differentiable primitives [Bronstein et al., 2021, Dubey and Müller, 2019, Fréchet, 1948].
Canonical datasets#
For an array geometry with event shape M.shape, the canonical dataset layout
is
The axis immediately before the event dimensions is the sample axis. Product
data use the same nested tuple, list, or dictionary as M.factors; every leaf
has the same batch shape and sample count but its own event shape.
import jax
from geojax.geometry import Product, SPDLogEuclidean, Sphere
from geojax.learning import as_manifold_data
M = Product({
"direction": Sphere(3),
"covariance": SPDLogEuclidean((2, 2)),
})
values = M.random_point(jax.random.key(0), sample_shape=(32,))
data = as_manifold_data(M, values)
as_manifold_data defaults to membership validation. It rejects malformed,
nonfinite, or off-manifold observations. Passing repair=True explicitly calls
M.project; projection is never silent. sample_axis must be provided when an
input does not already use the canonical layout, so an adapter never guesses
which axis represents observations.
Each ManifoldData object is bound to the exact geometry instance that
validated it. This matters when two geometries share an event shape but use
different metrics or parameters. Reusing the object with that instance skips
validation already performed; requesting a stronger level upgrades the check
in the order shape, finite, belongs. To use the same canonical values
with another geometry, adapt data.values explicitly under that geometry.
Alternate representations#
The adapter accepts named representations only when their conversion has a defined geometric meaning. Examples include hyperspherical angles, Poincaré coordinates, Grassmann projectors, SPD Cholesky factors, covariance matrices for correlation geometries, SO(3) quaternions, SE(2)/SE(3) twists, raw Kendall landmarks, and low-rank factors. Product representations may themselves be pytrees.
from geojax.geometry import Grassmann
from geojax.learning import as_manifold_data
M = Grassmann((5, 2))
frames = as_manifold_data(M, projectors, representation="projector")
A spanning basis represents the same Grassmann point and may be
orthonormalized directly. A nonorthonormal Stiefel frame represents a different
ambient matrix, so it is accepted only through repair=True. User-defined
representations can be added with register_manifold_data_adapter.
Exact capabilities#
Distance-only methods require operation_kind("dist") == "exact". Methods
that update intrinsic centers additionally require exact logarithmic and
exponential maps. GeoJAX raises LearningCapabilityError when a geometry only
offers a retraction proxy or numerical-local logarithm. This prevents an
algorithm named after a geodesic quantity from silently changing its
mathematical objective.
Required geometry |
Learning methods |
|---|---|
Exact distance |
pairwise distances, neighbors, nearest-centroid and k-NN prediction, medoids, hierarchy, spectral and graph learning, kernel regression, MDS, Isomap, kernel PCA, Sammon, t-SNE, PHATE, transport, energy and kernel tests |
Exact distance, logarithm, exponential |
interpolation, Fréchet and robust summaries, geodesic and local Fréchet regression, k-means and mini-batch summaries, mean shift, CLRQ, PGA, barycentric coding, dictionary learning, enclosing balls, Fréchet ANOVA, paired tests |
Equivariant embedding |
Riemannian manifold metric learning |
Differentiable primitives#
geojax.learning.pairwise_distances() returns ordinary or squared exact
distances. Collections broadcast over leading batch axes, Product values remain
pytrees, and block_size limits temporary right-hand blocks while retaining a
dense result. The returned matrix still requires
\(O(n_\mathrm{left}n_\mathrm{right})\) memory; blocking controls intermediate
geometry evaluations, not the output size.
from geojax.learning import pairwise_distances
squared = pairwise_distances(M, queries, prototypes, squared=True)
logits = -squared
Geodesic interpolation evaluates
and tangent_space_map composes a user transformation between source and
target tangent spaces. These wrappers are compatible with jax.jit,
jax.vmap, and differentiation whenever the selected geometry operations are.
Statistical algorithms#
Fréchet means minimize weighted squared distance and use GeoJAX’s manifold optimizer. Their default line search starts with a half-gradient step and uses retraction-curve derivatives to check progress when objective changes are comparable to floating-point rounding. Convergence still requires the reported gradient tolerance; a small step alone does not certify a mean. An explicitly supplied solver retains its own line-search settings. Custom retractions that encounter JAX tracing errors from Python or NumPy scalar conversions use the previous Armijo strategy without the derivative-based safeguard; unrelated errors still propagate. Medians use a guarded Riemannian Weiszfeld iteration for a Huber-smoothed distance objective; the returned diagnostics distinguish that objective from the unsmoothed median loss. The minimum enclosing ball uses a farthest-point approximation, so its convergence flag certifies stabilization of that iteration rather than global optimality on an arbitrary manifold. Clustering provides intrinsic Lloyd updates, medoids, valid metric-space linkage rules, spectral graph methods, mean shift, and competitive quantization [Karcher, 1977, Lloyd, 1982, Zelnik-Manor and Perona, 2005].
Dimension-reduction methods consume exact pairwise distances. PGA differs: it
forms its covariance Gram matrix with M.inner at the Fréchet mean, so the
result remains valid for Product manifolds and metrics that are not ambient
Frobenius metrics [Fletcher et al., 2004]. Classical MDS and kernel
methods report negative eigenvalue mass rather than pretending every manifold
distance is Euclidean. Classical scaling normalizes the distance scale before
forming its Gram matrix and reports both normalized and physical spectra. It
raises when squaring the physical scale is not representable in the selected
dtype instead of returning overflowed diagnostics. GeoJAX’s phate follows
the PHATE diffusion-potential construction but uses classical scaling for the
final metric embedding; it is a dependency-free dense approximation rather
than the reference package’s metric-MDS optimizer.
Dense spectral and graph routines materialize \(n\times n\) distance, affinity,
or Laplacian matrices. They therefore require \(O(n^2)\) memory, and dense
eigendecompositions can require \(O(n^3)\) work. For large datasets, reduce the
sample set first or use the mini-batch and coreset routines rather than treating
block_size as a sparse-graph substitute.
The exact empirical Wasserstein routine solves the finite weighted transport
problem and reports its transport plan, marginal residuals, reduced costs, and
duality gap. The eager simplex solver uses common integer units for its mass
and cost comparisons. It converts the supplied weights before normalization,
so splitting an atom into repeated observations with the same total weight
preserves the measure. The objective uses those mass units even when a plan
entry is too small to represent in the output dtype. Zero-weight points keep
their places in the returned plan. The solver uses their positive-weight counterparts to set the distance
scale. For \(p=1\) and \(p=2\) the pivot comparisons preserve the stored distances
and their exact squares. Other finite powers use rounded mantissas and separate
binary exponents. An extreme fractional-power range that would require more
than a million bits per cost raises a range error. The distance can remain
finite when its \(p\)-th power exceeds the output dtype. sinkhorn_divergence is a separate optional OTT-JAX operation;
regularization is never labeled exact [Cuturi, 2013].
Inference separates three null hypotheses. Fréchet ANOVA compares object-valued populations through their means and variances, the Biswas–Ghosh statistic uses only interpoint distances, and the Wasserstein test compares empirical measures [Biswas and Ghosh, 2014, Dubey and Müller, 2019]. Permutation calibration is finite-sample valid only under exchangeability of the pooled labels. A distance statistic need not characterize equality of distributions on every metric space; any stronger consistency claim requires the assumptions in the cited result.
For group proportions \(\gamma_j\), Fréchet variances \(V_j\), variance estimators \(\sigma_j^2\), and
frechet_anova reports the Dubey–Müller statistic
The asymptotic calibration requires the regularity conditions of the cited result; the permutation option instead calibrates the same statistic under exchangeable group labels.
riemannian_metric_learning forms similar- and dissimilar-pair scatter
matrices after an equivariant embedding, regularizes both matrices, and uses
their weighted log-Euclidean closed form. The balance parameter controls the
relative contributions; the default midpoint matches the core RMML
construction [Zhu et al., 2018].
Supervised prediction#
Distance classifiers make the smallest geometric commitment. The nearest- centroid rule estimates one weighted Fréchet mean \(\widehat\mu_c\) per class and predicts
while knn_classifier votes among the \(k\) closest training observations. Both
work with any exact-distance geometry, including nested Product data.
NearestCentroidModel.predict_proba converts negative squared distances into a
Gibbs score with a query-local scale. Those rows sum to one, but they are not
calibrated posterior probabilities. Centroid and tangent-feature models expose
whether their internal Fréchet reference fits converged; callers should inspect
converged, reason, and the stored fit diagnostics before treating a model as
fully resolved.
Tangent classifiers first compute a reference Fréchet mean \(\widehat\mu\) and an intrinsic metric Gram matrix
Its positive eigenspace gives metric-orthonormal coordinates, rather than an
ambient Frobenius flattening. tangent_space_logistic_regression fits a
multinomial softmax model there;
tangent_space_discriminant_analysis provides regularized LDA and QDA. These
models are local to the selected logarithm chart and should not be interpreted
across a cut locus.
Manifold-valued responses#
geodesic_regression fits the one-predictor curve
by intrinsic least squares, profiling \(v\in T_p\mathcal M\) while optimizing the intercept \(p\) [Fletcher, 2013]. This is a parametric geodesic model, so systematic curvature away from one geodesic remains in the residuals.
local_polynomial_regression instead estimates a conditional Fréchet mean.
For local-linear smoothing at \(t\), its signed weights are
and the prediction minimizes \(\sum_i s_i(t)d^2(p,y_i)\). Degree zero uses positive Nadaraya–Watson weights. Signed local-linear objectives need not be globally convex on a general manifold, so GeoJAX initializes them with the positive local Fréchet mean and reports no global-optimum claim [Petersen and Müller, 2019].
Uncertainty and testing#
bootstrap_frechet_mean resamples the empirical measure, recomputes intrinsic
means, and reports the requested quantile of replicate distances from the
original estimate as a bootstrap geodesic ball. It is an approximate
percentile region, not a curvature-corrected confidence set.
The energy statistic compares between-sample and within-sample distances
[Székely and Rizzo, 2013]. On a completely general metric space, equality
characterization requires an appropriate negative-type condition. The MMD
test similarly requires a positive-semidefinite kernel
[Gretton et al., 2012]: GeoJAX checks the observed Gram eigenvalues by
default because an RBF of squared geodesic distance is not universally PSD.
The check uses the larger of the requested tolerance and a dtype-aware
eigensolver backward-error bound, so roundoff-scale negative eigenvalues in
float32 are not mistaken for a mathematically indefinite kernel.
The permutation test compares weighted sums of the stored Gram entries in
common integer units. This preserves exact ties when evaluating the empirical
kernel-mean difference for different assignments.
paired_frechet_test applies sign flips to paired tangent displacements.
Under the null, the joint sample must be invariant to independently swapping
the two observations within each pair. GeoJAX orders the pooled observations
deterministically before fitting their shared reference point, so every swap
uses the same fitted reference even when the mean solver has several local
solutions. The coordinate-based ordering selects among tied initializations;
it does not certify a unique or globally optimal mean. A tangent-symmetry
model instead requires joint sign-flip invariance conditional on the fitted
reference; marginal symmetry alone does not suffice.
Scalable summaries#
streaming_frechet_mean performs the inductive update
It is exact for a weighted Euclidean mean and order-dependent on a curved
manifold. By default the first positive-weight observation initializes the
recursion. A user-provided initial_point contributes only when accompanied by
an explicit positive initial_weight, so no undocumented pseudo-observation is
introduced. minibatch_frechet_mean and minibatch_kmeans use shuffled batches
and decaying log-map steps, following the stochastic Riemannian optimization
view [Bonnabel, 2013]. They require an explicit key and return
objective and update histories; they are approximations to the corresponding
full-batch estimators. A convergence flag additionally requires a full-data
stationarity check, so learning-rate decay alone cannot masquerade as
convergence. Competitive quantization applies the same distinction between a
flat objective history and stationary prototypes.
Barycentric coding and dictionaries#
For atoms \(D_1,\ldots,D_m\) and an observation \(x\), intrinsic barycentric coding solves
geodesic_barycentric_coding uses projected gradient steps on the simplex and
reconstructs each observation as the weighted Fréchet mean of its atoms.
manifold_dictionary_learning alternates these codes with a Product-manifold
optimization of the fixed-code intrinsic residual. Backtracking accepts only
atom updates that do not increase the reported reconstruction objective
[Ho et al., 2013]. These are dense barycentric codes; the simplex
\(\ell_1\) norm is constant, so the routine does not claim lasso sparsity. When
sample weights are supplied, atom optimization, backtracking acceptance, and
the returned objective all use the same normalized weighted criterion.
Robust and graph learning#
The trimmed mean repeatedly retains the smallest squared geodesic residuals
until the requested fraction of total sample-weight mass remains. If the trim
boundary crosses an observation’s weight, that boundary weight is included
partially. This reduces to ordinary count trimming under equal weights.
geodesic_m_estimator uses Huber, Cauchy, or Tukey residual weights in guarded
iteratively reweighted Fréchet updates. geodesic_spatial_depth evaluates
with the coincident contribution set to zero; distance ranks use midranks around an intrinsic median [Fletcher et al., 2009]. A weighted trimmed fit reports its objective with weights renormalized over the retained measure.
For partially labeled data, label_propagation diffuses class scores with a
symmetric normalized affinity operator and hard-clamps known labels after each
update
[Zhou et al., 2003]. manifold_regularized_regression solves the
dense transductive objective
where \(L_G\) is the graph Laplacian [Belkin et al., 2006]. The current result predicts only the supplied graph vertices; it does not claim the RKHS out-of-sample extension of the full manifold-regularization framework. For a \(k\)-nearest-neighbor graph, the diagonal is excluded before sorting, so tied duplicate observations cannot accidentally select themselves as neighbors.
Learning roadmap#
The adapter-first core now covers the former priority-one roadmap, intrinsic dictionary learning, robust analysis, and graph semi-supervision. The next candidate families are deliberately narrower:
Method family |
Candidate public methods |
Geometric requirements |
|---|---|---|
Graph embeddings |
diffusion maps and Laplacian eigenmaps |
exact distance or a user-supplied affinity |
Supervised reduction |
discriminant tangent components and supervised distance embeddings |
exact logarithm and metric or an equivariant embedding |
Model assessment |
intrinsic silhouette, gap statistic, and resampling-based clustering stability |
exact distance; randomized procedures require keys |
Transport statistics |
entropic Wasserstein barycenters and transport-based clustering |
optional differentiable Sinkhorn backend |
Curves and spatial-analysis routines remain outside this roadmap. The current nearest-neighbor search evaluates every candidate. Approximate search remains a possible extension for larger collections.
Computational limits#
Full pairwise distance matrices use \(O(n^2)\) storage for \(n\) observations. Floyd-Warshall Isomap and hierarchical updates can require \(O(n^3)\) work. The tiled nearest-neighbor search and sparse graph below avoid storing the full distance matrix. High-level assignments, permutations, graph construction, and exact transport involve discrete decisions.
Working with larger point collections#
Pass block_size to nearest_neighbors or knn_classifier to bound temporary
distance storage. For tiles of side \(b\) and \(k\) requested neighbors, a merge
holds \(O(b(b+k))\) distances and indices, in addition to input and output
storage. Every candidate is evaluated. Equal distances are ordered by the
training index. An implicit self-query excludes only the observation’s own
index. neighbor_graph returns a directed JAX sparse BCOO matrix with \(k\)
edges per row. Connectivity edges have weight one, and distance edges retain
explicit zeros between duplicates. The ordinary pairwise_distances operation
still returns its full rectangular output.
The optional OTT backend accepts sinkhorn_divergence(..., block_size=b).
It applies cross and self costs in blocks against the opposing support.
Reverse-mode differentiation recomputes each block when taking the cost gradient.
Its time and memory costs differ from the top-\(k\) search because the
regularized transport problem requires contributions from the whole support.
From multichannel observations to covariance matrices#
estimate_covariance treats all axes other than channel_axis and time_axis
as independent batches. By default it centers the time series and divides
the scatter by \(n-1\). Given sample covariance \(S\) and \(c\) channels, the
regularized result is
Here shrinkage sets \(\alpha\) and ridge sets \(\lambda\). Positive shrinkage
makes the estimate positive definite when the mean variance is positive.
A constant signal also needs a positive ridge for an SPD result. Choose
regularization using the training data in each cross-validation fold.
from geojax.learning import estimate_covariance
covariances = estimate_covariance(epochs, channel_axis=-2, time_axis=-1,
shrinkage=0.1, ridge=1e-6)
Predictive uncertainty for manifold responses#
wrapped_gaussian_process(M, predictors, responses, base_point=p) maps each
response into the tangent space at \(p\) with the logarithm. It fits an RBF
Gaussian process with a shared scalar kernel and independent coordinates in a
metric-orthonormal basis. Predictors are a sample vector or a sample-by-feature
matrix. The length scale uses predictor units, and both noise and signal
parameters are variances. Omitting the base fits a reference Fréchet mean
using the training responses.
from geojax.learning import wrapped_gaussian_process
model = wrapped_gaussian_process(M, t_train, y_train, base_point=p,
length_scale=0.8, noise_variance=0.01)
prediction = model.predict(t_query)
prediction.points applies the exponential to the posterior tangent means.
At prediction.base_point, the cross-covariance between queries \(i,j\) is
prediction.covariance[i, j] times the metric identity. This describes the
latent tangent function before wrapping, conditional on the chosen base and
kernel parameters. The fit rejects undefined training logarithms and a
singular training system. Prediction checks that its mean stays in the
chosen chart. A dense fit requires quadratic storage and cubic factorization
time in the training sample count.
References#
Mikhail Belkin, Partha Niyogi, and Vikas Sindhwani. Manifold regularization: a geometric framework for learning from labeled and unlabeled examples. Journal of Machine Learning Research, 7(85):2399–2434, 2006. URL: https://www.jmlr.org/papers/v7/belkin06a.html.
Munmun Biswas and Anil K. Ghosh. A nonparametric two-sample test applicable to high dimensional data. Journal of Multivariate Analysis, 123:160–171, 2014. doi:10.1016/j.jmva.2013.09.004.
Silvère Bonnabel. Stochastic gradient descent on Riemannian manifolds. IEEE Transactions on Automatic Control, 58(9):2217–2229, 2013. doi:10.1109/TAC.2013.2254619.
Michael M. Bronstein, Joan Bruna, Taco Cohen, and Petar Veličković. Geometric deep learning: grids, groups, graphs, geodesics, and gauges. arXiv preprint arXiv:2104.13478, 2021. doi:10.48550/arXiv.2104.13478.
Marco Cuturi. Sinkhorn distances: lightspeed computation of optimal transport. In Advances in Neural Information Processing Systems, volume 26, 2292–2300. 2013.
Paromita Dubey and Hans-Georg Müller. Fréchet analysis of variance for random objects. Biometrika, 106(4):803–821, 2019. doi:10.1093/biomet/asz052.
P. Thomas Fletcher. Geodesic regression and the theory of least squares on Riemannian manifolds. International Journal of Computer Vision, 105(2):171–185, 2013. doi:10.1007/s11263-012-0591-y.
P. Thomas Fletcher, Conglin Lu, Stephen M. Pizer, and Sarang Joshi. Principal geodesic analysis for the study of nonlinear statistics of shape. IEEE Transactions on Medical Imaging, 23(8):995–1005, 2004. doi:10.1109/TMI.2004.831793.
P. Thomas Fletcher, Suresh Venkatasubramanian, and Sarang Joshi. The geometric median on Riemannian manifolds with application to robust atlas estimation. NeuroImage, 45(1, Supplement 1):S143–S152, 2009. doi:10.1016/j.neuroimage.2008.10.052.
Maurice Fréchet. Les éléments aléatoires de nature quelconque dans un espace distancié. Annales de l'Institut Henri Poincaré, 10(4):215–310, 1948. URL: https://www.numdam.org/item/AIHP_1948__10_4_215_0/.
Arthur Gretton, Karsten M. Borgwardt, Malte J. Rasch, Bernhard Schölkopf, and Alexander Smola. A kernel two-sample test. Journal of Machine Learning Research, 13(25):723–773, 2012. URL: https://www.jmlr.org/papers/v13/gretton12a.html.
Jeffrey Ho, Yuchen Xie, and Baba Vemuri. On a nonlinear generalization of sparse coding and dictionary learning. In Proceedings of the 30th International Conference on Machine Learning, volume 28 of Proceedings of Machine Learning Research, 1480–1488. 2013. URL: https://proceedings.mlr.press/v28/ho13a.html.
Hermann Karcher. Riemannian center of mass and mollifier smoothing. Communications on Pure and Applied Mathematics, 30(5):509–541, 1977. doi:10.1002/cpa.3160300502.
Stuart P. Lloyd. Least squares quantization in PCM. IEEE Transactions on Information Theory, 28(2):129–137, 1982. doi:10.1109/TIT.1982.1056489.
Alexander Petersen and Hans-Georg Müller. Fréchet regression for random objects with Euclidean predictors. The Annals of Statistics, 47(2):691–719, 2019. doi:10.1214/17-AOS1624.
Gábor J. Székely and Maria L. Rizzo. Energy statistics: a class of statistics based on distances. Journal of Statistical Planning and Inference, 143(8):1249–1272, 2013. doi:10.1016/j.jspi.2013.03.018.
Lihi Zelnik-Manor and Pietro Perona. Self-tuning spectral clustering. In Advances in Neural Information Processing Systems, volume 17, 1601–1608. 2005.
Dengyong Zhou, Olivier Bousquet, Thomas Navin Lal, Jason Weston, and Bernhard Schölkopf. Learning with local and global consistency. In Advances in Neural Information Processing Systems, volume 16. 2003. URL: https://proceedings.neurips.cc/paper/2003/hash/87682805257e619d49b8e0dfdc14affa-Abstract.html.
Pengfei Zhu, Hao Cheng, Qinghua Hu, Qilong Wang, and Changqing Zhang. Towards generalized and efficient metric learning on Riemannian manifold. In Proceedings of the Twenty-Seventh International Joint Conference on Artificial Intelligence, 3235–3241. 2018. doi:10.24963/ijcai.2018/449.