私の知る限り、Math.net には多変量乱数正規数を与えるすぐに利用できる関数はありません。ただし、共分散行列のコレスキー分解を使用する、その目的のための特定の関数を簡単に作成できます。実際、p 変量ベクトル Z の各要素が標準正規分布 N(0,1) に従って個別に分散される場合、ベクトル X = M + L * Z は、母集団平均ベクトルが M である p 変量正規分布に従って分散され、その共分散行列は S (S = L*L') です。
私はVBの男なので、そのような関数を書くためのVBコードをここに示します:
Public Function MvNRnd(Mu As Vector, Covariance As Matrix, Cases As Double) As Matrix
Dim standardNormalDistribution As New Normal(0, 1)
Dim randomValues(Cases - 1) As Vector
Dim cholesky As Factorization.Cholesky(Of Double) = Covariance.Cholesky
For i As Integer = 0 To Cases - 1
'generate independent standard normal random numbers
randomValues(i) = DenseVector.CreateRandom(Mu.Count, standardNormalDistribution)
'generate multivariate normal random numbers
cholesky.Factor.Multiply(randomValues(i), randomValues(i))
randomValues(i) += Mu
Next
Return DenseMatrix.OfRowVectors(randomValues)
End Function
同等の C# コードは次のようになります ( http://converter.telerik.comで翻訳):
public Matrix MvNRnd(Vector Mu, Matrix Covariance, double Cases)
{
Normal standardNormalDistribution = new Normal(0, 1);
Vector[] randomValues = new Vector[Cases];
Factorization.Cholesky<double> cholesky = Covariance.Cholesky;
for (int i = 0; i <= Cases - 1; i++) {
//generate independent standard normal random numbers
randomValues(i) = DenseVector.CreateRandom(Mu.Count, standardNormalDistribution);
//generate multivariate normal random numbers
cholesky.Factor.Multiply(randomValues(i), randomValues(i));
randomValues(i) += Mu;
}
return DenseMatrix.OfRowVectors(randomValues);
}