pyFDN.Match#
- class pyFDN.Match(target, feature, distance=<pyFDN.train.losses.distances.SquaredError object>, reduction=<pyFDN.train.losses.reductions.Mean object>)[source]#
Compares a model’s impulse response to a target using three steps:
1. Feature: Extracts representations from both the model response and the target (e.g., raw waveform, magnitude spectrum, or phase). 2. Distance: Computes the differences between the extracted features (e.g., squared error or circular phase difference). 3. Reduction: Aggregates the elementwise differences into a scalar loss tensor (e.g., mean or sum).
The reference target is aligned in length, shape, device, and dtype using
_CachedTarget, and its feature is computed once and cached until the loss is called on a response of a different shape, device, dtype or sample rate.Without a target (
target=None) the distance is called with an all-zeros tensor in place of the reference feature; targetless losses use a distance that compares against a constant of its own and ignores it.- Parameters:
target (
Any|None) – Reference impulse response (NumPy array, PyTorch tensor, or list), or None.feature (
Feature|Callable[[Tensor,float],Tensor]) – Extracts the representation to compare:(h, fs) -> torch.Tensor.distance (
Distance|Callable[[Tensor,Tensor],Tensor]) – Calculates error between two features:(pred, target) -> torch.Tensor.reduction (
Reduction|Callable[[Tensor],Tensor]) – Turns the error tensor into a single scalar:(diff) -> torch.Tensor.
- __init__(target, feature, distance=<pyFDN.train.losses.distances.SquaredError object>, reduction=<pyFDN.train.losses.reductions.Mean object>)[source]#
Methods
__init__(target, feature[, distance, reduction])check(model)Preflight against the model it will train, before the first step.
terms()Flatten into
(weight, loss)leaves.Attributes
nameShort label, used as the key in
pyFDN.TrainLog.loss_log.