MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / _create_spd_matrix

Function _create_spd_matrix

linear_algebra/src/conjugate_gradient.py:48–68  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

46
47
48def _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
71def conjugate_gradient(

Callers 1

test_conjugate_gradientFunction · 0.85

Calls 1

_is_matrix_spdFunction · 0.85

Tested by 1

test_conjugate_gradientFunction · 0.68