コード例 #1
0
        public void ConstructorTest2()
        {
            var laplace = new LaplaceDistribution(location: 4, scale: 2);

            double mean   = laplace.Mean;                                     // 4.0
            double median = laplace.Median;                                   // 4.0
            double var    = laplace.Variance;                                 // 8.0

            double cdf  = laplace.DistributionFunction(x: 0.27);              // 0.077448104942453522
            double pdf  = laplace.ProbabilityDensityFunction(x: 0.27);        // 0.038724052471226761
            double lpdf = laplace.LogProbabilityDensityFunction(x: 0.27);     // -3.2512943611198906

            double ccdf = laplace.ComplementaryDistributionFunction(x: 0.27); // 0.92255189505754642
            double icdf = laplace.InverseDistributionFunction(p: cdf);        // 0.27

            double hf  = laplace.HazardFunction(x: 0.27);                     // 0.041974931360160776
            double chf = laplace.CumulativeHazardFunction(x: 0.27);           // 0.080611649844768624

            string str = laplace.ToString(CultureInfo.InvariantCulture);      // Laplace(x; μ = 4, b = 2)

            Assert.AreEqual(4.0, mean);
            Assert.AreEqual(4.0, median);
            Assert.AreEqual(8.0, var);
            Assert.AreEqual(0.080611649844768624, chf);
            Assert.AreEqual(0.077448104942453522, cdf);
            Assert.AreEqual(0.038724052471226761, pdf);
            Assert.AreEqual(-3.2512943611198906, lpdf);
            Assert.AreEqual(0.041974931360160776, hf);
            Assert.AreEqual(0.92255189505754642, ccdf);
            Assert.AreEqual(0.26999999840794775, icdf);
            Assert.AreEqual("Laplace(x; μ = 4, b = 2)", str);
        }
コード例 #2
0
        public void ConstructorTest2()
        {
            var laplace = new LaplaceDistribution(location: 4, scale: 2);

            double mean   = laplace.Mean;                                     // 4.0
            double median = laplace.Median;                                   // 4.0
            double var    = laplace.Variance;                                 // 8.0
            double mode   = laplace.Mode;                                     // 4.0

            double cdf  = laplace.DistributionFunction(x: 0.27);              // 0.077448104942453522
            double pdf  = laplace.ProbabilityDensityFunction(x: 0.27);        // 0.038724052471226761
            double lpdf = laplace.LogProbabilityDensityFunction(x: 0.27);     // -3.2512943611198906

            double ccdf = laplace.ComplementaryDistributionFunction(x: 0.27); // 0.92255189505754642
            double icdf = laplace.InverseDistributionFunction(p: cdf);        // 0.27

            double hf  = laplace.HazardFunction(x: 0.27);                     // 0.041974931360160776
            double chf = laplace.CumulativeHazardFunction(x: 0.27);           // 0.080611649844768624

            string str = laplace.ToString(CultureInfo.InvariantCulture);      // Laplace(x; μ = 4, b = 2)

            Assert.AreEqual(4.0, mean);
            Assert.AreEqual(4.0, median);
            Assert.AreEqual(8.0, var);
            Assert.AreEqual(4.0, mode);
            Assert.AreEqual(0.080611649844768624, chf);
            Assert.AreEqual(0.077448104942453522, cdf);
            Assert.AreEqual(0.038724052471226761, pdf);
            Assert.AreEqual(-3.2512943611198906, lpdf);
            Assert.AreEqual(0.041974931360160776, hf);
            Assert.AreEqual(0.92255189505754642, ccdf);
            Assert.AreEqual(0.26999999840794775, icdf);
            Assert.AreEqual("Laplace(x; μ = 4, b = 2)", str);

            var range1 = laplace.GetRange(0.95);
            var range2 = laplace.GetRange(0.99);
            var range3 = laplace.GetRange(0.01);

            Assert.AreEqual(-0.60517019072231026, range1.Min);
            Assert.AreEqual(8.6051701894643209, range1.Max);
            Assert.AreEqual(-3.8240460108561982, range2.Min);
            Assert.AreEqual(11.824046011144626, range2.Max);
            Assert.AreEqual(-3.8240460108561951, range3.Min);
            Assert.AreEqual(11.824046011144626, range3.Max);
        }
コード例 #3
0
        public void MedianTest()
        {
            var target = new LaplaceDistribution(location: 2, scale: 0.42);

            Assert.AreEqual(target.Median, target.InverseDistributionFunction(0.5));
        }