/// <summary>
        ///   Creates a OxyPlot's graph for the Quantile Function.
        /// </summary>
        ///
        public PlotModel CreateICDF()
        {
            try
            {
                double[] y;
                try { y = probabilities.Apply(instance.InverseDistributionFunction); }
                catch
                {
                    try
                    {
                        var general = GeneralContinuousDistribution
                                      .FromDensityFunction(instance.Support, instance.ProbabilityFunction);
                        y = probabilities.Apply(general.InverseDistributionFunction);
                    }
                    catch
                    {
                        var general = GeneralContinuousDistribution
                                      .FromDistributionFunction(instance.Support, instance.DistributionFunction);
                        y = probabilities.Apply(general.InverseDistributionFunction);
                    }
                }

                return(createBaseModel(unit, "QDF", probabilities, y, false));
            }
            catch
            {
                return(null);
            }
        }
        /// <summary>
        ///   Creates a OxyPlot's graph for the Hazard Function.
        /// </summary>
        ///
        public PlotModel CreateHF()
        {
            try
            {
                double[] y;
                try { y = supportPoints.Apply(instance.HazardFunction); }
                catch
                {
                    try
                    {
                        var general = GeneralContinuousDistribution
                                      .FromDensityFunction(instance.Support, instance.ProbabilityFunction);
                        y = supportPoints.Apply(general.HazardFunction);
                    }
                    catch
                    {
                        var general = GeneralContinuousDistribution
                                      .FromDistributionFunction(instance.Support, instance.DistributionFunction);
                        y = supportPoints.Apply(general.HazardFunction);
                    }
                }

                return(createBaseModel(range, "HF", supportPoints, y, instance is UnivariateDiscreteDistribution));
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        public void ConstructorTest9()
        {
            var original = new LognormalDistribution(location: 0.42, shape: 1.1);

            var log = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            testLognormal(log);
        }
Exemplo n.º 4
0
        public void ConstructorTest17()
        {
            var original = new VonMisesDistribution(mean: 0.42, concentration: 1.2);

            var vonMises = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            testVonMises(vonMises);
        }
Exemplo n.º 5
0
        public void ConstructorTest1()
        {
            var original = new NormalDistribution(mean: 4, stdDev: 4.2);

            var normal = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            testNormal(normal);
        }
Exemplo n.º 6
0
        public void ConstructorTest14()
        {
            var original = new NakagamiDistribution(shape: 2.4, spread: 4.2);

            var nakagami = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            testNakagami(nakagami);
        }
Exemplo n.º 7
0
        public void ConstructorTest13()
        {
            var original = new GompertzDistribution(eta: 4.2, b: 1.1);

            var gompertz = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            testGompertz(gompertz);
        }
Exemplo n.º 8
0
        public void ConstructorTest10()
        {
            var original = new ChiSquareDistribution(degreesOfFreedom: 7);

            var chisq = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            testChiSquare(chisq);
        }
Exemplo n.º 9
0
        public void ConstructorTest4()
        {
            var original = new InverseGaussianDistribution(mean: 0.42, shape: 1.2);

            var invGaussian = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            testInvGaussian(invGaussian);
        }
Exemplo n.º 10
0
        public void ConstructorTest6()
        {
            var original = new LaplaceDistribution(location: 4, scale: 2);

            var laplace = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            testLaplace(laplace);
        }
        /// <summary>
        ///   Creates a OxyPlot's graph for the Probability Density Function.
        /// </summary>
        ///
        public PlotModel CreatePDF()
        {
            try { pdf = supportPoints.Apply(instance.ProbabilityFunction); }
            catch
            {
                var general = GeneralContinuousDistribution
                              .FromDistributionFunction(instance.Support, instance.DistributionFunction);
                pdf = supportPoints.Apply(general.ProbabilityDensityFunction);
            }

            return(createBaseModel(range, "PDF", supportPoints, pdf, instance is UnivariateDiscreteDistribution));
        }
        /// <summary>
        ///   Creates a OxyPlot's graph for the Log Probability Density Function.
        /// </summary>
        ///
        public PlotModel CreateLPDF()
        {
            double[] y;
            try { y = supportPoints.Apply(instance.LogProbabilityFunction); }
            catch
            {
                var general = GeneralContinuousDistribution
                              .FromDistributionFunction(instance.Support, instance.DistributionFunction);
                y = supportPoints.Apply(general.LogProbabilityDensityFunction);
            }

            return(createBaseModel(range, "Log-PDF", supportPoints, y, instance is UnivariateDiscreteDistribution));
        }
Exemplo n.º 13
0
        public void MedianTest2()
        {
            NormalDistribution original = new NormalDistribution(0.4, 2.2);

            var target = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            Assert.AreEqual(target.Median, target.InverseDistributionFunction(0.5));
            Assert.AreEqual(target.Median, original.Median, 1e-10);

            target = GeneralContinuousDistribution.FromDensityFunction(
                original.Support, original.ProbabilityDensityFunction);

            Assert.AreEqual(target.Median, target.InverseDistributionFunction(0.5), 1e-10);
            Assert.AreEqual(target.Median, original.Median, 1e-10);
        }
Exemplo n.º 14
0
        public void MedianTest()
        {
            var laplace = new LaplaceDistribution(location: 2, scale: 0.42);

            var target = GeneralContinuousDistribution.FromDensityFunction(
                laplace.Support, laplace.ProbabilityDensityFunction);

            Assert.AreEqual(target.Median, target.InverseDistributionFunction(0.5));
            Assert.AreEqual(laplace.Median, target.Median, 1e-10);

            target = GeneralContinuousDistribution.FromDistributionFunction(
                laplace.Support, laplace.DistributionFunction);

            Assert.AreEqual(target.Median, target.InverseDistributionFunction(0.5), 1e-10);
            Assert.AreEqual(laplace.Median, target.Median, 1e-10);
        }
Exemplo n.º 15
0
        public void ConstructorTest6()
        {
            var original = new LaplaceDistribution(location: 4, scale: 2);

            var laplace = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            for (double i = -10; i < +10; i += 0.1)
            {
                double expected = original.ProbabilityDensityFunction(i);
                double actual   = laplace.ProbabilityDensityFunction(i);

                Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-4));
            }

            testLaplace(laplace);
        }
