---
title: Source Aggregated Signal-to-Distortion Ratio (SA-SDR)
description: Source-aggregated signal-to-distortion ratio (SA-SDR).
canonical: >-
  https://lightning.ai/docs/torchmetrics/stable/audio/source_aggregated_signal_distortion_ratio
---
# Source Aggregated Signal-to-Distortion Ratio (SA-SDR) {#source-aggregated-signal-to-distortion-ratio-sa-sdr}

## Module Interface {#module-interface}

### `class torchmetrics.audio.sdr.SourceAggregatedSignalDistortionRatio(scale_invariant=True, zero_mean=False, **kwargs)` {#torchmetrics.audio.sdr.SourceAggregatedSignalDistortionRatio}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/audio/sdr.py#L282-L399)

[Source-aggregated signal-to-distortion ratio](https://arxiv.org/abs/2110.15581) (SA-SDR).

The SA-SDR is proposed to provide a stable gradient for meeting style source separation, where one-speaker and multiple-speaker scenes coexist.

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

*   `preds` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): float tensor with shape `(..., spk, time)`
    
*   `target` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): float tensor with shape `(..., spk, time)`
    

As output of forward and compute the metric returns the following output

*   `sa_sdr` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): float scalar tensor with average SA-SDR value over samples
    

Parameters:

*   **preds** – float tensor with shape `(..., spk, time)`
    
*   **target** – float tensor with shape `(..., spk, time)`
    
*   **scale\_invariant** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – if True, scale the targets of different speakers with the same alpha
    
*   **zero\_mean** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If to zero mean target and preds or not
    
*   **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.
    

Example

```python
>>> from torch import randn
>>> from torchmetrics.audio import SourceAggregatedSignalDistortionRatio
>>> preds = randn(2, 8000) # [..., spk, time]
>>> target = randn(2, 8000)
>>> sasdr = SourceAggregatedSignalDistortionRatio()
>>> sasdr(preds, target)
tensor(-50.8171)
>>> # use with pit
>>> from torchmetrics.audio import PermutationInvariantTraining
>>> from torchmetrics.functional.audio import source_aggregated_signal_distortion_ratio
>>> preds = randn(4, 2, 8000)  # [batch, spk, time]
>>> target = randn(4, 2, 8000)
>>> pit = PermutationInvariantTraining(source_aggregated_signal_distortion_ratio,
...     mode="permutation-wise", eval_func="max")
>>> pit(preds, target)
tensor(-43.9780)
```

#### `plot(val=None, ax=None)` {#torchmetrics.audio.sdr.SourceAggregatedSignalDistortionRatio.plot}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/audio/sdr.py#L361-L399)

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.audio import SourceAggregatedSignalDistortionRatio
>>> metric = SourceAggregatedSignalDistortionRatio()
>>> metric.update(torch.rand(2,8000), torch.rand(2,8000))
>>> fig_, ax_ = metric.plot()
```

[![../../\_images/source\_aggregated\_signal\_distortion\_ratio-1.png](/docs/torchmetrics/1.9.0/static/_images/source_aggregated_signal_distortion_ratio-1.png)](/docs/torchmetrics/1.9.0/static/_images/source_aggregated_signal_distortion_ratio-1.png)

```python
>>> # Example plotting multiple values
>>> import torch
>>> from torchmetrics.audio import SourceAggregatedSignalDistortionRatio
>>> metric = SourceAggregatedSignalDistortionRatio()
>>> values = [ ]
>>> for _ in range(10):
...     values.append(metric(torch.rand(2,8000), torch.rand(2,8000)))
>>> fig_, ax_ = metric.plot(values)
```

[![../../\_images/source\_aggregated\_signal\_distortion\_ratio-2.png](/docs/torchmetrics/1.9.0/static/_images/source_aggregated_signal_distortion_ratio-2.png)](/docs/torchmetrics/1.9.0/static/_images/source_aggregated_signal_distortion_ratio-2.png)

## Functional Interface {#functional-interface}

### `torchmetrics.functional.audio.sdr.source_aggregated_signal_distortion_ratio(preds, target, scale_invariant=True, zero_mean=False)` {#torchmetrics.functional.audio.sdr.source_aggregated_signal_distortion_ratio}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/audio/sdr.py#L241-L303)

[Source-aggregated signal-to-distortion ratio](https://arxiv.org/abs/2110.15581) (SA-SDR).

The SA-SDR is proposed to provide a stable gradient for meeting style source separation, where one-speaker and multiple-speaker scenes coexist.

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – float tensor with shape `(..., spk, time)`
    
*   **target** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – float tensor with shape `(..., spk, time)`
    
*   **scale\_invariant** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – if True, scale the targets of different speakers with the same alpha
    
*   **zero\_mean** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If to zero mean target and preds or not
    

Return type:

[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")

Returns:

SA-SDR with shape `(...)`

Example

```python
>>> from torch import randn
>>> from torchmetrics.functional.audio import source_aggregated_signal_distortion_ratio
>>> preds = randn(2, 8000)  # [..., spk, time]
>>> target = randn(2, 8000)
>>> source_aggregated_signal_distortion_ratio(preds, target)
tensor(-50.8171)
>>> # use with permutation_invariant_training
>>> from torchmetrics.functional.audio import permutation_invariant_training
>>> preds = randn(4, 2, 8000)  # [batch, spk, time]
>>> target = randn(4, 2, 8000)
>>> best_metric, best_perm = permutation_invariant_training(preds, target,
...     source_aggregated_signal_distortion_ratio, mode="permutation-wise")
>>> best_metric
tensor([-42.6290, -44.3500, -34.7503, -54.1828])
>>> best_perm
tensor([[0, 1],
        [1, 0],
        [0, 1],
        [1, 0]])
```

---

**Navigation**

- Parent: [Audio](/docs/torchmetrics/1.9.0/audio.md)
