2

math.net ライブラリを使用して C# で以下の matlab 関数を実装するにはどうすればよいですか。

多変量正規ランダム分布- http://in.mathworks.com/help/stats/mvnrnd.html

r = mvnrnd(MU,SIGMA,cases)

また、結果を返さないmath.net関数の下。Selectpermutations/SelectVariations のような他の方法を試しましたが、繰り返しあり/なしで実行しましたが、いずれの方法も結果を返しません。

IEnumerable<double> input=new double[] { 1, 2, 3, 4, 5 };
var re = input.SelectCombinationWithRepetition(3);

ここに画像の説明を入力

私は何かが欠けていますか??

4

2 に答える 2

1
Random randomSource = new SystemRandomSource();

var mu = new DenseMatrix(2, 1, new[] { 2.0, 3 });
var sigma = new DenseMatrix(2, 2, new[] { 1, 1.5, 1.5, 3 });
var one = DenseMatrix.CreateIdentity(1);

var mvnrnd = new MatrixNormal(mu, sigma, one, randomSource);
var sample = mvnrnd.Sample();
于 2016-03-10T19:41:00.033 に答える
1

私の知る限り、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);

}
于 2015-09-23T16:51:33.440 に答える