@@ -24,6 +24,11 @@ def kernel_reduction(cov, b, kernel_options: KernelOptions, n_faults: int = 0) -
24
24
match (BackendTensor .engine_backend , BackendTensor .pykeops_enabled , solver ):
25
25
case (AvailableBackends .PYTORCH , False , _):
26
26
w = bt .t .linalg .solve (cov , b )
27
+
28
+ cond_number = bt .t .linalg .cond (cov )
29
+ print (f'Condition number: { cond_number } .' )
30
+ cond_number .backward ()
31
+
27
32
case (AvailableBackends .PYTORCH , True , _):
28
33
raise NotImplementedError ('Pykeops is not implemented for pytorch yet' )
29
34
case (AvailableBackends .tensorflow , True , _):
@@ -89,8 +94,18 @@ def _compute_conditional_number(cov):
89
94
eigvals = np .linalg .eigvals (cov )
90
95
is_positive_definite = np .all (eigvals > 0 )
91
96
print (f'Condition number: { cond_number } . Is positive definite: { is_positive_definite } ' )
97
+
98
+ idx = np .where (eigvals > 800 )
99
+ print (idx )
100
+ import matplotlib .pyplot as plt
92
101
if not is_positive_definite : # ! Careful numpy False
93
102
warnings .warn ('The covariance matrix is not positive definite' )
103
+ # Plotting the histogram
104
+ plt .hist (eigvals , bins = 50 , color = 'blue' , alpha = 0.7 , log = True )
105
+ plt .xlabel ('Eigenvalue' )
106
+ plt .ylabel ('Frequency' )
107
+ plt .title ('Histogram of Eigenvalues' )
108
+ plt .show ()
94
109
95
110
96
111
0 commit comments