torchnmf.metrics
- torchnmf.metrics.beta_div(input, target, beta=2)[source]
The β-divergence loss measure
The loss can be described as:
\[\ell(x, y) = \sum_{n = 0}^{N - 1} \frac{1}{\beta (\beta - 1)}\left ( x_n^{\beta} + \left (\beta - 1 \right ) y_n^{\beta} - \beta x_n y_n^{\beta-1}\right )\]- Parameters
input (Tensor) – tensor of arbitrary shape
target (Tensor) – tensor of the same shape as input
beta (float) – a real value control the shape of loss function
- Returns
single element tensor
- Return type
Tensor
- torchnmf.metrics.euclidean(input, target)[source]
The Euclidean distance, which equal to β-divergence loss when β = 2.
\[\ell(x, y) = \frac{1}{2} \sum_{n = 0}^{N - 1} (x_n - y_n)^2\]- Parameters
input (Tensor) – tensor of arbitrary shape
target (Tensor) – tensor of the same shape as input
- Returns
single element tensor
- Return type
Tensor
- torchnmf.metrics.is_div(input, target)[source]
The Itakura–Saito divergence, which equal to β-divergence loss when β = 0.
\[\ell(x, y) = \sum_{n = 0}^{N - 1} \frac{x_n}{y_n} - log(\frac{x_n}{y_n}) - 1\]- Parameters
input (Tensor) – tensor of arbitrary shape
target (Tensor) – tensor of the same shape as input
- Returns
single element tensor
- Return type
Tensor
- torchnmf.metrics.kl_div(input, target)[source]
The generalized Kullback-Leibler divergence Loss, which equal to β-divergence loss when β = 1.
The loss can be described as:
\[\ell(x, y) = \sum_{n = 0}^{N - 1} x_n log(\frac{x_n}{y_n}) - x_n + y_n\]- Parameters
input (Tensor) – tensor of arbitrary shape
target (Tensor) – tensor of the same shape as input
- Returns
single element tensor
- Return type
Tensor
- torchnmf.metrics.sparseness(x)[source]
The sparseness measure proposed in Non-negative Matrix Factorization with Sparseness Constraints, can be caculated as:
\[f(x) = \frac{\sqrt{N} - \frac{\sum_{n=0}^{N-1} |x_n|}{\sqrt{\sum_{n=0}^{N-1} x_n^2}}}{\sqrt{N} - 1}\]- Parameters
x (Tensor) – tensor of arbitrary shape
- Returns
single element tensor with value range between 0 (the most sparse) to 1 (the most dense)
- Return type
Tensor