Question

I am converting a code written on Matlab to C#. In Matlab, there is a function called mvnrnd which is amultivariate normal random number generator. This requires two inputs: n x d mean matrix and d-by-d cov matrix. I googled and found math.net matrixnormal does do the same thing.

Unlike the function in Matlab, matrixnormal requires three inputs: mean matrix (M), a cov matrix for the rows (V) and a cov matrix for the columns (K). The documentation states if the dimension of M is d-by-m then V is d-by-d and K is m-by-m. I have these two inputs matrices (1x12 mean matrix and 12x12 cov matrixfor Matlab. I would like to convert these two inputs into three inputs for matrixnormal.

Mean matrix part is not a problem but I don't know how to convert cov part. I am not good at statistics. Could someone help me to do this? Thanks,

Was it helpful?

Solution

This isn't an elegant solution or anything, but I think it can work...

Why don't you create a covariance matrix by filling in the values, and then call ColumnCovariance() and RowCovariance() on it? I've never written C#, so I don't know the syntax but this should give you a general idea:

Matrix covariance = new Matrix( [some numbers]) // basically just copy the covariance values
Matrix rowCov = covariance.getRowCovariance()
Matrix colCov = covariance.getColumnCovariance()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top