Computing covarince matrix from batches of cholesky upper matrices

I have a batch of upper triangular matrix of shape (B, N, N) and I want to calculate a batch of positive definite matrices (covariance matrix) using cholesky decomposition such that each matrix in resultant batch comes from corresponding upper triangular matrix in the given batch of upper triangular matrices.

Hi Bhavya!

Let me say what I think your problem is:

You have a batch (batch-size B) of NxN upper triangular matrices
that are stored as full NxN matrices, for which the elements in
the lower triangle are zero.

We think of these matrices as having come from the Cholesky
decomposition of symmetric-positive-definite (SPD) matrices,
and you wish to recover those SPD matrices as explicit, full
NxN matrices.

Let S be the desired full SPD matrix, and L be its upper-triangular
Cholesky decomposition. Then, by definition, S = L x L-transpose.

torch.matmul() does matrix multiplication on a batch basis, and you
can use torch.transpose() to perform matrix transposition on a batch
basis by specifying the dimensions to swap.

So, letting l be your (B, N, N) batch of upper-triangular matrices,
s = torch.matmul (l, torch.transpose (l, 1, 2))
should give you s, the (B, N, N) batch of your SPD matrices.

Good luck.

K. Frank

2 Likes

This is perfectly what I was looking for !!
Thanks K. Frank !!