# Sourceaggregatedsignaldistortionratio

> Compute the SourceAggregatedSignalDistortionRatio metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute SourceAggregatedSignalDistortionRatio, or asks how to score with SourceAggregatedSignalDistortionRatio.

- Skill: `qhjqhj00/sourceaggregatedsignaldistortionratio` (Agent Skill)
- Install (CLI): `npx skillmds add qhjqhj00/sourceaggregatedsignaldistortionratio`
- Raw SKILL.md: https://api.skillmd.com/api/skills/qhjqhj00/sourceaggregatedsignaldistortionratio/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: qhjqhj00 (https://skillmd.com/u/qhjqhj00)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/qhjqhj00/sourceaggregatedsignaldistortionratio

---


# sourceaggregatedsignaldistortionratio

> Metric `SourceAggregatedSignalDistortionRatio` from `torchmetrics` (torchmetrics.audio.SourceAggregatedSignalDistortionRatio)

## When to invoke this skill

The user has predictions + ground truth and asks to evaluate with SourceAggregatedSignalDistortionRatio, or
mentions `torchmetrics.audio.SourceAggregatedSignalDistortionRatio` directly, or wants the standard torchmetrics implementation.

## Reference signature

```python
from torchmetrics.audio import SourceAggregatedSignalDistortionRatio

# SourceAggregatedSignalDistortionRatio(scale_invariant: bool = True, zero_mean: bool = False, **kwargs: Any) -> None
```

## Library docstring

```
`Source-aggregated signal-to-distortion ratio`_ (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`` (:class:`~torch.Tensor`): float tensor with shape ``(..., spk, time)``
- ``target`` (:class:`~torch.Tensor`): float tensor with shape ``(..., spk, time)``

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

- ``sa_sdr`` (:class:`~torch.Tensor`): float scalar tensor with average SA-SDR value over samples

Args:
    preds: float tensor with shape ``(..., spk, time)``
    target: float tensor with shape ``(..., spk, time)``
    scale_invariant: if True, scale the targets of different speakers with the same alpha
    zero_mean: If to zero mean target and preds or not
    kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

Example:
    >>> 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)
```

## Quick recipe

```python
import torchmetrics.audio as _m
score = _m.SourceAggregatedSignalDistortionRatio(y_true, y_pred)
```

## Don'ts

- Don't reimplement when the library version handles edge cases (NaN, ties, empty inputs) better than a hand-rolled formula.
- Always check the library version's argument order — sklearn is `(y_true, y_pred)` while torchmetrics is `(preds, target)`.

