Skip to content

Creating triangular matrices #10146

Answered by sharadmv
jatentaki asked this question in Q&A
Apr 5, 2022 · 5 comments · 4 replies
Discussion options

You must be logged in to vote

TensorFlow Probability (on JAX) has a bijector meant for this application (tfb.FillScaleTriL). It will convert a vector of unconstrained values into a PSD matrix (and it can also convert the PSD matrix back into the vector if you want).

The implementation is based on the fill_triangular function that concatenates a vector to the "tail" of itself, reshapes, then zeros out half of the matrix.

Pasted from fill_triangular's docstring:

x = np.arange(15) + 1
xc = np.concatenate([x, x[5:][::-1]])
# ==> array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 14, 13,
#            12, 11, 10, 9, 8, 7, 6])
# (We add one to the arange result to disambiguate the zeros below the
# diagonal of our…

Replies: 5 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@aldopareja
Comment options

@gil2rok
Comment options

Comment options

You must be logged in to vote
1 reply
@YouJiacheng
Comment options

Answer selected by jatentaki
Comment options

You must be logged in to vote
1 reply
@dishank-b
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants