Esempio n. 1
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);
        }
        public void CanCreateMatrixNormal(int n, int p)
        {
            var          M = MatrixLoader.GenerateRandomDenseMatrix(n, p);
            var          V = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n);
            var          K = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p);
            MatrixNormal d = new MatrixNormal(M, V, K);

            for (int i = 0; i < M.RowCount; i++)
            {
                for (int j = 0; j < M.ColumnCount; j++)
                {
                    Assert.AreEqual <double>(M[i, j], d.Mean[i, j]);
                }
            }

            for (int i = 0; i < V.RowCount; i++)
            {
                for (int j = 0; j < V.ColumnCount; j++)
                {
                    Assert.AreEqual <double>(V[i, j], d.RowCovariance[i, j]);
                }
            }

            for (int i = 0; i < K.RowCount; i++)
            {
                for (int j = 0; j < K.ColumnCount; j++)
                {
                    Assert.AreEqual <double>(K[i, j], d.ColumnCovariance[i, j]);
                }
            }
        }
        public void CanCreateMatrixNormal(int n ,int p)
        {
            var M = MatrixLoader.GenerateRandomDenseMatrix(n, p);
            var V = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n);
            var K = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p);
            MatrixNormal d = new MatrixNormal(M, V, K);

            for (int i = 0; i < M.RowCount; i++)
            {
                for (int j = 0; j < M.ColumnCount; j++)
                {
                    Assert.AreEqual<double>(M[i, j], d.Mean[i, j]);
                }
            }

            for (int i = 0; i < V.RowCount; i++)
            {
                for (int j = 0; j < V.ColumnCount; j++)
                {
                    Assert.AreEqual<double>(V[i, j], d.RowCovariance[i, j]);
                }
            }

            for (int i = 0; i < K.RowCount; i++)
            {
                for (int j = 0; j < K.ColumnCount; j++)
                {
                    Assert.AreEqual<double>(K[i, j], d.ColumnCovariance[i, j]);
                }
            }
        }
        public void ValidateDensity()
        {
            int rows = 2;
            int cols = 2;
            var M    = new DenseMatrix(rows, cols);

            M[0, 0] = 0.156065579983862;
            M[0, 1] = -0.568039841576594;
            M[1, 0] = -0.806288628097313;
            M[1, 1] = -1.20004405005077;

            var V = new DenseMatrix(rows, rows);

            V[0, 0] = 0.674457817054746;
            V[0, 1] = 0.878930403442185;
            V[1, 0] = 0.878930403442185;
            V[1, 1] = 1.76277498368061;

            var K = new DenseMatrix(cols, cols);

            K[0, 0] = 0.674457817054746;
            K[0, 1] = 0.878930403442185;
            K[1, 0] = 0.878930403442185;
            K[1, 1] = 1.76277498368061;
            MatrixNormal d = new MatrixNormal(M, V, K);

            var X = new DenseMatrix(rows, cols);

            X[0, 0] = 2;
            X[0, 1] = 2;

            AssertHelpers.AlmostEqual(0.00015682927366491211, d.Density(X), 16);
        }
 public MultiVariateNormalPrimitive(double[] mean, Matrix <double> covariance, Random gen)
 {
     Mean       = mean;
     Covariance = covariance;
     Gen        = gen;
     mvn        = MultiVariateNormalPrimitive.CreateMultivariateNormal(mean, covariance);
 }
        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);
        }
        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]);
                }
            }
        }
        public void CanCreateMatrixNormal(int n, int p)
        {
            var matrixM = MatrixLoader.GenerateRandomDenseMatrix(n, p);
            var matrixV = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n);
            var matrixK = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p);
            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]);
                }
            }
        }
        public void CanCreateMatrixNormal(int n, int p)
        {
            var matrixM = MatrixLoader.GenerateRandomDenseMatrix(n, p);
            var matrixV = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n);
            var matrixK = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p);
            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]);
                }
            }
        }
        public void FailCreateMatrixNormal(int mRows, int mCols, int vRows, int vCols, int kRows, int kCols)
        {
            var M = MatrixLoader.GenerateRandomDenseMatrix(mRows, mCols);
            var V = MatrixLoader.GenerateRandomDenseMatrix(vRows, vCols);
            var K = MatrixLoader.GenerateRandomDenseMatrix(kRows, kCols);

            MatrixNormal d = new MatrixNormal(M, V, K);
        }
        public void ValidateToString()
        {
            int n = 2;
            int p = 5;
            var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));

            Assert.AreEqual <string>("MatrixNormal(Rows = 2, Columns = 5)", d.ToString());
        }
        public void FailSetRandomSourceWithNullReference()
        {
            int n = 2;
            int p = 3;
            var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));

            d.RandomSource = null;
        }
        public void CanSetRandomSource()
        {
            int n = 2;
            int p = 3;
            var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));

            d.RandomSource = new Random();
        }
        public void HasRandomSource()
        {
            int n = 2;
            int p = 3;
            var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));

            Assert.IsNotNull(d.RandomSource);
        }
