From e25ca7495535ccf08c479123494b6c1f871256c0 Mon Sep 17 00:00:00 2001 From: Daniel Povey Date: Tue, 26 Jul 2022 13:40:57 +0800 Subject: [PATCH] Use a measure of correlation for eigs that can be negative. --- icefall/diagnostics.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/icefall/diagnostics.py b/icefall/diagnostics.py index ba56a2425..445500206 100644 --- a/icefall/diagnostics.py +++ b/icefall/diagnostics.py @@ -324,7 +324,11 @@ class TensorDiagnostic(object): if stats.ndim == 2: # Matrices, for purposes of measuring eigenvalues. Just compute a dot-product-related - # measure of correlation. + # measure of correlation of eigenvalues. + def norm_diag_mean(x): + return x - torch.eye(x.shape[0], dtype=x.dtype, device=x.device) * x.diag().mean() + stats = norm_diag_mean(stats) + other_stats = norm_diag_mean(other_stats) correlation = ((stats * other_stats).sum() / ((stats**2).sum() * (other_stats**2).sum() + 1.0e-20).sqrt()) else: