Exemplo n.º 1
0
        public void StabilityMeanVariance()
        {
            // Test around 10^9, potential stability issues
            var gaussian = new Distributions.Normal(1e+9, 2)
            {
                RandomSource = new Numerics.Random.MersenneTwister(100)
            };

            AssertHelpers.AlmostEqual(1e+9, gaussian.Samples().Take(10000).Mean(), 11);
            AssertHelpers.AlmostEqual(4d, gaussian.Samples().Take(10000).Variance(), 1);
            AssertHelpers.AlmostEqual(2d, gaussian.Samples().Take(10000).StandardDeviation(), 2);
        }
Exemplo n.º 2
0
        public static Vector GenerateRandomDenseVector(int order)
        {
            // Fill a matrix with standard random numbers.
            var normal = new Distributions.Normal();
            normal.RandomSource = new Random.MersenneTwister(1);
            var v = new DenseVector(order);
            for (int i = 0; i < order; i++)
            {
                v[i] = normal.Sample();
            }

            // Generate a matrix which is positive definite.
            return v;
        }
        public static Vector <float> GenerateRandomUserDefinedVector(int order)
        {
            // Fill a matrix with standard random numbers.
            var normal = new Distributions.Normal();

            normal.RandomSource = new Numerics.Random.MersenneTwister(1);
            var v = new UserDefinedVector(order);

            for (int i = 0; i < order; i++)
            {
                v[i] = (float)normal.Sample();
            }

            // Generate a matrix which is positive definite.
            return(v);
        }
Exemplo n.º 4
0
        public static Matrix GenerateRandomPositiveDefiniteDenseMatrix(int order)
        {
            // Fill a matrix with standard random numbers.
            var normal = new Distributions.Normal();
            normal.RandomSource = new Random.MersenneTwister(1);
            var A = new DenseMatrix(order);
            for (int i = 0; i < order; i++)
            {
                for (int j = 0; j < order; j++)
                {
                    A[i, j] = normal.Sample();
                }
            }

            // Generate a matrix which is positive definite.
            return A.Transpose() * A;
        }
Exemplo n.º 5
0
        public static Matrix GenerateRandomDenseMatrix(int row, int col)
        {
            // Fill a matrix with standard random numbers.
            var normal = new Distributions.Normal();
            normal.RandomSource = new Random.MersenneTwister(1);
            var A = new DenseMatrix(row, col);
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    A[i, j] = normal.Sample();
                }
            }

            // Generate a matrix which is positive definite.
            return A;
        }
Exemplo n.º 6
0
        public void StabilityMeanVariance()
        {
            // Test around 10^9, potential stability issues
            var gaussian = new Distributions.Normal(1e+9, 2, new MersenneTwister(100));

            AssertHelpers.AlmostEqual(1e+9, Statistics.Mean(gaussian.Samples().Take(10000)), 11);
            AssertHelpers.AlmostEqual(4d, Statistics.Variance(gaussian.Samples().Take(10000)), 1);
            AssertHelpers.AlmostEqual(2d, Statistics.StandardDeviation(gaussian.Samples().Take(10000)), 2);

            AssertHelpers.AlmostEqual(1e+9, ArrayStatistics.Mean(gaussian.Samples().Take(10000).ToArray()), 11);
            AssertHelpers.AlmostEqual(4d, ArrayStatistics.Variance(gaussian.Samples().Take(10000).ToArray()), 1);
            AssertHelpers.AlmostEqual(2d, ArrayStatistics.StandardDeviation(gaussian.Samples().Take(10000).ToArray()), 2);

            AssertHelpers.AlmostEqual(1e+9, StreamingStatistics.Mean(gaussian.Samples().Take(10000)), 11);
            AssertHelpers.AlmostEqual(4d, StreamingStatistics.Variance(gaussian.Samples().Take(10000)), 1);
            AssertHelpers.AlmostEqual(2d, StreamingStatistics.StandardDeviation(gaussian.Samples().Take(10000)), 2);
        }
Exemplo n.º 7
0
        public static Vector <Complex> GenerateRandomDenseVector(int order)
        {
            // Fill a matrix with standard random numbers.
            var normal = new Distributions.Normal
            {
                RandomSource = new Numerics.Random.MersenneTwister(1)
            };
            var v = new DenseVector(order);

            for (var i = 0; i < order; i++)
            {
                v[i] = new Complex(normal.Sample(), normal.Sample());
            }

            // Generate a matrix which is positive definite.
            return(v);
        }
Exemplo n.º 8
0
        public static Matrix<Complex> GenerateRandomDenseMatrix(int row, int col)
        {
            // Fill a matrix with standard random numbers.
            var normal = new Distributions.Normal
                         {
                             RandomSource = new Random.MersenneTwister(1)
                         };
            var matrixA = new DenseMatrix(row, col);
            for (var i = 0; i < row; i++)
            {
                for (var j = 0; j < col; j++)
                {
                    matrixA[i, j] = new Complex(normal.Sample(), normal.Sample());
                }
            }

            // Generate a matrix which is positive definite.
            return matrixA;
        }
        public static Matrix <float> GenerateRandomDenseMatrix(int row, int col)
        {
            // Fill a matrix with standard random numbers.
            var normal = new Distributions.Normal();

            normal.RandomSource = new Numerics.Random.MersenneTwister(1);
            var matrixA = new DenseMatrix(row, col);

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    matrixA[i, j] = (float)normal.Sample();
                }
            }

            // Generate a matrix which is positive definite.
            return(matrixA);
        }
        public static Matrix <float> GenerateRandomPositiveDefiniteUserDefinedMatrix(int order)
        {
            // Fill a matrix with standard random numbers.
            var normal = new Distributions.Normal();

            normal.RandomSource = new Numerics.Random.MersenneTwister(1);
            var matrixA = new UserDefinedMatrix(order);

            for (int i = 0; i < order; i++)
            {
                for (int j = 0; j < order; j++)
                {
                    matrixA[i, j] = (float)normal.Sample();
                }
            }

            // Generate a matrix which is positive definite.
            return(matrixA.Transpose() * matrixA);
        }