Esempio n. 15
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);
        }
Esempio n. 16
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());
        }
Esempio n. 17
0
        public void ValidateToString()
        {
            const int N = 2;
            const int P = 5;
            var       d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(N, P), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(N), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(P));

            Assert.AreEqual("MatrixNormal(Rows = 2, Columns = 5)", d.ToString());
        }
Esempio n. 18
0
        public void HasRandomSource()
        {
            const int N = 2;
            const int P = 3;
            var       d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(N, P), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(N), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(P));

            Assert.IsNotNull(d.RandomSource);
        }
Esempio n. 19
0
        public void FailSetRandomSourceWithNullReference()
        {
            const int N = 2;
            const int P = 3;
            var       d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(N, P), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(N), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(P));

            Assert.Throws <ArgumentNullException>(() => d.RandomSource = null);
        }
        public void ValidateToString()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            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());
        }
Esempio n. 21
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);
        }
        public void HasRandomSourceEvenAfterSetToNull()
        {
            const int N = 2;
            const int P = 3;
            var       d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(N, P), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(N), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(P));

            Assert.DoesNotThrow(() => d.RandomSource = null);
            Assert.IsNotNull(d.RandomSource);
        }
 public void FailSampleStatic(
     [Values(2, 2, 2, 2, 5, 5, 5, 5)] int rowsOfM,
     [Values(2, 2, 2, 2, 2, 2, 2, 2)] int columnsOfM,
     [Values(3, 2, 2, 2, 6, 5, 5, 5)] int rowsOfV,
     [Values(2, 3, 2, 2, 5, 6, 5, 5)] int columnsOfV,
     [Values(2, 2, 3, 2, 2, 2, 3, 2)] int rowsOfK,
     [Values(2, 2, 2, 3, 2, 2, 2, 3)] int columnsOfK)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => MatrixNormal.Sample(new Random(), MatrixLoader.GenerateRandomDenseMatrix(rowsOfM, columnsOfM), MatrixLoader.GenerateRandomDenseMatrix(rowsOfV, columnsOfV), MatrixLoader.GenerateRandomDenseMatrix(rowsOfK, columnsOfK)));
 }
        public void CanGetV([Values(1, 3, 10)] int n, [Values(1, 3, 10)] int p)
        {
            var matrixV = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n);
            var d       = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), matrixV, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));

            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]);
                }
            }
        }
    /// <summary>
    /// Generates a random trajectory set for a map.
    /// </summary>
    /// <param name="map">The map we want to generate trajectories on.</param>
    /// <param name="precisionError">The precision error we want the trajectories of our set to contain.</param>
    /// <param name="samplingError">The sampling error we want the trajectories of our set to contain.</param>
    /// <param name="amount">The amount of random trajectories we want to generate.</param>
    /// <returns></returns>
    public List <List <(Vector3, int)> > GenerateTracks(Map map, int precisionError, int samplingError, int amount)
    {
        norm = null;                                                //reset our distribution matrix.
        map.roads.ForEach(x => x.popularities.ForEach(y => y = 0)); //reset how often the edges of a road has been traversed.
        List <List <(Vector3, int)> > allTrajectories = new List <List <(Vector3, int)> >();

        for (int i = 0; i < amount; i++)
        {
            allTrajectories.Add(GenerateTrack(map, precisionError, samplingError));
        }

        return(allTrajectories);
    }
        public void CanGetV(int n, int p)
        {
            var V = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n);
            var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), V, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));

            for (int i = 0; i < V.RowCount; i++)
            {
                for (int j = 0; j < V.ColumnCount; j++)
                {
                    Assert.AreEqual <double>(V[i, j], d.RowCovariance[i, j]);
                }
            }
        }
