Skip to content

Commit 7445b36

Browse files
committed
fix crash for near 0 covariance matrix
1 parent 9303406 commit 7445b36

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/deterministic_gaussian_sampling_fibonacci/sample_gaus.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ def _fast_cholesky_covariance_correction(samples, V, D):
4949

5050
# Fast Cholesky Covariance Correction
5151
C_stdD = 1 / L * (X_stdD.T @ X_stdD)
52-
L_stdD = np.linalg.cholesky(C_stdD)
53-
L_stdD_inv = np.linalg.inv(L_stdD)
52+
try:
53+
L_stdD = np.linalg.cholesky(C_stdD)
54+
L_stdD_inv = np.linalg.inv(L_stdD)
55+
except np.linalg.LinAlgError:
56+
# In case L_stdD non PD (for example if C is almost 0, or other numerical issues), skip the correction
57+
return samples
5458

5559
X_Gauss = V @ D @ L_stdD_inv @ X_stdD.T # (dim,dim) @ (dim,dim) @ (dim,dim) @ (dim,L) -> (dim,L)
5660
X_Gauss = X_Gauss.T # (L,dim)

0 commit comments

Comments
 (0)