Exemplo n.º 11
0
        public static Matrix <Complex> GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(int order)
        {
            // Fill a matrix with standard random numbers.
            var normal = new Distributions.Normal
            {
                RandomSource = new Numerics.Random.MersenneTwister(1)
            };
            var matrixA = new UserDefinedMatrix(order);

            for (var i = 0; i < order; i++)
            {
                for (var j = 0; j < order; j++)
                {
                    matrixA[i, j] = new Complex(normal.Sample(), normal.Sample());
                }
            }

            // Generate a Hermitian matrix which is positive definite.
            return(matrixA.ConjugateTranspose() * matrixA);
        }
Exemplo n.º 12
0
        public static Matrix <Complex> GenerateRandomUserDefinedMatrix(int row, int col)
        {
            // Fill a matrix with standard random numbers.
            var normal = new Distributions.Normal
            {
                RandomSource = new Numerics.Random.MersenneTwister(1)
            };
            var matrixA = new UserDefinedMatrix(row, col);

            for (var i = 0; i < row; i++)
            {
                for (var j = 0; j < col; j++)
                {
                    matrixA[i, j] = new Complex(normal.Sample(), normal.Sample());
                }
            }

            // Generate a matrix which is positive definite.
            return(matrixA);
        }
Exemplo n.º 13
0
        public void StabilityMeanVariance()
        {
            // Test around 10^9, potential stability issues
            var gaussian = new Distributions.Normal(1e+9, 2)
                {
                    RandomSource = new Numerics.Random.MersenneTwister(100)
                };

            AssertHelpers.AlmostEqual(1e+9, gaussian.Samples().Take(10000).Mean(), 11);
            AssertHelpers.AlmostEqual(4d, gaussian.Samples().Take(10000).Variance(), 1);
            AssertHelpers.AlmostEqual(2d, gaussian.Samples().Take(10000).StandardDeviation(), 2);
        }
Exemplo n.º 14
0
        public void StabilityMeanVariance()
        {
            // Test around 10^9, potential stability issues
            var gaussian = new Distributions.Normal(1e+9, 2, new MersenneTwister(100));

            AssertHelpers.AlmostEqual(1e+9, Statistics.Mean(gaussian.Samples().Take(10000)), 11);
            AssertHelpers.AlmostEqual(4d, Statistics.Variance(gaussian.Samples().Take(10000)), 1);
            AssertHelpers.AlmostEqual(2d, Statistics.StandardDeviation(gaussian.Samples().Take(10000)), 2);

            AssertHelpers.AlmostEqual(1e+9, ArrayStatistics.Mean(gaussian.Samples().Take(10000).ToArray()), 11);
            AssertHelpers.AlmostEqual(4d, ArrayStatistics.Variance(gaussian.Samples().Take(10000).ToArray()), 1);
            AssertHelpers.AlmostEqual(2d, ArrayStatistics.StandardDeviation(gaussian.Samples().Take(10000).ToArray()), 2);

            AssertHelpers.AlmostEqual(1e+9, StreamingStatistics.Mean(gaussian.Samples().Take(10000)), 11);
            AssertHelpers.AlmostEqual(4d, StreamingStatistics.Variance(gaussian.Samples().Take(10000)), 1);
            AssertHelpers.AlmostEqual(2d, StreamingStatistics.StandardDeviation(gaussian.Samples().Take(10000)), 2);
        }
Exemplo n.º 15
0
        public static Matrix<Complex> GenerateRandomPositiveDefiniteHermitianDenseMatrix(int order)
        {
            // Fill a matrix with standard random numbers.
            var normal = new Distributions.Normal
                         {
                             RandomSource = new Random.MersenneTwister(1)
                         };
            var matrixA = new DenseMatrix(order);
            for (var i = 0; i < order; i++)
            {
                for (var j = 0; j < order; j++)
                {
                    matrixA[i, j] = new Complex(normal.Sample(), normal.Sample());
                }
            }

            // Generate a Hermitian matrix which is positive definite.
            return matrixA.ConjugateTranspose() * matrixA;
        }
Exemplo n.º 16
0
        public static Vector<Complex> GenerateRandomUserDefinedVector(int order)
        {
            // Fill a matrix with standard random numbers.
            var normal = new Distributions.Normal
                         {
                             RandomSource = new Random.MersenneTwister(1)
                         };
            var v = new UserDefinedVector(order);
            for (var i = 0; i < order; i++)
            {
                v[i] = new Complex(normal.Sample(), normal.Sample());
            }

            // Generate a matrix which is positive definite.
            return v;
        }