From dba338d6cdb9faca85d44d329de418235bbcac4c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 14 Feb 2025 01:31:52 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- hera_filters/dspec.py | 12 ++++++------ hera_filters/tests/test_dspec.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hera_filters/dspec.py b/hera_filters/dspec.py index 4758c04..8b26e64 100644 --- a/hera_filters/dspec.py +++ b/hera_filters/dspec.py @@ -2933,11 +2933,11 @@ def sparse_linear_fit_2D( If True, the solver will apply a preconditioner to the basis matrices before solving the least-squares problem. This option is useful when the input weights are frequency or time dependent and are either very large or very small, or when - the basis matrices are ill-conditioned due to large stretches of zeros. - The preconditioner is computed using the the inverse of the regularized Gramian - matrix of the basis matrices. Prior computing the inverse, the eigenvalues of the - Gramian matrix are regularized by adding a small value proportional to the smallest - eigenvalue. This helps to stabilize the computation of the inverse. The regularization + the basis matrices are ill-conditioned due to large stretches of zeros. + The preconditioner is computed using the the inverse of the regularized Gramian + matrix of the basis matrices. Prior computing the inverse, the eigenvalues of the + Gramian matrix are regularized by adding a small value proportional to the smallest + eigenvalue. This helps to stabilize the computation of the inverse. The regularization factor is computed as the minimum eigenvalue of the Gramian matrix multiplied by the `eig_scaling_factor` parameter. eig_scaling_factor : float, optional, default 1e-1 @@ -2994,7 +2994,7 @@ def sparse_linear_fit_2D( axis_1_pcond = np.linalg.pinv( XTX_axis_1 + np.eye(XTX_axis_1.shape[0]) * axis_1_lambda ) - + # Compute the preconditioner for the second axis XTX_axis_2 = np.dot(axis_2_basis.T.conj() * axis_2_wgts, axis_2_basis) eigenval, _ = np.linalg.eig(XTX_axis_2) diff --git a/hera_filters/tests/test_dspec.py b/hera_filters/tests/test_dspec.py index 4efa554..7c3c0a7 100644 --- a/hera_filters/tests/test_dspec.py +++ b/hera_filters/tests/test_dspec.py @@ -1557,7 +1557,7 @@ def test_precondition_sparse_solver(): axis_1_weights = (~time_flags[:, 0]).astype(float) * rng.integers(1, 10, size=(ntimes,)) axis_2_weights = (~freq_flags[0]).astype(float) wgts = np.outer(axis_1_weights, axis_2_weights) - + # Add frequency dependence to the weights to make the problem more ill-conditioned wgts *= (freqs / 150e6) ** -3.5 @@ -1589,4 +1589,4 @@ def test_precondition_sparse_solver(): # Check that the fit closely matches to the separable fit np.testing.assert_allclose(sol, sol_sparse, atol=1e-8, rtol=1e-6) np.testing.assert_allclose(sol, sol_sparse_precond, atol=1e-8, rtol=1e-6) - np.testing.assert_array_less(meta_precond['iter_num'], meta['iter_num']) \ No newline at end of file + np.testing.assert_array_less(meta_precond['iter_num'], meta['iter_num'])