ott.geometry.graph.Graph#
- class ott.geometry.graph.Graph(laplacian, t=0.001, n_steps=100, numerical_scheme='backward_euler', tol=-1.0, **kwargs)[source]#
Graph distance approximation using heat kernel [Crane et al., 2013, Heitz et al., 2021].
Approximates the heat kernel for large
n_steps
, which for smallt
approximates the geodesic exponential kernel \(e^{\frac{-d(x, y)^2}{t}}\).- Parameters
laplacian (
Array
) – Symmetric graph Laplacian. The check for symmetry is NOT performed. See alsofrom_graph()
.n_steps (
int
) – Maximum number of steps used to approximate the heat kernel.numerical_scheme (
Literal
['backward_euler'
,'crank_nicolson'
]) – Numerical scheme used to solve the heat diffusion.normalize – Whether to normalize the Laplacian as \(L^{sym} = \left(D^+\right)^{\frac{1}{2}} L \left(D^+\right)^{\frac{1}{2}}\), where \(L\) is the non-normalized Laplacian and \(D\) is the degree matrix.
tol (
float
) – Relative tolerance with respect to the Hilbert metric, see [Peyré and Cuturi, 2019], Remark 4.12. Used when iteratively updating scalings. If negative, this option is ignored and onlyn_steps
is used.t (
float
) –
Methods
apply_cost
(arr[, axis, fn])Apply
cost_matrix
to array (vector or matrix).apply_kernel
(scaling[, eps, axis])Apply
kernel_matrix
on positive scaling vector.apply_lse_kernel
(f, g, eps[, vec, axis])Apply
kernel_matrix
in log domain.apply_square_cost
(arr[, axis])Apply elementwise-square of cost matrix to array (vector or matrix).
apply_transport_from_potentials
(f, g, vec[, ...])Since applying from potentials is not feasible in grids, use scalings.
apply_transport_from_scalings
(u, v, vec[, axis])Apply transport matrix computed from scalings to a (batched) vec.
copy_epsilon
(other)Copy the epsilon parameters from another geometry.
from_graph
(G[, t, directed, normalize])Construct
Graph
from an adjacency matrix.marginal_from_potentials
(f, g[, axis])Not implemented.
marginal_from_scalings
(u, v[, axis])Output marginal of transportation matrix from scalings.
mask
(src_mask, tgt_mask[, mask_value])Mask rows or columns of a geometry.
potential_from_scaling
(scaling)Compute dual potential vector from scaling vector.
prepare_divergences
(*args[, static_b])Instantiate 2 (or 3) geometries to compute a Sinkhorn divergence.
scaling_from_potential
(potential)Compute scaling vector from dual potential.
set_scale_cost
(scale_cost)Modify how to rescale of the
cost_matrix
.subset
(src_ixs, tgt_ixs, **kwargs)Subset rows or columns of a geometry.
to_LRCGeometry
([rank, tol, rng, scale])Factorize the cost matrix using either SVD (full) or [Indyk et al., 2019].
Not implemented.
transport_from_scalings
(u, v)Output transport matrix from pair of scalings.
update_potential
(f, g, log_marginal[, ...])Carry out one Sinkhorn update for potentials, i.e. in log space.
update_scaling
(scaling, marginal[, ...])Carry out one Sinkhorn update for scalings, using kernel directly.
Attributes
Check quickly if casting geometry as LRC makes sense.
Cost matrix, recomputed from kernel if only kernel was specified.
Output rank of cost matrix, if any was provided.
The data type.
Epsilon regularization value.
Compute and return inverse of scaling factor for cost matrix.
Whether geometry cost/kernel should be recomputed on the fly.
Whether cost is computed by taking squared Euclidean distance.
Whether geometry cost/kernel is a symmetric matrix.
Kernel matrix.
Mean of the
cost_matrix
.Median of the
cost_matrix
.Shape of the geometry.
Mask of shape
[num_a,]
to computecost_matrix
statistics.Mask of shape
[num_b,]
to computecost_matrix
statistics.