示例#1
0
        public double[] getSamples(int num) // 获取指定个数的样本
        {
            double[] ret     = new double[num];
            int[]    ret_int = new int[num];
            switch (DistributionName)
            {
            case "Normal":
                normalDis.Samples(ret);
                break;

            case "ContinuousUniform":
                continuousUniformDis.Samples(ret);
                break;

            case "Triangular":
                triangularDis.Samples(ret);
                break;

            case "StudentT":
                studentTDis.Samples(ret);
                break;

            case "DiscreteUniform":
                discreteUniform.Samples(ret_int);
                for (int i = 0; i < num; i++)
                {
                    ret[i] = ret_int[i];
                }
                break;
            }
            return(ret);
        }
示例#2
0
        public void CanSampleSequence()
        {
            var n   = new StudentT();
            var ied = n.Samples();

            ied.Take(5).ToArray();
        }
示例#3
0
        public static double[] studentT(double v1, double v2, double v3, int num)
        {
            var t = new StudentT(v1, v2, v3);

            double[] ret = new double[num];
            t.Samples(ret);
            return(ret);
        }
示例#4
0
 public void FailSampleSequenceStatic(double location, double scale, double dof)
 {
     var ied = StudentT.Samples(new Random(), location, scale, dof);
     var e   = ied.Take(5).ToArray();
 }
示例#5
0
 public void CanSampleSequenceStatic()
 {
     var ied = StudentT.Samples(new Random(), 0.0, 1.0, 3.0);
     var arr = ied.Take(5).ToArray();
 }
示例#6
0
        public void FailSampleSequenceStatic()
        {
            var ied = StudentT.Samples(new Random(0), 0.0, 1.0, Double.NaN);

            Assert.Throws <ArgumentOutOfRangeException>(() => ied.Take(5).ToArray());
        }
示例#7
0
        public void CanSampleSequenceStatic()
        {
            var ied = StudentT.Samples(new Random(0), 0.0, 1.0, 3.0);

            GC.KeepAlive(ied.Take(5).ToArray());
        }
 public void CanSampleSequence()
 {
     var n = new StudentT();
     var ied = n.Samples();
     var e = ied.Take(5).ToArray();
 }
        /// <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];

            StudentT.Samples(data, 0, 1, 1);
            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.Samples(data, 0, 1, 5);
            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.Samples(data, 0, 1, 10);
            ConsoleHelper.DisplayHistogram(data);
        }