Skip to content

Commit

Permalink
remove unused function _nearest_positive_definite()
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyod committed Nov 29, 2024
1 parent 2c3ef8a commit 8288511
Showing 1 changed file with 0 additions and 29 deletions.
29 changes: 0 additions & 29 deletions src/semeio/fmudesign/create_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,6 @@ def _is_positive_definite(b_mat):
return False


def _nearest_positive_definite(a_mat):
"""Implementation taken from:
https://stackoverflow.com/questions/43238173/
python-convert-matrix-to-positive-semi-definite/43244194#43244194
"""

b_mat = (a_mat + a_mat.T) / 2
_, s_mat, v_mat = la.svd(b_mat)

h_mat = np.dot(v_mat.T, np.dot(np.diag(s_mat), v_mat))

a2_mat = (b_mat + h_mat) / 2

a3_mat = (a2_mat + a2_mat.T) / 2

if _is_positive_definite(a3_mat):
return a3_mat

spacing = np.spacing(la.norm(a_mat))
identity = np.eye(a_mat.shape[0])
kiter = 1
while not _is_positive_definite(a3_mat):
mineig = np.min(np.real(la.eigvals(a3_mat)))
a3_mat += identity * (-mineig * kiter**2 + spacing)
kiter += 1

return a3_mat


def nearest_correlation_matrix(matrix, *, weights=None, eps=1e-6, verbose=False):
"""Returns the correlation matrix nearest to `matrix`, weighted elementwise
by `weights`.
Expand Down

0 comments on commit 8288511

Please sign in to comment.