Implement three tools from Murphy's book that avoid large inversions.
woodbury_solve(sigma_diag, X, B): return where with all , sigma_diag has shape (N,), X has shape (N, D) and B has shape (N,) or (N, K) (return the same shape as B). Use the matrix inversion lemma
so that the only linear system you solve is . Never form an matrix: tests use in the tens of thousands.
sherman_morrison(A_inv, u, v): given (shape (n, n)) and vectors u, v, return by the Sherman-Morrison formula in work. If the update is singular: raise ValueError.
logdet_rank_one_update(logdet_A, A_inv, u, v): given and , return as a float using the matrix determinant lemma . Assume ; raise ValueError if (the updated determinant is not positive).