Procrustes Disparity

Module Interface

class torchmetrics.shape.ProcrustesDisparity(reduction='mean', **kwargs)[source]

Compute the Procrustes Disparity.

The Procrustes Disparity is defined as the sum of the squared differences between two datasets after applying a Procrustes transformation. The Procrustes Disparity is useful to compare two datasets that are similar but not aligned.

The metric works similar to scipy.spatial.procrustes but for batches of data points. The disparity is aggregated over the batch, thus to get the individual disparities please use the functional version of this metric: torchmetrics.functional.shape.procrustes.procrustes_disparity.

As input to forward and update the metric accepts the following input:

  • point_cloud1 (torch.Tensor): A tensor of shape (N, M, D) with N being the batch size, M the number of data points and D the dimensionality of the data points.

  • point_cloud2 (torch.Tensor): A tensor of shape (N, M, D) with N being the batch size, M the number of data points and D the dimensionality of the data points.

As output to forward and compute the metric returns the following output:

  • gds (Tensor): A scalar tensor with the Procrustes Disparity.

Parameters:
  • reduction (Literal['mean', 'sum']) – Determines whether to return the mean disparity or the sum of the disparities. Can be one of "mean" or "sum".

  • kwargs (Any) – Additional keyword arguments, see Advanced metric settings for more info.

Raises:

ValueError – If average is not one of "mean" or "sum".

Example

>>> from torch import randn
>>> from torchmetrics.shape import ProcrustesDisparity
>>> metric = ProcrustesDisparity()
>>> point_cloud1 = randn(10, 50, 2)
>>> point_cloud2 = randn(10, 50, 2)
>>> metric(point_cloud1, point_cloud2)
tensor(0.9770)
plot(val=None, ax=None)[source]

Plot a single or multiple values from the metric.

Parameters:
  • val (Union[Tensor, Sequence[Tensor], None]) – Either a single result from calling metric.forward or metric.compute or a list of these results. If no value is provided, will automatically call metric.compute and plot that result.

  • ax (Optional[Axes]) – An matplotlib axis object. If provided will add plot to that axis

Return type:

Tuple[Figure, Union[Axes, ndarray]]

Returns:

Figure and Axes object

Raises:

ModuleNotFoundError – If matplotlib is not installed

>>> # Example plotting a single value
>>> import torch
>>> from torchmetrics.shape import ProcrustesDisparity
>>> metric = ProcrustesDisparity()
>>> metric.update(torch.randn(10, 50, 2), torch.randn(10, 50, 2))
>>> fig_, ax_ = metric.plot()
../_images/procrustes-1.png
>>> # Example plotting multiple values
>>> import torch
>>> from torchmetrics.shape import ProcrustesDisparity
>>> metric = ProcrustesDisparity()
>>> values = [ ]
>>> for _ in range(10):
...     values.append(metric(torch.randn(10, 50, 2), torch.randn(10, 50, 2)))
>>> fig_, ax_ = metric.plot(values)
../_images/procrustes-2.png

Functional Interface

torchmetrics.functional.shape.procrustes_disparity(point_cloud1, point_cloud2, return_all=False)[source]

Runs procrustrus analysis on a batch of data points.

Works similar scipy.spatial.procrustes but for batches of data points.

Parameters:
  • point_cloud1 (Tensor) – The first set of data points

  • point_cloud2 (Tensor) – The second set of data points

  • return_all (bool) – If True, returns the scale and rotation matrices along with the disparity

Return type:

Union[Tensor, Tuple[Tensor, Tensor, Tensor]]