Created
April 22, 2014 00:24
-
-
Save kcarnold/11161244 to your computer and use it in GitHub Desktop.
Reconstruct the actual Cholesky factor of a covariance matrix parameterized using the LKJ "onion method"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reconstruct_lkj_cholesky(ell, R2): | |
num_items = len(R2) + 1 | |
L = np.zeros((num_items, num_items)) | |
L[0, 0] = 1. | |
L[1, 0] = 2. * R2[0] - 1.0 | |
L[1, 1] = np.sqrt(1.0 - L[1, 0]) | |
start = 0 | |
for i in range(2, num_items): | |
ell_row = ell[start:start+i] | |
assert len(ell_row) == i | |
scale = np.sqrt(R2[i-1] / np.dot(ell_row, ell_row)) | |
L[i, :i] = scale * ell_row | |
L[i, i] = np.sqrt(1.0 - R2[i-1]) | |
start += i | |
return L |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment