waxmorph.jax.losses.chamfer_distance

waxmorph.jax.losses.chamfer_distance#

waxmorph.jax.losses.chamfer_distance(X_pred, X_target)[source]#

Two directional mean distances between unordered, possibly unequal clouds.

Euclidean nearest-neighbor terms provide permutation invariance and exchange symmetry:

\[\mathcal{L} = \frac{1}{N}\sum_i \min_j \lVert X^f_i - X^T_j \rVert + \frac{1}{M}\sum_j \min_i \lVert X^f_i - X^T_j \rVert\]

JAX splits a min cotangent equally among tied minima; the derivative remains nonsmooth because the tied set changes under perturbation. Coincident distances use a finite zero-gradient branch.

Raises:

ValueError – If either cloud is empty, has another rank, or has a different width.

Parameters:
Return type:

Array

Examples

>>> x = jnp.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]])
>>> y = jnp.array([[0.0, 0.0, 0.0], [2.0, 0.0, 0.0]])
>>> print(float(chamfer_distance(x, y)))
1.0