Exemplo n.º 1
0
        public void TestStudentTDistribution()
        {
            double[][] para =
            {
                new double[]
                {
                    12,
                    0,
                    -0.6954828655117925816605449,
                    0.3022177430388599749597682,
                    1.782287555649320074526381,
                    0.08490359467537564413509914
                }
            };

            for (int i = 0; i < para.Length; i++)
            {
                var tester = new ContDistTester(para[i], delegate(double a, double b)
                {
                    var ret = new StudentTDistribution
                    {
                        Nu = (int)a
                    };
                    return(ret);
                }
                                                );
                tester.Test(1e-7);
            }
        }
Exemplo n.º 2
0
        public void TestStudentTRoundTrip()
        {
            // arrange
            var expected = new StudentTDistribution(0d, 1d, 2d, 0.3, 0.7);

            // act
            var serialized   = expected.ToString();
            var deserialized = Distribution.DeserializeDistribution(serialized);
            var distribution = deserialized.IfNone(() => { Assert.Fail(); return(default !); });
Exemplo n.º 3
0
        public void TestStudentTDistributionQuantile()
        {
            // N[Quantile[StudentTDistribution[12], 1/10], 25]
            Assert.AreEqual(-1.356217334023205433796216, StudentTDistribution.Quantile(0.1, 12), 1e-14);

            // N[Quantile[StudentTDistribution[12], 5/10], 25]
            Assert.AreEqual(0, StudentTDistribution.Quantile(0.5, 12));

            // N[Quantile[StudentTDistribution[12], 9/10], 25]
            Assert.AreEqual(1.356217334023205433796216, StudentTDistribution.Quantile(0.9, 12), 1e-14);
        }
Exemplo n.º 4
0
        public void TestStudentTWithBoundsGetSample()
        {
            // arrange
            var subject = new StudentTDistribution(0d, 1d, 2d, 0.3, 0.7);

            // act
            var sample = subject.GetSample();

            // assert
            Assert.IsTrue(sample > 0.3 && sample < 0.7);
        }
Exemplo n.º 5
0
        public void TestStudentTWithBoundsFillSamples()
        {
            // arrange
            var subject = new StudentTDistribution(0d, 1d, 2d, 0.3, 0.7);
            var samples = Range(0, 42).Map(_ => NaN).ToArray();

            // act
            subject.FillSamples(samples);

            // assert
            Assert.IsTrue(samples.All(d => d > 0.3 && d < 0.7));
        }
Exemplo n.º 6
0
        public void TestStudentTDistributionCDF()
        {
            // N[CDF[StudentTDistribution[12], 1/10], 25
            Assert.AreEqual(0.5390022147715870702517874, StudentTDistribution.CDF(0.1, 12), 1e-14);

            // N[CDF[StudentTDistribution[12], 5/10], 25
            Assert.AreEqual(0.6869412618873379592985154, StudentTDistribution.CDF(0.5, 12), 1e-14);

            // N[CDF[StudentTDistribution[12], 9/10], 25
            Assert.AreEqual(0.8070872841025491107351673, StudentTDistribution.CDF(0.9, 12), 1e-14);

            // N[CDF[StudentTDistribution[12], -9/10], 25
            Assert.AreEqual(0.1929127158974508892648327, StudentTDistribution.CDF(-0.9, 12), 1e-14);
        }
Exemplo n.º 7
0
        public void TestStudentTDistributionPDF()
        {
            // N[PDF[StudentTDistribution[12], 1/10], 25]
            Assert.AreEqual(0.3886164693412969119684949, StudentTDistribution.PDF(0.1, 12), 1e-14);

            // N[PDF[StudentTDistribution[12], 5/10], 25]
            Assert.AreEqual(0.3417166761526545973157284, StudentTDistribution.PDF(0.5, 12), 1e-14);

            // N[PDF[StudentTDistribution[12], 9/10], 25]
            Assert.AreEqual(0.2555532488891510539167125, StudentTDistribution.PDF(0.9, 12), 1e-14);

            // N[PDF[StudentTDistribution[12], -9/10], 25]
            Assert.AreEqual(0.2555532488891510539167125, StudentTDistribution.PDF(-0.9, 12), 1e-14);
        }
Exemplo n.º 8
0
        public async Task TestStudentTCumulativeDistributionAtBounds()
        {
            // arrange
            var subject        = new StudentTDistribution(0d, 1d, 2d, 0.3, 0.7);
            var expectedLowerP = (await GetNumDataAsync("pt(0.3, 2)"))[0].Data[0];
            var expectedUpperP = (await GetNumDataAsync("pt(0.7, 2)"))[0].Data[0];

            // act
            var(actualLowerP, actualUpperP) = subject.CumulativeDistributionAtBounds;

            // assert
            Assert.AreEqual(expectedLowerP, actualLowerP, Base.Constant.TOLERANCE);
            Assert.AreEqual(expectedUpperP, actualUpperP, Base.Constant.TOLERANCE);
        }
Exemplo n.º 9
0
        public async Task TestStudentTGetDensities()
        {
            // arrange
            var subject  = new StudentTDistribution(0d, 1d, 2d);
            var expected = (await GetNumDataAsync(
                                "sapply(seq(qt(0.3, 2), qt(0.7, 2), length.out = 5), function(cd){dt(cd, 2)})"
                                ))[0].Data.ToArr();

            // act
            var(_, actual) = subject.GetDensities(0.3, 0.7, 5);

            // assert
            Assert.IsTrue(actual.Count == 5);
            expected.Iter((i, d) => Assert.AreEqual(d, actual[i], Base.Constant.TOLERANCE));
        }
Exemplo n.º 10
0
 public void TestInitialize()
 {
     tDistributionDouble  = new StudentTDistribution(n, tDouble);
     tDistributionFloat   = new StudentTDistribution(n, tFloat);
     tDistributionDecimal = new StudentTDistribution(n, tDecimal);
 }
Exemplo n.º 11
0
 public void ShouldThrowAnEceptioWhenTypeIsNotSupported()
 {
     StudentTDistribution testObject = new StudentTDistribution(31, string.Empty);
 }
Exemplo n.º 12
0
 public void ShouldThrowAnEceptioWhenNIsFreaerThanThirty()
 {
     StudentTDistribution testObject = new StudentTDistribution(31, tDouble);
 }
Exemplo n.º 13
0
 public void ShouldThrowAnEceptioWhenNIsEqualZero()
 {
     StudentTDistribution testObject = new StudentTDistribution(0, tDouble);
 }
Exemplo n.º 14
0
 public void ShouldReturnCorrectValueForTParameter_StaticDouble()
 {
     Assert.AreEqual(2.55, Convert.ToDouble(StudentTDistribution.GetTParameter(98, 18)), 0.001);
 }
Exemplo n.º 15
0
        public void ShouldThrowAnEceptioWhenWhenConfidenceLevelIsLessGreaterNightyNine()
        {
            StudentTDistribution testObject = new StudentTDistribution(25, tDouble);

            testObject.GetTParameter(99.01);
        }
Exemplo n.º 16
0
        public void ShouldThrowAnEceptioWhenTypeNIsTwoForVarianceCalculation()
        {
            StudentTDistribution testObject = new StudentTDistribution(2, tDouble);

            testObject.GetVariance();
        }
Exemplo n.º 17
0
        public void ShouldThrowAnEceptioWhenNIsOneForMeanCalculation()
        {
            StudentTDistribution testObject = new StudentTDistribution(1, tDouble);

            testObject.GetMean();
        }
Exemplo n.º 18
0
        public void ShouldThrowAnEceptioWhenTypeNIsTwoForStandardDeviationCalculation()
        {
            StudentTDistribution testObject = new StudentTDistribution(2, tDouble);

            testObject.GetStandardDeviation();
        }
Exemplo n.º 19
0
 public void ShouldReturnCorrectValueForConfidenceInterval_StaticDecimal()
 {
     Assert.AreEqual(2.65M, Convert.ToDecimal(StudentTDistribution.GetConfidenceInterval(95, 5, 16)));
 }
Exemplo n.º 20
0
        public void ShouldThrowAnEceptioWhenWhenConfidenceLevelIsLessThanEigthy()
        {
            StudentTDistribution testObject = new StudentTDistribution(25, tDouble);

            testObject.GetTParameter(79.99);
        }
Exemplo n.º 21
0
 public void ShouldReturnCorrectValueForTParameter_StaticDecimal()
 {
     Assert.AreEqual(2.54999999999999M, Convert.ToDecimal(StudentTDistribution.GetTParameter(98, 18)));
 }
Exemplo n.º 22
0
 public void ShouldReturnCorrectValueForConfidenceInterval_StaticDouble()
 {
     Assert.AreEqual(2.65, Convert.ToDouble(StudentTDistribution.GetConfidenceInterval(95, 5, 16)), 0.001);
 }
Exemplo n.º 23
0
 public void ShouldReturnCorrectValueForTTestValue_StaticDecimal()
 {
     Assert.AreEqual(6.09721295301628M, Convert.ToDecimal(StudentTDistribution.GetTTestValue(arrayDouble1, arrayDouble2)));
 }
Exemplo n.º 24
0
 public void ShouldReturnCorrectValueForTTestValue_StaticDouble()
 {
     Assert.AreEqual(6.0972, Convert.ToDouble(StudentTDistribution.GetTTestValue(arrayDouble1, arrayDouble2)), 0.001);
 }
Exemplo n.º 25
0
 public void ShouldThrowAnEceptioWhenNIsLessThanZero()
 {
     StudentTDistribution testObject = new StudentTDistribution(-1, tDouble);
 }