Skip to content

Commit 61c5fdb

Browse files
committed
[WIP] Towards using the gradient of the cond number as marker of conflictive points
1 parent b6044cb commit 61c5fdb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

gempy_engine/modules/solver/solver_interface.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ def kernel_reduction(cov, b, kernel_options: KernelOptions, n_faults: int = 0) -
2424
match (BackendTensor.engine_backend, BackendTensor.pykeops_enabled, solver):
2525
case (AvailableBackends.PYTORCH, False, _):
2626
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+
2732
case (AvailableBackends.PYTORCH, True, _):
2833
raise NotImplementedError('Pykeops is not implemented for pytorch yet')
2934
case (AvailableBackends.tensorflow, True, _):
@@ -89,8 +94,18 @@ def _compute_conditional_number(cov):
8994
eigvals = np.linalg.eigvals(cov)
9095
is_positive_definite = np.all(eigvals > 0)
9196
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
92101
if not is_positive_definite: # ! Careful numpy False
93102
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()
94109

95110

96111

0 commit comments

Comments
 (0)