예제 #1
0
 static double[][] GenerateRandomVector()
 {
     double[]   excpectationVector = { 116, 102, 113, 100, 107, 110 };
     double[]   variance           = { 1, 36, 4, 49, 16, 9 };
     double[][] oilCost            = new double[2][];
     for (int i = 0; i < 2; i++)
     {
         oilCost[i] = new double[3];
         for (int j = 0; j < 3; j++)
         {
             do
             {
                 oilCost[i][j] = StudentT.Sample(excpectationVector[i + j], Math.Sqrt(variance[i + j]), 4);
             }while (80 > oilCost[i][j] && oilCost[i][j] > 120);
         }
     }
     return(oilCost);
 }
예제 #2
0
        public double getSample() // 获取当前分布样本
        {
            double ret = 0;

            switch (DistributionName)
            {
            case "Normal":
                ret = normalDis.Sample(); break;

            case "ContinuousUniform":
                ret = continuousUniformDis.Sample(); break;

            case "Triangular":
                ret = triangularDis.Sample(); break;

            case "StudentT":
                ret = studentTDis.Sample(); break;

            case "DiscreteUniform":
                ret = discreteUniform.Sample(); break;
            }
            return(ret);
        }
예제 #3
0
 public void CanSample()
 {
     var n = new StudentT();
     var d = n.Sample();
 }
예제 #4
0
 public void FailSampleStatic(double location, double scale, double dof)
 {
     var d = StudentT.Sample(new Random(), location, scale, dof);
 }
예제 #5
0
 public void CanSampleStatic()
 {
     var d = StudentT.Sample(new Random(), 0.0, 1.0, 3.0);
 }
예제 #6
0
 public void FailSampleStatic()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => StudentT.Sample(new Random(0), Double.NaN, 1.0, Double.NaN));
 }
        /// <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 CanSample()
 {
     var n = new StudentT();
     var d = n.Sample();
 }