예제 #1
0
        public void CanCreateMatrixNormal(int n, int p)
        {
            var matrixM = Matrix<double>.Build.Random(n, p, 1);
            var matrixV = Matrix<double>.Build.RandomPositiveDefinite(n, 1);
            var matrixK = Matrix<double>.Build.RandomPositiveDefinite(p, 1);
            var d = new MatrixNormal(matrixM, matrixV, matrixK);

            for (var i = 0; i < matrixM.RowCount; i++)
            {
                for (var j = 0; j < matrixM.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixM[i, j], d.Mean[i, j]);
                }
            }

            for (var i = 0; i < matrixV.RowCount; i++)
            {
                for (var j = 0; j < matrixV.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixV[i, j], d.RowCovariance[i, j]);
                }
            }

            for (var i = 0; i < matrixK.RowCount; i++)
            {
                for (var j = 0; j < matrixK.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixK[i, j], d.ColumnCovariance[i, j]);
                }
            }
        }
예제 #2
0
 public void CanSample(int n, int p)
 {
     var d = new MatrixNormal(Matrix<double>.Build.Random(n, p, 1), Matrix<double>.Build.RandomPositiveDefinite(n, 1), Matrix<double>.Build.RandomPositiveDefinite(p, 1));
     d.Sample();
 }
예제 #3
0
        public void ValidateDensity()
        {
            const int Rows = 2;
            const int Cols = 2;
            var m = Matrix<double>.Build.Dense(Rows, Cols);
            m[0, 0] = 0.156065579983862;
            m[0, 1] = -0.568039841576594;
            m[1, 0] = -0.806288628097313;
            m[1, 1] = -1.20004405005077;

            var v = Matrix<double>.Build.Dense(Rows, Rows);
            v[0, 0] = 0.674457817054746;
            v[0, 1] = 0.878930403442185;
            v[1, 0] = 0.878930403442185;
            v[1, 1] = 1.76277498368061;

            var k = Matrix<double>.Build.Dense(Cols, Cols);
            k[0, 0] = 0.674457817054746;
            k[0, 1] = 0.878930403442185;
            k[1, 0] = 0.878930403442185;
            k[1, 1] = 1.76277498368061;

            var d = new MatrixNormal(m, v, k);

            var x = Matrix<double>.Build.Dense(Rows, Cols);
            x[0, 0] = 2;
            x[0, 1] = 2;

            AssertHelpers.AlmostEqualRelative(0.00015682927366491211, d.Density(x), 16);
        }
예제 #4
0
        public void ValidateNonsquareDensity()
        {
            const int Rows = 2;
            const int Cols = 1;
            var m = Matrix<double>.Build.Dense(Rows, Cols);
            m[0, 0] = 0.156065579983862;
            m[1, 0] = -0.806288628097313;

            var v = Matrix<double>.Build.Dense(Rows, Rows);
            v[0, 0] = 0.674457817054746;
            v[0, 1] = 0.878930403442185;
            v[1, 0] = 0.878930403442185;
            v[1, 1] = 1.76277498368061;

            var k = Matrix<double>.Build.Dense(Cols, Cols);
            k[0, 0] = 0.674457817054746;

            var d = new MatrixNormal(m, v, k);

            var x = Matrix<double>.Build.Dense(Rows, Cols);
            x[0, 0] = 2;
            x[1, 0] = 1.5;

            AssertHelpers.AlmostEqualRelative(0.008613384131384546, d.Density(x), 12);
        }
예제 #5
0
 public void CanGetK(int n, int p)
 {
     var matrixK = Matrix<double>.Build.RandomPositiveDefinite(p, 1);
     var d = new MatrixNormal(Matrix<double>.Build.Random(n, p, 1), Matrix<double>.Build.RandomPositiveDefinite(n, 1), matrixK);
     for (var i = 0; i < matrixK.RowCount; i++)
     {
         for (var j = 0; j < matrixK.ColumnCount; j++)
         {
             Assert.AreEqual(matrixK[i, j], d.ColumnCovariance[i, j]);
         }
     }
 }
예제 #6
0
 public void CanGetM(int n, int p)
 {
     var matrixM = Matrix<double>.Build.Random(n, p, 1);
     var d = new MatrixNormal(matrixM, Matrix<double>.Build.RandomPositiveDefinite(n, 1), Matrix<double>.Build.RandomPositiveDefinite(p, 1));
     for (var i = 0; i < matrixM.RowCount; i++)
     {
         for (var j = 0; j < matrixM.ColumnCount; j++)
         {
             Assert.AreEqual(matrixM[i, j], d.Mean[i, j]);
         }
     }
 }
예제 #7
0
 public void ValidateToString()
 {
     const int N = 2;
     const int P = 5;
     var d = new MatrixNormal(Matrix<double>.Build.Random(N, P, 1), Matrix<double>.Build.RandomPositiveDefinite(N, 1), Matrix<double>.Build.RandomPositiveDefinite(P, 1));
     Assert.AreEqual("MatrixNormal(Rows = 2, Columns = 5)", d.ToString());
 }
예제 #8
0
 public void HasRandomSourceEvenAfterSetToNull()
 {
     const int N = 2;
     const int P = 3;
     var d = new MatrixNormal(Matrix<double>.Build.Random(N, P, 1), Matrix<double>.Build.RandomPositiveDefinite(N, 1), Matrix<double>.Build.RandomPositiveDefinite(P, 1));
     Assert.DoesNotThrow(() => d.RandomSource = null);
     Assert.IsNotNull(d.RandomSource);
 }
예제 #9
0
 public void HasRandomSource()
 {
     const int N = 2;
     const int P = 3;
     var d = new MatrixNormal(Matrix<double>.Build.Random(N, P, 1), Matrix<double>.Build.RandomPositiveDefinite(N, 1), Matrix<double>.Build.RandomPositiveDefinite(P, 1));
     Assert.IsNotNull(d.RandomSource);
 }