예제 #1
0
        public void InverseTest3()
        {
            var invchisq = new InverseChiSquareDistribution(degreesOfFreedom: 7);

            double cdf, icdf;


            // Round-trip with 6.27
            cdf = invchisq.DistributionFunction(x: 6.27);
            Assert.AreEqual(0.99998842765450235, cdf);

            icdf = invchisq.InverseDistributionFunction(p: cdf);
            Assert.AreEqual(6.2699998329362963, icdf, 1e-6);


            // Round-trip with 0
            cdf = invchisq.DistributionFunction(x: 0);
            Assert.AreEqual(0, cdf);

            icdf = invchisq.InverseDistributionFunction(p: cdf);
            Assert.AreEqual(0, icdf, 1e-6);


            // Round-trip with 1
            cdf = invchisq.DistributionFunction(x: 1);
            Assert.AreEqual(0.99482853651651548, cdf);

            icdf = invchisq.InverseDistributionFunction(p: cdf);
            Assert.AreEqual(1, icdf, 1e-6);
        }
예제 #2
0
        public void ConstructorTest()
        {
            #region doc_ctor
            // Create a new Inverse Chi-Square distribution with 7 d. of freedom.
            var invchisq = new InverseChiSquareDistribution(degreesOfFreedom: 7);

            double mean   = invchisq.Mean;                                     // 0.2
            double median = invchisq.Median;                                   // 0.1575844721504685
            double var    = invchisq.Variance;                                 // 75
            double mode   = invchisq.Mode;                                     // 0.1111111111111111

            double cdf  = invchisq.DistributionFunction(x: 6.27);              // 0.99998842765450235
            double pdf  = invchisq.ProbabilityDensityFunction(x: 6.27);        // 0.0000063457380298844403
            double lpdf = invchisq.LogProbabilityDensityFunction(x: 6.27);     // -11.967727146795536

            double ccdf = invchisq.ComplementaryDistributionFunction(x: 6.27); // 1.1572345497645742E-05
            double icdf = invchisq.InverseDistributionFunction(p: cdf);        // 6.2700000113440124

            double hf  = invchisq.HazardFunction(x: 6.27);                     // 0.54835366185492873
            double chf = invchisq.CumulativeHazardFunction(x: 6.27);           // 11.366892314949228

            string str = invchisq.ToString();                                  // "Inv-χ²(x; df = 7)"
            #endregion

            Assert.AreEqual(0.2, mean, 1e-10);
            Assert.AreEqual(0.1575844721504685, median, 1e-6);
            Assert.AreEqual(75, var);
            Assert.AreEqual(0.1111111111111111, mode);
            Assert.AreEqual(11.366892314949228, chf);
            Assert.AreEqual(0.99998842765450235, cdf);
            Assert.AreEqual(0.0000063457380298844403, pdf);
            Assert.AreEqual(-11.967727146795536, lpdf);
            Assert.AreEqual(0.54835366185492873, hf);
            Assert.AreEqual(1.1572345497645742E-05, ccdf);
            Assert.AreEqual(6.2700000113440124, icdf, 1e-6);
            Assert.AreEqual("Inv-χ²(x; df = 7)", str);

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

            Assert.AreEqual(0.071087647148133509, range1.Min, 1e-10);
            Assert.AreEqual(0.4613930157807814, range1.Max, 1e-10);
            Assert.AreEqual(0.054126298885838933, range2.Min, 1e-10);
            Assert.AreEqual(0.807074944498757, range2.Max, 1e-10);
            Assert.AreEqual(0.054126298885838926, range3.Min, 1e-10);
            Assert.AreEqual(0.807074944498757, range3.Max, 1e-10);

            Assert.AreEqual(0, invchisq.Support.Min);
            Assert.AreEqual(double.PositiveInfinity, invchisq.Support.Max);

            Assert.AreEqual(invchisq.InverseDistributionFunction(0), invchisq.Support.Min);
            Assert.AreEqual(invchisq.InverseDistributionFunction(1), invchisq.Support.Max);
        }
예제 #3
0
        public void ConstructorTest()
        {
            var invchisq = new InverseChiSquareDistribution(degreesOfFreedom: 7);

            double mean   = invchisq.Mean;                                     // 0.2
            double median = invchisq.Median;                                   // 6.345811068141737
            double var    = invchisq.Variance;                                 // 75
            double mode   = invchisq.Mode;                                     // 0.1111111111111111

            double cdf  = invchisq.DistributionFunction(x: 6.27);              // 0.50860033566176044
            double pdf  = invchisq.ProbabilityDensityFunction(x: 6.27);        // 0.0000063457380298844403
            double lpdf = invchisq.LogProbabilityDensityFunction(x: 6.27);     // -11.967727146795536

            double ccdf = invchisq.ComplementaryDistributionFunction(x: 6.27); // 0.49139966433823956
            double icdf = invchisq.InverseDistributionFunction(p: cdf);        // 6.2699998329362963

            double hf  = invchisq.HazardFunction(x: 6.27);                     // 0.000012913598625327002
            double chf = invchisq.CumulativeHazardFunction(x: 6.27);           // 0.71049750196765715

            string str = invchisq.ToString();                                  // "Inv-χ²(x; df = 7)"

            Assert.AreEqual(0.2, mean, 1e-10);
            Assert.AreEqual(6.345811068141737, median, 1e-6);
            Assert.AreEqual(75, var);
            Assert.AreEqual(0.1111111111111111, mode);
            Assert.AreEqual(0.71049750196765715, chf);
            Assert.AreEqual(0.50860033566176044, cdf);
            Assert.AreEqual(0.0000063457380298844403, pdf);
            Assert.AreEqual(-11.967727146795536, lpdf);
            Assert.AreEqual(0.000012913598625327002, hf);
            Assert.AreEqual(0.49139966433823956, ccdf);
            Assert.AreEqual(6.2699998329362963, icdf, 1e-6);
            Assert.AreEqual("Inv-χ²(x; df = 7)", str);

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

            Assert.AreEqual(2.1673499092513264, range1.Min, 1e-10);
            Assert.AreEqual(14.067140449765922, range1.Max, 1e-10);
            Assert.AreEqual(1.2390421125300894, range2.Min, 1e-10);
            Assert.AreEqual(18.475307115523769, range2.Max, 1e-10);
            Assert.AreEqual(1.2390421125300894, range3.Min, 1e-10);
            Assert.AreEqual(18.475307115523773, range3.Max, 1e-10);
        }