Exemplo n.º 16
0
        public void ConstructorTest17()
        {
            var original = new VonMisesDistribution(mean: 0.42, concentration: 1.2);

            var vonMises = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            for (double i = -10; i < +10; i += 0.1)
            {
                double expected = original.ProbabilityDensityFunction(i);
                double actual   = vonMises.ProbabilityDensityFunction(i);

                Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-4));
            }

            testVonMises(vonMises, 1);
        }
Exemplo n.º 17
0
        public void ConstructorTest9()
        {
            var original = new LognormalDistribution(location: 0.42, shape: 1.1);

            var log = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            for (double i = -10; i < +10; i += 0.1)
            {
                double expected = original.ProbabilityDensityFunction(i);
                double actual   = log.ProbabilityDensityFunction(i);

                double diff = Math.Abs(expected - actual);
                Assert.AreEqual(expected, actual, 1e-8);
            }

            testLognormal(log);
        }
Exemplo n.º 18
0
        public void ConstructorTest6()
        {
            var original = new LaplaceDistribution(location: 4, scale: 2);

            var laplace = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            for (double i = -10; i < +10; i += 0.1)
            {
                double expected = original.ProbabilityDensityFunction(i);
                double actual   = laplace.ProbabilityDensityFunction(i);

                double diff = Math.Abs(expected - actual);
                Assert.AreEqual(expected, actual, 1e-6);
            }

            testLaplace(laplace);
        }
Exemplo n.º 19
0
        public void ConstructorTest1()
        {
            var original = new NormalDistribution(mean: 4, stdDev: 4.2);

            var normal = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            for (double i = -10; i < +10; i += 0.1)
            {
                double expected = original.ProbabilityDensityFunction(i);
                double actual   = normal.ProbabilityDensityFunction(i);

                double diff = Math.Abs(expected - actual);
                Assert.AreEqual(expected, actual, 1e-6);
            }

            testNormal(normal, 1e3);
        }
Exemplo n.º 20
0
        public void ConstructorTest10()
        {
            var original = new ChiSquareDistribution(degreesOfFreedom: 7);

            var chisq = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            for (double i = -10; i < +10; i += 0.1)
            {
                double expected = original.ProbabilityDensityFunction(i);
                double actual   = chisq.ProbabilityDensityFunction(i);

                Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-7));
                Assert.IsFalse(Double.IsNaN(actual));
                Assert.IsFalse(Double.IsNaN(expected));
            }

            testChiSquare(chisq);
        }
Exemplo n.º 21
0
        public void ConstructorTest14()
        {
            var original = new NakagamiDistribution(shape: 2.4, spread: 4.2);

            var nakagami = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            for (double i = -10; i < +10; i += 0.1)
            {
                double expected = original.ProbabilityDensityFunction(i);
                double actual   = nakagami.ProbabilityDensityFunction(i);

                Assert.IsTrue(expected.IsRelativelyEqual(actual, 0.8));
                Assert.IsFalse(double.IsNaN(expected));
                Assert.IsFalse(double.IsNaN(actual));
            }

            testNakagami(nakagami);
        }
Exemplo n.º 22
0
        public void ConstructorTest13()
        {
            var original = new GompertzDistribution(eta: 4.2, b: 1.1);

            var gompertz = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            for (double i = -10; i < +10; i += 0.1)
            {
                double expected = original.DistributionFunction(i);
                double actual   = gompertz.DistributionFunction(i);

                Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-7));
                Assert.IsFalse(double.IsNaN(expected));
                Assert.IsFalse(double.IsNaN(actual));
            }

            testGompertz(gompertz);
        }
Exemplo n.º 23
0
        public void InverseDistributionFunctionTest()
        {
            double[] expected =
            {
                Double.NegativeInfinity, -4.38252, -2.53481, -1.20248,
                -0.0640578,                   1.0,  2.06406,  3.20248,4.53481, 6.38252,
                Double.PositiveInfinity
            };

            NormalDistribution original = new NormalDistribution(1.0, 4.2);
            var target = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            for (int i = 0; i < expected.Length; i++)
            {
                double x      = i / 10.0;
                double actual = target.InverseDistributionFunction(x);
                Assert.AreEqual(expected[i], actual, 1e-5);
                Assert.IsFalse(Double.IsNaN(actual));
            }
        }