public void CanSampleSequence() { var n = new InverseGamma(1.0, 1.0); var ied = n.Samples(); GC.KeepAlive(ied.Take(5).ToArray()); }
public void CanSampleSequence() { var n = new InverseGamma(1.0, 1.0); var ied = n.Samples(); ied.Take(5).ToArray(); }
/// <summary> /// Run example /// </summary> /// <a href="http://en.wikipedia.org/wiki/Inverse-gamma_distribution">InverseGamma distribution</a> public void Run() { // 1. Initialize the new instance of the InverseGamma distribution class with parameters shape = 4, scale = 0.5 var inverseGamma = new InverseGamma(4, 0.5); Console.WriteLine(@"1. Initialize the new instance of the InverseGamma distribution class with parameters Shape = {0}, Scale = {1}", inverseGamma.Shape, inverseGamma.Scale); Console.WriteLine(); // 2. Distributuion properties: Console.WriteLine(@"2. {0} distributuion properties:", inverseGamma); // Cumulative distribution function Console.WriteLine(@"{0} - Сumulative distribution at location '0.3'", inverseGamma.CumulativeDistribution(0.3).ToString(" #0.00000;-#0.00000")); // Probability density Console.WriteLine(@"{0} - Probability density at location '0.3'", inverseGamma.Density(0.3).ToString(" #0.00000;-#0.00000")); // Log probability density Console.WriteLine(@"{0} - Log probability density at location '0.3'", inverseGamma.DensityLn(0.3).ToString(" #0.00000;-#0.00000")); // Entropy Console.WriteLine(@"{0} - Entropy", inverseGamma.Entropy.ToString(" #0.00000;-#0.00000")); // Largest element in the domain Console.WriteLine(@"{0} - Largest element in the domain", inverseGamma.Maximum.ToString(" #0.00000;-#0.00000")); // Smallest element in the domain Console.WriteLine(@"{0} - Smallest element in the domain", inverseGamma.Minimum.ToString(" #0.00000;-#0.00000")); // Mean Console.WriteLine(@"{0} - Mean", inverseGamma.Mean.ToString(" #0.00000;-#0.00000")); // Mode Console.WriteLine(@"{0} - Mode", inverseGamma.Mode.ToString(" #0.00000;-#0.00000")); // Variance Console.WriteLine(@"{0} - Variance", inverseGamma.Variance.ToString(" #0.00000;-#0.00000")); // Standard deviation Console.WriteLine(@"{0} - Standard deviation", inverseGamma.StdDev.ToString(" #0.00000;-#0.00000")); // Skewness Console.WriteLine(@"{0} - Skewness", inverseGamma.Skewness.ToString(" #0.00000;-#0.00000")); Console.WriteLine(); // 3. Generate 10 samples of the InverseGamma distribution Console.WriteLine(@"3. Generate 10 samples of the InverseGamma distribution"); for (var i = 0; i < 10; i++) { Console.Write(inverseGamma.Sample().ToString("N05") + @" "); } Console.WriteLine(); Console.WriteLine(); // 4. Generate 100000 samples of the InverseGamma(4, 0.5) distribution and display histogram Console.WriteLine(@"4. Generate 100000 samples of the InverseGamma(4, 0.5) distribution and display histogram"); var data = new double[100000]; InverseGamma.Samples(data, 4, 0.5); ConsoleHelper.DisplayHistogram(data); Console.WriteLine(); // 5. Generate 100000 samples of the InverseGamma(8, 0.5) distribution and display histogram Console.WriteLine(@"5. Generate 100000 samples of the InverseGamma(8, 0.5) distribution and display histogram"); InverseGamma.Samples(data, 8, 0.5); ConsoleHelper.DisplayHistogram(data); Console.WriteLine(); // 6. Generate 100000 samples of the InverseGamma(2, 1) distribution and display histogram Console.WriteLine(@"6. Generate 100000 samples of the InverseGamma(8, 2) distribution and display histogram"); InverseGamma.Samples(data, 8, 2); ConsoleHelper.DisplayHistogram(data); }