Esempio n. 27
0
        public void CanGetK(int n, int p)
        {
            var matrixK = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p);
            var d       = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), 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]);
                }
            }
        }
Esempio n. 28
0
        public void CanGetM(int n, int p)
        {
            var matrixM = MatrixLoader.GenerateRandomDenseMatrix(n, p);
            var d       = new MatrixNormal(matrixM, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));

            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]);
                }
            }
        }
Esempio n. 29
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]);
                }
            }
        }
Esempio n. 30
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]);
                }
            }
        }
    /// <summary>
    /// Gets a random 2d error.
    /// </summary>
    /// <param name="sigmaSquared">The square of the sigma we want for our error.</param>
    /// <returns></returns>
    public (Vector3, Vector3) GetRandom2D(float sigmaSquared)
    {
        if (norm == null)
        {
            Matrix <double> m = Matrix <double> .Build.Dense(2, 1);

            m[0, 0] = 0;
            m[1, 0] = 0;

            Matrix <double> v = Matrix <double> .Build.Dense(2, 2);

            v[0, 0] = sigmaSquared;
            v[0, 1] = 0;
            v[1, 0] = 0;
            v[1, 1] = sigmaSquared;

            Matrix <double> k = Matrix <double> .Build.Dense(1, 1);

            k[0, 0] = 1.0;

            norm = new MatrixNormal(m, v, k, random);
        }

        Matrix <double> samp       = norm.Sample();
        Vector3         randVector = new Vector3((float)samp[0, 0], 0, (float)samp[1, 0]);

        //We average the result of multiple subsequent points to smoothen the trajectories here.
        Vector3 acc = Vector3.Zero;

        for (int i = 0; i < interpolationRands.Length; i++)
        {
            if (i != interpolationRands.Length - 1)
            {
                interpolationRands[i] = interpolationRands[i + 1];
            }
            else
            {
                interpolationRands[i] = randVector;
            }
            acc += interpolationRands[i];
        }

        acc = acc / interpolationLength;

        return(randVector, acc);
    }
 public void CanSetRandomSource()
 {
     int n = 2;
     int p = 3;
     var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));
     d.RandomSource = new Random();
 }
        public void FailCreateMatrixNormal(int mRows, int mCols, int vRows, int vCols, int kRows, int kCols)
        {
            var M = MatrixLoader.GenerateRandomDenseMatrix(mRows, mCols);
            var V = MatrixLoader.GenerateRandomDenseMatrix(vRows, vCols);
            var K = MatrixLoader.GenerateRandomDenseMatrix(kRows, kCols);

            MatrixNormal d = new MatrixNormal(M, V, K);
        }
 public void CanSetV(int n, int p)
 {
     var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));
     d.RowCovariance = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n);
 }
 public void HasRandomSource()
 {
     int n = 2;
     int p = 3;
     var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));
     Assert.IsNotNull(d.RandomSource);
 }
 public void FailSetRandomSourceWithNullReference()
 {
     int n = 2;
     int p = 3;
     var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));
     d.RandomSource = null;
 }
