---
title: Procrustes Disparity
description: Compute the Procrustes Disparity.
canonical: 'https://lightning.ai/docs/torchmetrics/stable/shape/procrustes'
---
# Procrustes Disparity {#procrustes-disparity}

## Module Interface {#module-interface}

### `class torchmetrics.shape.ProcrustesDisparity(reduction='mean', **kwargs)` {#torchmetrics.shape.ProcrustesDisparity}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/shape/procrustes.py#L30-L138)

Compute the [Procrustes Disparity](https://en.wikipedia.org/wiki/Procrustes_analysis).

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`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): A scalar tensor with the Procrustes Disparity.
    

Parameters:

*   **reduction** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'mean'`, `'sum'`\]) – Determines whether to return the mean disparity or the sum of the disparities. Can be one of `"mean"` or `"sum"`.
    
*   **kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Additional keyword arguments, see [Advanced metric settings](/docs/torchmetrics/1.9.0/user-guide/overview.md#metric-kwargs) for more info.
    

Raises:

[**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If `average` is not one of `"mean"` or `"sum"`.

Example

```python
>>> 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)` {#torchmetrics.shape.ProcrustesDisparity.plot}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/shape/procrustes.py#L100-L138)

Plot a single or multiple values from the metric.

Parameters:

*   **val** (`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\], [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – 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`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)")\]) – An matplotlib axis object. If provided will add plot to that axis
    

Return type:

[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[[`Figure`](https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure "(in Matplotlib v3.11.2)"), `Union`\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)"), [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.5)")\]\]

Returns:

Figure and Axes object

Raises:

[**ModuleNotFoundError**](https://docs.python.org/3/builtins/exceptions.html#ModuleNotFoundError "(in Python v3.15)") – If matplotlib is not installed

```python
>>> # 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](/docs/torchmetrics/1.9.0/static/_images/procrustes-1.png)](/docs/torchmetrics/1.9.0/static/_images/procrustes-1.png)

```python
>>> # 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](/docs/torchmetrics/1.9.0/static/_images/procrustes-2.png)](/docs/torchmetrics/1.9.0/static/_images/procrustes-2.png)

## Functional Interface {#functional-interface}

### `torchmetrics.functional.shape.procrustes_disparity(point_cloud1, point_cloud2, return_all=False)` {#torchmetrics.functional.shape.procrustes_disparity}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/shape/procrustes.py#L23-L66)

Runs procrustrus analysis on a batch of data points.

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

Parameters:

*   **point\_cloud1** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – The first set of data points
    
*   **point\_cloud2** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – The second set of data points
    
*   **return\_all** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If True, returns the scale and rotation matrices along with the disparity
    

Return type:

`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\]\]

---

**Navigation**

- Parent: [Shape](/docs/torchmetrics/1.9.0/shape.md)
