public void TestAccumulatorNumericStability()
        {
            /* NOTE: Statistically it is possible that this test fails even
              * if everything works as expected. However, it's very unlikely to happen,
              * and even more unlikely to happen in a series. */

            Accumulator accumulator = new Accumulator();
            NormalDistribution gaussian = new NormalDistribution();

            // Test around 0, no stability issues expected
            gaussian.SetDistributionParameters(0, 1);
            for(int i = 0; i < 10000; i++)
            {
                accumulator.Add(gaussian.NextDouble());
            }

            Assert.That(accumulator.Mean, NumericIs.AlmostEqualTo((double) 0, 0.2), "Mean of (0,1)");
            Assert.That(accumulator.Variance, NumericIs.AlmostEqualTo((double) 1, 0.5), "Variance of (0,1)");

            // Test around 10^9, potential stability issues
            accumulator.Clear();
            gaussian.SetDistributionParameters(1e+9, 1);
            for(int i = 0; i < 10000; i++)
            {
                accumulator.Add(gaussian.NextDouble());
            }

            Assert.That(accumulator.Mean, NumericIs.AlmostEqualTo(1e+9, 0.2), "Mean of (1e+9,1)");
            Assert.That(accumulator.Variance, NumericIs.AlmostEqualTo((double) 1, 0.5), "Variance of (1e+9,1)");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Represents the target for the adapter.
        /// </summary>
        //public Distributions()
        //{
            
        //}
        public double NormCdf(double x)
        {
            double cdf;
            NormalDistribution normCdf = new NormalDistribution(0, 1);

            cdf = normCdf.CumulativeDistribution(x);
            return cdf;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Represents the target for the adapter.
        /// </summary>
        //public Distributions()
        //{
        //}
        public double NormCdf(double x)
        {
            double cdf;
            Debug.Assert(!double.IsNaN(x));
            var normCdf = new NormalDistribution(0, 1);

            cdf = normCdf.CumulativeDistribution(x);
            return cdf;
        }
 /// <summary>
 /// Create a gaussian noise source with normally distributed amplitudes.
 /// </summary>
 /// <param name="uniformWhiteRandomSource">Uniform white random source.</param>
 /// <param name="mean">mu-parameter of the normal distribution</param>
 /// <param name="standardDeviation">sigma-parameter of the normal distribution</param>
 public WhiteGaussianNoiseSource(
     RandomSource uniformWhiteRandomSource,
     double mean,
     double standardDeviation
     )
 {
     NormalDistribution gaussian = new NormalDistribution(uniformWhiteRandomSource);
     gaussian.SetDistributionParameters(mean, standardDeviation);
     _distribution = gaussian;
 }
        public void TestDescriptiveStatisticsMeanVariance()
        {
            // Test around 10^9, potential stability issues
            NormalDistribution gaussian = new NormalDistribution(1e+9, 2);

            Assert.That(DescriptiveStatistics.Mean(gaussian.EnumerateDoubles(10000)), NumericIs.AlmostEqualTo(1e+9, 0.2), "Mean of (1e+9,2)");
            Assert.That(DescriptiveStatistics.Variance(gaussian.EnumerateDoubles(10000)), NumericIs.AlmostEqualTo((double) 4, 0.5), "Variance of (1e+9,2)");
            Assert.That(DescriptiveStatistics.StandardDeviation(gaussian.EnumerateDoubles(10000)), NumericIs.AlmostEqualTo((double) 2, 0.5), "StdDev of (1e+9,2)");
        }
Ejemplo n.º 6
0
 private double[,] InitializeDataArray(int size)
 {
     double[,] data = new double[size, size];
     NormalDistribution normalDist = new NormalDistribution(mean, delta);
     for (int i = 0; i < size; ++i) {
         for (int j = 0; j < size; ++j) {
             data[i, j] = normalDist.NextDouble();
         }
     }
     return data;
 }
Ejemplo n.º 7
0
        public void AdapterConstructorTargetTest()
        {
            Distributions target1 = new Distributions();
            Adapter target = new Adapter(target1);
            Adaptee adaptee = new Adaptee();
            NormalDistribution normCdf = new NormalDistribution(0, 1);

            Func<double, double> expected = target1.NormCdf;
            Func<double, double> actual = target.NormCdf;
            
            Assert.AreNotEqual(expected(1), adaptee.NormCdf(1), "Should NOT be equal function behaviour.");
            Assert.AreEqual(expected(1), actual(1), "Should be equal function behaviour.");
            Assert.AreEqual( normCdf.CumulativeDistribution(1), actual(1), "Should be equal function behaviour.");

            Func<double, double> normCdf2 = arg =>
            {
                arg = arg - 1;
                return arg;
            };
            Assert.AreNotEqual(expected, normCdf2);
        }
        public void TestContinuousDistributions_Gaussian()
        {
            TestContinuousDistributionShapeMatchesCumulativeDensity(
                new StandardDistribution(),
                -2.0,
                2.0,
                10,
                100000,
                0.01,
                "StandardDistribution()");

            TestContinuousDistributionShapeMatchesCumulativeDensity(
                new NormalDistribution(-5.0, 2.0),
                -9.0,
                -1.0,
                10,
                100000,
                0.01,
                "NormalDistribution(-5.0,2.0)");

            TestContinuousDistributionShapeMatchesCumulativeDensity(
                new LognormalDistribution(1.0, 0.5),
                0.0,
                8.0,
                10,
                100000,
                0.01,
                "LognormalDistribution(1.0,0.5)");

            // Test Parameter Estimation
            NormalDistribution source = new NormalDistribution(4.0, 2.0);
            NormalDistribution target = new NormalDistribution();
            target.EstimateDistributionParameters(source.EnumerateDoubles(1000));
            Assert.That(target.Mu, NumericIs.AlmostEqualTo(4.0, 0.1), "Normal Parameter Estimation: Mu");
            Assert.That(target.Sigma, NumericIs.AlmostEqualTo(2.0, 0.1), "Normal Parameter Estimation: Sigma");
        }