linalg
matrix_inversion_dispatcher(K, method='inv')
¶
Returns the inverse of K using one of three methods: ‘inv’ -> direct numpy.linalg.inv(K), ‘chol’ -> Cholesky factorization (then forms K^-1), ‘direct’ -> Cholesky factorization with repeated solves (still forms K^-1).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
K |
ndarray
|
The matrix to invert. |
required |
method |
str
|
The inversion method to use. |
'inv'
|
Returns:
Name | Type | Description |
---|---|---|
ndarray |
ndarray
|
The inverse of K. |
Raises:
Type | Description |
---|---|
ValueError
|
If method is not ‘inv’, ‘chol’, or ‘direct’. |
Examples:
>>> import numpy as np
>>> from spotpython.utils.linalg import matrix_inversion_dispatcher
>>> K = np.array([[1.0, 0.5], [0.5, 1.0]])
>>> Ki = matrix_inversion_dispatcher(K, method="inv")
>>> print(Ki)
[[ 1.33333333 -0.66666667]
[-0.66666667 1.33333333]]
Source code in spotpython/utils/linalg.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
try_cholesky(Kmat, max_attempts=3)
¶
Attempt Cholesky on Kmat multiple times, adding jitter at each step.
Source code in spotpython/utils/linalg.py
6 7 8 9 10 11 12 13 14 15 16 17 |
|