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.
Installs into .claude/skills of the current project.
Are you the author of Sourceaggregatedsignaldistortionratio?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/qhjqhj00-sourceaggregatedsignaldistortionratio)
---
name: sourceaggregatedsignaldistortionratio
description: 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.
metadata:
skill_kind: metric
source_lib: torchmetrics
import_path: torchmetrics.audio.SourceAggregatedSignalDistortionRatio
source: library_introspection
---
# 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)`.