mathnet/mathnet-numerics — pull request #33 by seahearman (2012-04-06 15:26:26+00:00)
Title: NormalMatrix.cs update from sample()

I want to sample a vector from a multivariate normal distribution. According to the Help file, I should use the method Sample(), but I found out that I can only sample a square matrix from this method, that is when I use the following code:

var NRow = 3;
var NCol = 3;
var m = new DenseMatrix(NRow, NCol);
var v = new DenseMatrix(NRow);
for (var i = 0; i < NRow; i++)
{
v[i, i] = 1;
}
var k = new DenseMatrix(NCol);
for (var i = 0; i < NCol; i++)
{
k[i, i] = 1;
}
var NewMatrix = new MatrixNormal(m, v, k);
var Sampleone = NewMatrix.Sample();

It is fine, but when I change NRow=4, (but keep NCol=3) it does not work. I checked the code, I think the problem is in MatrixNormal.cs Line 286:

var vector = SampleVectorNormal(rnd, new DenseVector(n * n, 0.0), vki);

but I think it should be:

var vector = SampleVectorNormal(rnd, new DenseVector(n * p, 0.0), vki);