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);
Equals previously returned always false in case of (asymmetric) accidential
zeros. Instead, Equals now expects accidential zeros and treats them
correctly (so we can allow arithmetic algorithms to generate accidential
zeros, avoiding a lot of zero checks).
Previously sparse vectors for Complex and Complex32 did override
Object.Equals instead of the generic IEquatable<Vector<T>>.Equals.
Now only overrides the generic version to ensure that the right version
is called in all code paths.
CommonParallel did break on empty loops with an argument exception instead
of just doing nothing. It now exits early if there's nothing to do in
For and Invoke, no longer throwing an exception. Also, it now special cases
single-element iterations and inlines their execution (trivial loop
unrolling), skipping all the threading/task overhead.
Change LeftMultiply to a protected method (from protected abstract) and it now
calls TransposeThisAndMultiply(). TransposeThisAndMultiply has unit tests
so it was chosen as the "main" method. Overrides of LeftMultiply were removed,
because now only TransposeThisAndMultiply() needs to be overriden.
Signed-off-by: Alexander Karatarakis <alex@karatarakis.com>
The formulas found in various references do not have abs. Furthermore,
when multiplying A*A^T or A^T*A (for the frobenius norm we only care
about the diagonal so it doesn't matter which product is used) the
i-ith diagonal element of the final matrix comes from the multiplication
of line i with itself. Therefore, all numbers involved will be multiplied
with themselves resulting in numbers that are always non-negative.
Signed-off-by: Alexander Karatarakis <alex@karatarakis.com>