Esempio n. 37
0
 public void CanGetM(int n, int p)
 {
     var matrixM = MatrixLoader.GenerateRandomDenseMatrix(n, p);
     var d = new MatrixNormal(matrixM, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));
     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]);
         }
     }
 }
        public void ValidateDensity()
        {
            int rows = 2;
            int cols = 2;
            var M = new DenseMatrix(rows, cols);
            M[0, 0] = 0.156065579983862;
            M[0, 1] = -0.568039841576594;
            M[1, 0] = -0.806288628097313;
            M[1, 1] = -1.20004405005077;

            var V = new DenseMatrix(rows, rows);
            V[0, 0] = 0.674457817054746;
            V[0, 1] = 0.878930403442185;
            V[1, 0] = 0.878930403442185;
            V[1, 1] = 1.76277498368061;

            var K = new DenseMatrix(cols, cols);
            K[0, 0] = 0.674457817054746;
            K[0, 1] = 0.878930403442185;
            K[1, 0] = 0.878930403442185;
            K[1, 1] = 1.76277498368061;
            MatrixNormal d = new MatrixNormal(M, V, K);

            var X = new DenseMatrix(rows, cols);
            X[0, 0] = 2;
            X[0, 1] = 2;

            AssertHelpers.AlmostEqual(0.00015682927366491211, d.Density(X), 16);
        }
 public void FailSetRandomSourceWithNullReference()
 {
     const int N = 2;
     const int P = 3;
     var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(N, P), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(N), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(P));
     Assert.Throws<ArgumentNullException>(() => d.RandomSource = null);
 }
 public void CanGetV([Values(1, 3, 10)] int n, [Values(1, 3, 10)] int p)
 {
     var matrixV = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n);
     var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), matrixV, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));
     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]);
         }
     }
 }
Esempio n. 41
0
 public void HasRandomSourceEvenAfterSetToNull()
 {
     const int N = 2;
     const int P = 3;
     var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(N, P), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(N), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(P));
     Assert.DoesNotThrow(() => d.RandomSource = null);
     Assert.IsNotNull(d.RandomSource);
 }
Esempio n. 42
0
 public void HasRandomSource()
 {
     const int N = 2;
     const int P = 3;
     var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(N, P), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(N), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(P));
     Assert.IsNotNull(d.RandomSource);
 }
Esempio n. 43
0
 public void CanSample(int n, int p)
 {
     var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));
     d.Sample();
 }
Esempio n. 44
0
        public void ValidateDensity()
        {
            const int Rows = 2;
            const int Cols = 2;
            var m = new DenseMatrix(Rows, Cols);
            m[0, 0] = 0.156065579983862;
            m[0, 1] = -0.568039841576594;
            m[1, 0] = -0.806288628097313;
            m[1, 1] = -1.20004405005077;

            var v = new DenseMatrix(Rows, Rows);
            v[0, 0] = 0.674457817054746;
            v[0, 1] = 0.878930403442185;
            v[1, 0] = 0.878930403442185;
            v[1, 1] = 1.76277498368061;

            var k = new DenseMatrix(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 = new DenseMatrix(Rows, Cols);
            x[0, 0] = 2;
            x[0, 1] = 2;

            AssertHelpers.AlmostEqualRelative(0.00015682927366491211, d.Density(x), 16);
        }
Esempio n. 45
0
 public void CanGetK(int n, int p)
 {
     var matrixK = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p);
     var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), 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]);
         }
     }
 }
 public void CanGetV(int n, int p)
 {
     var V = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n);
     var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), V, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));
     for (int i = 0; i < V.RowCount; i++)
     {
         for (int j = 0; j < V.ColumnCount; j++)
         {
             Assert.AreEqual<double>(V[i, j], d.RowCovariance[i, j]);
         }
     }
 }
 public void ValidateToString()
 {
     int n = 2;
     int p = 5;
     var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));
     Assert.AreEqual<string>("MatrixNormal(Rows = 2, Columns = 5)", d.ToString());
 }
Esempio n. 48
0
 public void FailSampleStatic(int rowsOfM, int columnsOfM, int rowsOfV, int columnsOfV, int rowsOfK, int columnsOfK)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => MatrixNormal.Sample(new Random(), MatrixLoader.GenerateRandomDenseMatrix(rowsOfM, columnsOfM), MatrixLoader.GenerateRandomDenseMatrix(rowsOfV, columnsOfV), MatrixLoader.GenerateRandomDenseMatrix(rowsOfK, columnsOfK)));
 }
Esempio n. 49
0
 public void ValidateToString()
 {
     const int N = 2;
     const int P = 5;
     var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(N, P), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(N), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(P));
     Assert.AreEqual("MatrixNormal(Rows = 2, Columns = 5)", d.ToString());
 }