コード例 #1
0
        public void ConstructorTest2()
        {
            var nakagami = new NakagamiDistribution(shape: 2.4, spread: 4.2);

            double mean   = nakagami.Mean;                                    // 1.946082119049118
            double median = nakagami.Median;                                  // 1.9061151110206338
            double var    = nakagami.Variance;                                // 0.41276438591729486

            double cdf  = nakagami.DistributionFunction(x: 1.4);              // 0.20603416752368109
            double pdf  = nakagami.ProbabilityDensityFunction(x: 1.4);        // 0.49253215371343023
            double lpdf = nakagami.LogProbabilityDensityFunction(x: 1.4);     // -0.708195533773302

            double ccdf = nakagami.ComplementaryDistributionFunction(x: 1.4); // 0.79396583247631891
            double icdf = nakagami.InverseDistributionFunction(p: cdf);       // 1.400000000131993

            double hf  = nakagami.HazardFunction(x: 1.4);                     // 0.62034426869133652
            double chf = nakagami.CumulativeHazardFunction(x: 1.4);           // 0.23071485080660473

            string str = nakagami.ToString(CultureInfo.InvariantCulture);     // Nakagami(x; μ = 2,4, ω = 4,2)"

            Assert.AreEqual(1.946082119049118, mean);
            Assert.AreEqual(1.9061151110206338, median, 1e-6);
            Assert.AreEqual(0.41276438591729486, var);
            Assert.AreEqual(0.23071485080660473, chf);
            Assert.AreEqual(0.20603416752368109, cdf);
            Assert.AreEqual(0.49253215371343023, pdf);
            Assert.AreEqual(-0.708195533773302, lpdf);
            Assert.AreEqual(0.62034426869133652, hf);
            Assert.AreEqual(0.79396583247631891, ccdf);
            Assert.AreEqual(1.40, icdf, 1e-7);
            Assert.AreEqual("Nakagami(x; μ = 2.4, ω = 4.2)", str);
        }
コード例 #2
0
        public void ConstructorTest2()
        {
            var nakagami = new NakagamiDistribution(shape: 2.4, spread: 4.2);

            double mean   = nakagami.Mean;                                    // 1.946082119049118
            double median = nakagami.Median;                                  // 1.9061151110206338
            double var    = nakagami.Variance;                                // 0.41276438591729486
            double mode   = nakagami.Mode;                                    // 1.8234582528810468

            double cdf  = nakagami.DistributionFunction(x: 1.4);              // 0.20603416752368109
            double pdf  = nakagami.ProbabilityDensityFunction(x: 1.4);        // 0.49253215371343023
            double lpdf = nakagami.LogProbabilityDensityFunction(x: 1.4);     // -0.708195533773302

            double ccdf = nakagami.ComplementaryDistributionFunction(x: 1.4); // 0.79396583247631891
            double icdf = nakagami.InverseDistributionFunction(p: cdf);       // 1.400000000131993

            double hf  = nakagami.HazardFunction(x: 1.4);                     // 0.62034426869133652
            double chf = nakagami.CumulativeHazardFunction(x: 1.4);           // 0.23071485080660473

            string str = nakagami.ToString(CultureInfo.InvariantCulture);     // Nakagami(x; μ = 2,4, ω = 4,2)"

            Assert.AreEqual(1.946082119049118, mean);
            Assert.AreEqual(1.9061151110206338, median, 1e-6);
            Assert.AreEqual(1.8234582528810468, mode);
            Assert.AreEqual(0.41276438591729486, var);
            Assert.AreEqual(0.23071485080660473, chf);
            Assert.AreEqual(0.20603416752368109, cdf);
            Assert.AreEqual(0.49253215371343023, pdf);
            Assert.AreEqual(-0.708195533773302, lpdf);
            Assert.AreEqual(0.62034426869133652, hf);
            Assert.AreEqual(0.79396583247631891, ccdf);
            Assert.AreEqual(1.40, icdf, 1e-7);
            Assert.AreEqual("Nakagami(x; μ = 2.4, ω = 4.2)", str);

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

            Assert.AreEqual(0.96015082529305074, range1.Min);
            Assert.AreEqual(3.0683231810919338, range1.Max);
            Assert.AreEqual(0.65984207711153242, range2.Min);
            Assert.AreEqual(3.5903316858157317, range2.Max);
            Assert.AreEqual(0.6598420771115322, range3.Min);
            Assert.AreEqual(3.5903316858157317, range3.Max);
        }
コード例 #3
0
        public void ProbabilityDistributionTest()
        {
            NakagamiDistribution n = new NakagamiDistribution(0.807602, 12.5);

            double[] expected = { 0, 0.1775314, 0.224023, 0.2081279, 0.158044, 0.101360 };
            double[] actual   = new double[expected.Length];

            for (int i = 0; i < actual.Length; i++)
            {
                actual[i] = n.ProbabilityDensityFunction(i);
            }

            for (int i = 0; i < actual.Length; i++)
            {
                Assert.AreEqual(expected[i], actual[i], 1e-5);
                Assert.IsFalse(double.IsNaN(actual[i]));
            }
        }
コード例 #4
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);
        }