Пример #1
0
        public void ValidateDensityLn(
            [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)] double location,
            [Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale,
            [Values(1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof,
            [Values(0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, 2.0)] double x,
            [Values(-1.144729885849399, -1.837877066409348, -1.837877066409348, -2.754167798283503, -2.754167798283503, -1.039720770839917, -1.647918433002166, -1.647918433002166, -2.687639203842085, -2.687639203842085, -0.918938533204672, -1.418938533204674, -2.918938533204674)] double p)
        {
            var n = new StudentT(location, scale, dof);

            AssertHelpers.AlmostEqual(p, n.DensityLn(x), 13);
        }
Пример #2
0
        public void ValidateDensityLn(double location, double scale, double dof, double x, double p)
        {
            var n = new StudentT(location, scale, dof);

            AssertHelpers.AlmostEqual(p, n.DensityLn(x), 13);
        }
        /// <summary>
        /// Run example
        /// </summary>
        /// <a href="http://en.wikipedia.org/wiki/StudentT_distribution">StudentT distribution</a>
        public void Run()
        {
            // 1. Initialize the new instance of the StudentT distribution class with parameters Location = 0, Scale = 1, DegreesOfFreedom = 1
            var studentT = new StudentT();

            Console.WriteLine(@"1. Initialize the new instance of the StudentT distribution class with parameters Location = {0}, Scale = {1}, DegreesOfFreedom = {2}", studentT.Location, studentT.Scale, studentT.DegreesOfFreedom);
            Console.WriteLine();

            // 2. Distributuion properties:
            Console.WriteLine(@"2. {0} distributuion properties:", studentT);

            // Cumulative distribution function
            Console.WriteLine(@"{0} - Сumulative distribution at location '0.3'", studentT.CumulativeDistribution(0.3).ToString(" #0.00000;-#0.00000"));

            // Probability density
            Console.WriteLine(@"{0} - Probability density at location '0.3'", studentT.Density(0.3).ToString(" #0.00000;-#0.00000"));

            // Log probability density
            Console.WriteLine(@"{0} - Log probability density at location '0.3'", studentT.DensityLn(0.3).ToString(" #0.00000;-#0.00000"));

            // Entropy
            Console.WriteLine(@"{0} - Entropy", studentT.Entropy.ToString(" #0.00000;-#0.00000"));

            // Largest element in the domain
            Console.WriteLine(@"{0} - Largest element in the domain", studentT.Maximum.ToString(" #0.00000;-#0.00000"));

            // Smallest element in the domain
            Console.WriteLine(@"{0} - Smallest element in the domain", studentT.Minimum.ToString(" #0.00000;-#0.00000"));

            // Mean
            Console.WriteLine(@"{0} - Mean", studentT.Mean.ToString(" #0.00000;-#0.00000"));

            // Median
            Console.WriteLine(@"{0} - Median", studentT.Median.ToString(" #0.00000;-#0.00000"));

            // Mode
            Console.WriteLine(@"{0} - Mode", studentT.Mode.ToString(" #0.00000;-#0.00000"));

            // Variance
            Console.WriteLine(@"{0} - Variance", studentT.Variance.ToString(" #0.00000;-#0.00000"));

            // Standard deviation
            Console.WriteLine(@"{0} - Standard deviation", studentT.StdDev.ToString(" #0.00000;-#0.00000"));

            // 3. Generate 10 samples of the StudentT distribution
            Console.WriteLine(@"3. Generate 10 samples of the StudentT distribution");
            for (var i = 0; i < 10; i++)
            {
                Console.Write(studentT.Sample().ToString("N05") + @" ");
            }

            Console.WriteLine();
            Console.WriteLine();

            // 4. Generate 100000 samples of the StudentT(0, 1, 1) distribution and display histogram
            Console.WriteLine(@"4. Generate 100000 samples of the StudentT(0, 1, 1) distribution and display histogram");
            var data = new double[100000];

            for (var i = 0; i < data.Length; i++)
            {
                data[i] = studentT.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);

            // 5. Generate 100000 samples of the StudentT(0, 1, 5) distribution and display histogram
            Console.WriteLine(@"5. Generate 100000 samples of the StudentT(0, 1, 5) distribution and display histogram");
            studentT.DegreesOfFreedom = 5;
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = studentT.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
            Console.WriteLine();

            // 6. Generate 100000 samples of the StudentT(0, 1, 10) distribution and display histogram
            Console.WriteLine(@"6. Generate 100000 samples of the StudentT(0, 1, 10) distribution and display histogram");
            studentT.DegreesOfFreedom = 10;
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = studentT.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
        }
 public void ValidateDensityLn(double location, double scale, double dof, double x, double p)
 {
     var n = new StudentT(location, scale, dof);
     AssertHelpers.AlmostEqual(p, n.DensityLn(x), 13);
 }
Пример #5
0
 public void ValidateDensityLn(
     [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)] double location, 
     [Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale, 
     [Values(1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof, 
     [Values(0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, 2.0)] double x, 
     [Values(-1.144729885849399, -1.837877066409348, -1.837877066409348, -2.754167798283503, -2.754167798283503, -1.039720770839917, -1.647918433002166, -1.647918433002166, -2.687639203842085, -2.687639203842085, -0.918938533204672, -1.418938533204674, -2.918938533204674)] double p)
 {
     var n = new StudentT(location, scale, dof);
     AssertHelpers.AlmostEqual(p, n.DensityLn(x), 13);
 }