Returns a symmetric positive definite matrix given a dimension. Input: dimension gives the square matrix dimension. Output: spd_matrix is an diminesion x dimensions symmetric positive definite (SPD) matrix. >>> import numpy as np >>> dimension = 3 >>> spd_matrix =
(dimension: int)
| 46 | |
| 47 | |
| 48 | def _create_spd_matrix(dimension: int) -> Any: |
| 49 | """ |
| 50 | Returns a symmetric positive definite matrix given a dimension. |
| 51 | |
| 52 | Input: |
| 53 | dimension gives the square matrix dimension. |
| 54 | |
| 55 | Output: |
| 56 | spd_matrix is an diminesion x dimensions symmetric positive definite (SPD) matrix. |
| 57 | |
| 58 | >>> import numpy as np |
| 59 | >>> dimension = 3 |
| 60 | >>> spd_matrix = _create_spd_matrix(dimension) |
| 61 | >>> _is_matrix_spd(spd_matrix) |
| 62 | True |
| 63 | """ |
| 64 | rng = np.random.default_rng() |
| 65 | random_matrix = rng.normal(size=(dimension, dimension)) |
| 66 | spd_matrix = np.dot(random_matrix, random_matrix.T) |
| 67 | assert _is_matrix_spd(spd_matrix) |
| 68 | return spd_matrix |
| 69 | |
| 70 | |
| 71 | def conjugate_gradient( |