public void CanSample() { var d = new Zipf(0.7, 5); var s = d.Sample(); Assert.Between(s, 0, 5); }
public void ValidateCumulativeDistribution(double s, int n, int x) { var d = new Zipf(s, n); var cdf = SpecialFunctions.GeneralHarmonic(x, s) / SpecialFunctions.GeneralHarmonic(n, s); AssertHelpers.AlmostEqualRelative(cdf, d.CumulativeDistribution(x), 14); }
//private static bool TEST_ACTIVE = true; //private static void TestRequestQueue() //{ // RequestQueue<string> strQueue = new RequestQueue<string>(8); // long beginTicks = DateTime.Now.Ticks; // TEST_ACTIVE = true; // for (int i = 0; i < 8; i++) // { // Task.Factory.StartNew(TestEnqueue, strQueue); // } // Task.Factory.StartNew(TestDequeue, strQueue); // while (DateTime.Now.Ticks - beginTicks < 1 * 10000000) ; // TEST_ACTIVE = false; //} //private static Action<object> TestEnqueue = (object obj) => //{ // RequestQueue<string> strQueue = obj as RequestQueue<string>; // Random rand = new Random(); // while (TEST_ACTIVE) // { // int pk = rand.Next(0, 8); // strQueue.Enqueue("123", pk); // } //}; //private static Action<object> TestDequeue = (object obj) => //{ // RequestQueue<string> strQueue = obj as RequestQueue<string>; // Random rand = new Random(); // string value = null; // while (TEST_ACTIVE) // { // int pk = rand.Next(0, 8); // if (strQueue.TryDequeue(out value)) // { // Debug.Assert(value != null); // } // } //}; private static void ZipfTest() { Dictionary <int, int> dict = new Dictionary <int, int>(); Zipf zipf = new Zipf(100000, 0.8, false); for (int i = 0; i < 200000; i++) { int key = zipf.Next(); if (dict.ContainsKey(key)) { dict[key]++; } else { dict[key] = 1; } } List <KeyValuePair <int, int> > myList = dict.ToList(); myList.Sort( delegate(KeyValuePair <int, int> pair1, KeyValuePair <int, int> pair2) { return(pair2.Value.CompareTo(pair1.Value)); } ); for (int i = 0; i < 5; i++) { Console.WriteLine(myList[i].Key + " " + myList[i].Value); } }
public void CanCreateZipf(double s, int n) { var d = new Zipf(s, n); Assert.AreEqual(s, d.S); Assert.AreEqual(n, d.N); }
public void ValidateToString() { System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; var d = new Zipf(1.0, 5); Assert.AreEqual("Zipf(S = 1, N = 5)", d.ToString()); }
public void ValidateCumulativeDistribution([Values(0.1, 1)] double s, [Values(1, 20, 50)] int n, [Values(2, 15)] int x) { var d = new Zipf(s, n); var cdf = SpecialFunctions.GeneralHarmonic(x, s) / SpecialFunctions.GeneralHarmonic(n, s); AssertHelpers.AlmostEqual(cdf, d.CumulativeDistribution(x), 14); }
public void CanSample() { var d = new Zipf(0.7, 5); var s = d.Sample(); Assert.LessOrEqual(s, 5); Assert.GreaterOrEqual(s, 0); }
public void CanCreateZipf([Values(0.1, 1)] double s, [Values(1, 20, 50)] int n) { var d = new Zipf(s, n); Assert.AreEqual(s, d.S); Assert.AreEqual(n, d.N); }
private static void zipf_cdf_test() //****************************************************************************80 // // Purpose: // // ZIPF_CDF_TEST tests ZIPF_CDF, ZIPF_CDF_INV, ZIPF_PDF. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 09 March 2016 // // Author: // // John Burkardt // { int x; Console.WriteLine(""); Console.WriteLine("ZIPF_CDF_TEST"); Console.WriteLine(" ZIPF_CDF evaluates the Zipf CDF;"); Console.WriteLine(" ZIPF_CDF_INV inverts the Zipf CDF;"); Console.WriteLine(" ZIPF_PDF evaluates the Zipf PDF;"); double a = 2.0E+00; Console.WriteLine(""); Console.WriteLine(" PDF parameter A = " + a + ""); if (!Zipf.zipf_check(a)) { Console.WriteLine(""); Console.WriteLine("ZIPF_CDF_TEST - Fatal error!"); Console.WriteLine(" The parameters are not legal."); return; } Console.WriteLine(""); Console.WriteLine(" X PDF CDF CDF_INV()"); Console.WriteLine(""); for (x = 1; x <= 20; x++) { double pdf = Zipf.zipf_pdf(x, a); double cdf = Zipf.zipf_cdf(x, a); int x2 = Zipf.zipf_cdf_inv(a, cdf); Console.WriteLine(" " + x.ToString(CultureInfo.InvariantCulture).PadLeft(12) + " " + pdf.ToString(CultureInfo.InvariantCulture).PadLeft(12) + " " + cdf.ToString(CultureInfo.InvariantCulture).PadLeft(12) + " " + x2.ToString(CultureInfo.InvariantCulture).PadLeft(12) + ""); } }
static void Main(string[] args) { ThreadPool.SetMaxThreads(maxThreads, maxThreads); Console.WriteLine("Generating input distribution..."); samples = new int[sampleCount]; Zipf.Samples(samples, s, n); int[] threadCount = Enumerable.Range(1, maxThreads).ToArray(); // Desired output: // Class 1 2 3 4 5 // Classic 5 6 7 7 8 // Concurrent 5 6 7 7 8 DataTable resultTable = new DataTable(); resultTable.Clear(); resultTable.Columns.Add("Class"); foreach (var tc in threadCount) { resultTable.Columns.Add(tc.ToString()); } DataRow concurrentLru = resultTable.NewRow(); DataRow classicLru = resultTable.NewRow(); concurrentLru["Class"] = "concurrentLru"; classicLru["Class"] = "classicLru"; foreach (int tc in threadCount) { const int warmup = 3; const int runs = 6; double[] results = new double[warmup + runs]; for (int i = 0; i < warmup + runs; i++) { results[i] = MeasureThroughput(new ConcurrentLru <int, int>(tc, capacity, EqualityComparer <int> .Default), tc); } double avg = AverageLast(results, runs) / 1000000; Console.WriteLine($"ConcurrLru ({tc}) {avg} million ops/sec"); concurrentLru[tc.ToString()] = avg.ToString(); for (int i = 0; i < warmup + runs; i++) { results[i] = MeasureThroughput(new ClassicLru <int, int>(tc, capacity, EqualityComparer <int> .Default), tc); } avg = AverageLast(results, runs) / 1000000; Console.WriteLine($"ClassicLru ({tc}) {avg} million ops/sec"); classicLru[tc.ToString()] = avg.ToString(); } resultTable.Rows.Add(concurrentLru); resultTable.Rows.Add(classicLru); ExportCsv(resultTable); Console.WriteLine("Done."); }
public void ValidateSkewness(double s, int n) { var d = new Zipf(s, n); if (s > 4) { Assert.AreEqual(((SpecialFunctions.GeneralHarmonic(n, s - 3) * Math.Pow(SpecialFunctions.GeneralHarmonic(n, s), 2)) - (SpecialFunctions.GeneralHarmonic(n, s - 1) * ((3 * SpecialFunctions.GeneralHarmonic(n, s - 2) * SpecialFunctions.GeneralHarmonic(n, s)) - Math.Pow(SpecialFunctions.GeneralHarmonic(n, s - 1), 2)))) / Math.Pow((SpecialFunctions.GeneralHarmonic(n, s - 2) * SpecialFunctions.GeneralHarmonic(n, s)) - Math.Pow(SpecialFunctions.GeneralHarmonic(n, s - 1), 2), 1.5), d.Skewness); } }
public void ValidateEntropy( [Values(0.1, 0.1, 0.1, 1.0, 1.0, 1.0)] double s, [Values(1, 20, 50, 1, 20, 50)] int n, [Values(0.0, 2.9924075515295949, 3.9078245132371388, 0.0, 2.5279968533953743, 3.1971263138845916)] double e) { var d = new Zipf(s, n); AssertHelpers.AlmostEqual(e, d.Entropy, 15); }
public void Setup() { _newCache = new MassTransitCache <Guid, Item, CacheValue <Item> >(new UsageCachePolicy <Item>(), new CacheOptions { Capacity = 1000 }); _samples = new int[SampleCount]; Zipf.Samples(_samples, S, N); }
public void Setup() { _massTransitCache = new MassTransitCache <Guid, Item, ITimeToLiveCacheValue <Item> >(new TimeToLiveCachePolicy <Item>(TimeSpan.FromSeconds(30)), new CacheOptions { Capacity = 1000 }); _samples = new int[SampleCount]; Zipf.Samples(_samples, S, N); }
public void CanSampleSequence() { var d = new Zipf(0.7, 5); var ied = d.Samples(); var e = ied.Take(1000).ToArray(); foreach (var i in e) { Assert.LessOrEqual(i, 5); Assert.GreaterOrEqual(i, 0); } }
public void CanSampleSequence() { var d = new Zipf(0.7, 5); var ied = d.Samples(); var e = ied.Take(1000).ToArray(); foreach (var i in e) { Assert.Between(i, 0, 5); } }
//****************************************************************************80 public static double planck_sample(double a, double b, ref int seed) //****************************************************************************80 // // Purpose: // // PLANCK_SAMPLE samples the Planck PDF. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 26 October 2004 // // Author: // // John Burkardt // // Reference: // // Luc Devroye, // Non-Uniform Random Variate Generation, // Springer Verlag, 1986, pages 552. // // Parameters: // // Input, double A, B, the parameters of the PDF. // 0.0 < A, // 0.0 < B. // // Input/output, int &SEED, a seed for the random number generator. // // Output, double PLANCK_SAMPLE, a sample of the PDF. // { const double a2 = 0.0; const double b2 = 1.0; double c2 = b + 1.0; double g = Gamma.gamma_sample(a2, b2, c2, ref seed); int z = Zipf.zipf_sample(c2, ref seed); double x = g / (a * z); return(x); }
public MongoWorker(MongoClient c, POCTestOptions t, POCTestResults r, int id) { logger = LogManager.GetLogger($"MongoWorker {id}"); mongoClient = c; //Ping c.GetDatabase("admin").RunCommand <BsonDocument>(new BsonDocument("ping", 1)); testOpts = t; testResults = r; workerID = id; var db = mongoClient.GetDatabase(testOpts.namespaces[0]); maxCollections = testOpts.numcollections; String baseCollectionName = testOpts.namespaces[1]; if (maxCollections > 1) { colls = new List <IMongoCollection <BsonDocument> >(); lastCollection = 0; for (int i = 0; i < maxCollections; i++) { String str = baseCollectionName + i; colls.Add(db.GetCollection <BsonDocument>(str)); } } else { coll = db.GetCollection <BsonDocument>(baseCollectionName); } // id sequence = getHighestID(); ReviewShards(); rng = new Random(); if (testOpts.zipfsize > 0) { zipfian = true; zipf = new Zipf(0.99, testOpts.zipfsize); } if (!string.IsNullOrWhiteSpace(testOpts.workflow)) { workflow = testOpts.workflow; workflowed = true; keyStack = new List <BsonDocument>(); } }
public YCSBDataGenerator( int recordCount, double readWritePerc = 0.5, Distribution dist = Distribution.Uniform, double theta = 0.5) { this.recordCount = recordCount; this.dist = dist; this.readWritePerc = readWritePerc; this.readWriteRandBound = (int)(this.readWritePerc * RAND_UPPER_BOUND); if (this.dist == Distribution.Zipf) { // Console.WriteLine("theta = {0}", theta); this.zipf = new Zipf(recordCount, theta); } else { this.uniform = new Uniform(recordCount); } this.operationDist = new Uniform(RAND_UPPER_BOUND); }
public void ValidateProbabilityLn([Values(0.1, 1)] double s, [Values(1, 20, 50)] int n, [Values(1, 15)] int x) { var d = new Zipf(s, n); Assert.AreEqual(Math.Log(d.Probability(x)), d.ProbabilityLn(x)); }
public void ValidateMinimum() { var d = new Zipf(1.0, 5); Assert.AreEqual(1, d.Minimum); }
public void ValidateProbability([Values(0.1, 1)] double s, [Values(1, 20, 50)] int n, [Values(1, 15)] int x) { var d = new Zipf(s, n); Assert.AreEqual((1.0 / Math.Pow(x, s)) / SpecialFunctions.GeneralHarmonic(n, s), d.Probability(x)); }
public void SetNFails([Values(-1, 0)] int n) { var d = new Zipf(1.0, 5); Assert.Throws <ArgumentOutOfRangeException>(() => d.N = n); }
public void ValidateMode([Values(0.1, 1)] double s, [Values(1, 20, 50)] int n) { var d = new Zipf(s, n); Assert.AreEqual(1, d.Mode); }
public void SetSFails([Values(Double.NaN, -1.0, Double.NegativeInfinity)] double s) { var d = new Zipf(1.0, 5); Assert.Throws<ArgumentOutOfRangeException>(() => d.S = s); }
public void ValidateToString() { var d = new Zipf(1.0, 5); Assert.AreEqual("Zipf(S = 1, N = 5)", d.ToString()); }
public void ValidateEntropy(double s, int n, double e) { var d = new Zipf(s, n); AssertHelpers.AlmostEqualRelative(e, d.Entropy, 15); }
public void SetNFails(int n) { var d = new Zipf(1.0, 5); Assert.Throws<ArgumentOutOfRangeException>(() => d.N = n); }
public void SetSFails(double s) { var d = new Zipf(1.0, 5); Assert.Throws<ArgumentOutOfRangeException>(() => d.S = s); }
public void SetSFails(double s) { var d = new Zipf(1.0, 5); Assert.That(() => d.S = s, Throws.ArgumentException); }
public void SetSFails([Values(Double.NaN, -1.0, Double.NegativeInfinity)] double s) { var d = new Zipf(1.0, 5); Assert.Throws <ArgumentOutOfRangeException>(() => d.S = s); }
public void ValidateMaximum(double s, int n) { var d = new Zipf(s, n); Assert.AreEqual(n, d.Maximum); }
public void SetNFails(int n) { var d = new Zipf(1.0, 5); Assert.That(() => d.N = n, Throws.ArgumentException); }
public void ValidateMaximum([Values(0.1, 1)] double s, [Values(1, 20, 50)] int n) { var d = new Zipf(s, n); Assert.AreEqual(n, d.Maximum); }
public void ValidateMedianThrowsNotSupportedException() { var d = new Zipf(1.0, 5); Assert.Throws <NotSupportedException>(() => { var m = d.Median; }); }
public void ValidateProbability(double s, int n, int x) { var d = new Zipf(s, n); Assert.AreEqual((1.0 / Math.Pow(x, s)) / SpecialFunctions.GeneralHarmonic(n, s), d.Probability(x)); }
public void ValidateMode(double s, int n) { var d = new Zipf(s, n); Assert.AreEqual(1, d.Mode); }
public void ValidateProbabilityLn(double s, int n, int x) { var d = new Zipf(s, n); Assert.AreEqual(Math.Log(d.Probability(x)), d.ProbabilityLn(x)); }
public override void ExecuteExample() { // <a href="http://en.wikipedia.org/wiki/Binomial_distribution">Binomial distribution</a> MathDisplay.WriteLine("<b>Binomial distribution</b>"); // 1. Initialize the new instance of the Binomial distribution class with parameters P = 0.2, N = 20 var binomial = new Binomial(0.2, 20); MathDisplay.WriteLine(@"1. Initialize the new instance of the Binomial distribution class with parameters P = {0}, N = {1}", binomial.P, binomial.N); MathDisplay.WriteLine(); // 2. Distributuion properties: MathDisplay.WriteLine(@"2. {0} distributuion properties:", binomial); // Cumulative distribution function MathDisplay.WriteLine(@"{0} - Сumulative distribution at location '3'", binomial.CumulativeDistribution(3).ToString(" #0.00000;-#0.00000")); // Probability density MathDisplay.WriteLine(@"{0} - Probability mass at location '3'", binomial.Probability(3).ToString(" #0.00000;-#0.00000")); // Log probability density MathDisplay.WriteLine(@"{0} - Log probability mass at location '3'", binomial.ProbabilityLn(3).ToString(" #0.00000;-#0.00000")); // Entropy MathDisplay.WriteLine(@"{0} - Entropy", binomial.Entropy.ToString(" #0.00000;-#0.00000")); // Largest element in the domain MathDisplay.WriteLine(@"{0} - Largest element in the domain", binomial.Maximum.ToString(" #0.00000;-#0.00000")); // Smallest element in the domain MathDisplay.WriteLine(@"{0} - Smallest element in the domain", binomial.Minimum.ToString(" #0.00000;-#0.00000")); // Mean MathDisplay.WriteLine(@"{0} - Mean", binomial.Mean.ToString(" #0.00000;-#0.00000")); // Median MathDisplay.WriteLine(@"{0} - Median", binomial.Median.ToString(" #0.00000;-#0.00000")); // Mode MathDisplay.WriteLine(@"{0} - Mode", binomial.Mode.ToString(" #0.00000;-#0.00000")); // Variance MathDisplay.WriteLine(@"{0} - Variance", binomial.Variance.ToString(" #0.00000;-#0.00000")); // Standard deviation MathDisplay.WriteLine(@"{0} - Standard deviation", binomial.StdDev.ToString(" #0.00000;-#0.00000")); // Skewness MathDisplay.WriteLine(@"{0} - Skewness", binomial.Skewness.ToString(" #0.00000;-#0.00000")); MathDisplay.WriteLine(); // 3. Generate 10 samples of the Binomial distribution MathDisplay.WriteLine(@"3. Generate 10 samples of the Binomial distribution"); for (var i = 0; i < 10; i++) { MathDisplay.Write(binomial.Sample().ToString("N05") + @" "); } MathDisplay.FlushBuffer(); MathDisplay.WriteLine(); MathDisplay.WriteLine(); // <a href="http://en.wikipedia.org/wiki/Bernoulli_distribution">Bernoulli distribution</a> MathDisplay.WriteLine("<b>Bernoulli distribution</b>"); // 1. Initialize the new instance of the Bernoulli distribution class with parameter P = 0.2 var bernoulli = new Bernoulli(0.2); MathDisplay.WriteLine(@"1. Initialize the new instance of the Bernoulli distribution class with parameter P = {0}", bernoulli.P); MathDisplay.WriteLine(); // 2. Distributuion properties: MathDisplay.WriteLine(@"2. {0} distributuion properties:", bernoulli); // Cumulative distribution function MathDisplay.WriteLine(@"{0} - Сumulative distribution at location '3'", bernoulli.CumulativeDistribution(3).ToString(" #0.00000;-#0.00000")); // Probability density MathDisplay.WriteLine(@"{0} - Probability mass at location '3'", bernoulli.Probability(3).ToString(" #0.00000;-#0.00000")); // Log probability density MathDisplay.WriteLine(@"{0} - Log probability mass at location '3'", bernoulli.ProbabilityLn(3).ToString(" #0.00000;-#0.00000")); // Entropy MathDisplay.WriteLine(@"{0} - Entropy", bernoulli.Entropy.ToString(" #0.00000;-#0.00000")); // Largest element in the domain MathDisplay.WriteLine(@"{0} - Largest element in the domain", bernoulli.Maximum.ToString(" #0.00000;-#0.00000")); // Smallest element in the domain MathDisplay.WriteLine(@"{0} - Smallest element in the domain", bernoulli.Minimum.ToString(" #0.00000;-#0.00000")); // Mean MathDisplay.WriteLine(@"{0} - Mean", bernoulli.Mean.ToString(" #0.00000;-#0.00000")); // Mode MathDisplay.WriteLine(@"{0} - Mode", bernoulli.Mode.ToString(" #0.00000;-#0.00000")); // Variance MathDisplay.WriteLine(@"{0} - Variance", bernoulli.Variance.ToString(" #0.00000;-#0.00000")); // Standard deviation MathDisplay.WriteLine(@"{0} - Standard deviation", bernoulli.StdDev.ToString(" #0.00000;-#0.00000")); // Skewness MathDisplay.WriteLine(@"{0} - Skewness", bernoulli.Skewness.ToString(" #0.00000;-#0.00000")); MathDisplay.WriteLine(); // 3. Generate 10 samples of the Bernoulli distribution MathDisplay.WriteLine(@"3. Generate 10 samples of the Bernoulli distribution"); for (var i = 0; i < 10; i++) { MathDisplay.Write(bernoulli.Sample().ToString("N05") + @" "); } MathDisplay.FlushBuffer(); MathDisplay.WriteLine(); MathDisplay.WriteLine(); // <a href="http://en.wikipedia.org/wiki/Categorical_distribution">Categorical distribution</a> MathDisplay.WriteLine("<b>Categorical distribution</b>"); // 1. Initialize the new instance of the Categorical distribution class with parameters P = (0.1, 0.2, 0.25, 0.45) var binomialC = new Categorical(new[] { 0.1, 0.2, 0.25, 0.45 }); MathDisplay.WriteLine(@"1. Initialize the new instance of the Categorical distribution class with parameters P = (0.1, 0.2, 0.25, 0.45)"); MathDisplay.WriteLine(); // 2. Distributuion properties: MathDisplay.WriteLine(@"2. {0} distributuion properties:", binomialC); // Cumulative distribution function MathDisplay.WriteLine(@"{0} - Сumulative distribution at location '3'", binomialC.CumulativeDistribution(3).ToString(" #0.00000;-#0.00000")); // Probability density MathDisplay.WriteLine(@"{0} - Probability mass at location '3'", binomialC.Probability(3).ToString(" #0.00000;-#0.00000")); // Log probability density MathDisplay.WriteLine(@"{0} - Log probability mass at location '3'", binomialC.ProbabilityLn(3).ToString(" #0.00000;-#0.00000")); // Entropy MathDisplay.WriteLine(@"{0} - Entropy", binomialC.Entropy.ToString(" #0.00000;-#0.00000")); // Largest element in the domain MathDisplay.WriteLine(@"{0} - Largest element in the domain", binomialC.Maximum.ToString(" #0.00000;-#0.00000")); // Smallest element in the domain MathDisplay.WriteLine(@"{0} - Smallest element in the domain", binomialC.Minimum.ToString(" #0.00000;-#0.00000")); // Mean MathDisplay.WriteLine(@"{0} - Mean", binomialC.Mean.ToString(" #0.00000;-#0.00000")); // Median MathDisplay.WriteLine(@"{0} - Median", binomialC.Median.ToString(" #0.00000;-#0.00000")); // Variance MathDisplay.WriteLine(@"{0} - Variance", binomialC.Variance.ToString(" #0.00000;-#0.00000")); // Standard deviation MathDisplay.WriteLine(@"{0} - Standard deviation", binomialC.StdDev.ToString(" #0.00000;-#0.00000")); // 3. Generate 10 samples of the Categorical distribution MathDisplay.WriteLine(@"3. Generate 10 samples of the Categorical distribution"); for (var i = 0; i < 10; i++) { MathDisplay.Write(binomialC.Sample().ToString("N05") + @" "); } MathDisplay.FlushBuffer(); MathDisplay.WriteLine(); MathDisplay.WriteLine(); // <a href="http://en.wikipedia.org/wiki/Conway%E2%80%93Maxwell%E2%80%93Poisson_distribution">ConwayMaxwellPoisson distribution</a> MathDisplay.WriteLine("<b>Conway Maxwell Poisson distribution</b>"); // 1. Initialize the new instance of the ConwayMaxwellPoisson distribution class with parameters Lambda = 2, Nu = 1 var conwayMaxwellPoisson = new ConwayMaxwellPoisson(2, 1); MathDisplay.WriteLine(@"1. Initialize the new instance of the ConwayMaxwellPoisson distribution class with parameters Lambda = {0}, Nu = {1}", conwayMaxwellPoisson.Lambda, conwayMaxwellPoisson.Nu); MathDisplay.WriteLine(); // 2. Distributuion properties: MathDisplay.WriteLine(@"2. {0} distributuion properties:", conwayMaxwellPoisson); // Cumulative distribution function MathDisplay.WriteLine(@"{0} - Сumulative distribution at location '3'", conwayMaxwellPoisson.CumulativeDistribution(3).ToString(" #0.00000;-#0.00000")); // Probability density MathDisplay.WriteLine(@"{0} - Probability mass at location '3'", conwayMaxwellPoisson.Probability(3).ToString(" #0.00000;-#0.00000")); // Log probability density MathDisplay.WriteLine(@"{0} - Log probability mass at location '3'", conwayMaxwellPoisson.ProbabilityLn(3).ToString(" #0.00000;-#0.00000")); // Smallest element in the domain MathDisplay.WriteLine(@"{0} - Smallest element in the domain", conwayMaxwellPoisson.Minimum.ToString(" #0.00000;-#0.00000")); // Mean MathDisplay.WriteLine(@"{0} - Mean", conwayMaxwellPoisson.Mean.ToString(" #0.00000;-#0.00000")); // Variance MathDisplay.WriteLine(@"{0} - Variance", conwayMaxwellPoisson.Variance.ToString(" #0.00000;-#0.00000")); // Standard deviation MathDisplay.WriteLine(@"{0} - Standard deviation", conwayMaxwellPoisson.StdDev.ToString(" #0.00000;-#0.00000")); MathDisplay.WriteLine(); // 3. Generate 10 samples of the ConwayMaxwellPoisson distribution MathDisplay.WriteLine(@"3. Generate 10 samples of the ConwayMaxwellPoisson distribution"); for (var i = 0; i < 10; i++) { MathDisplay.Write(conwayMaxwellPoisson.Sample().ToString("N05") + @" "); } MathDisplay.FlushBuffer(); MathDisplay.WriteLine(); MathDisplay.WriteLine(); // <a href="http://en.wikipedia.org/wiki/Discrete_uniform">DiscreteUniform distribution</a> MathDisplay.WriteLine("<b>Discrete Uniform distribution</b>"); // 1. Initialize the new instance of the DiscreteUniform distribution class with parameters LowerBound = 2, UpperBound = 10 var discreteUniform = new DiscreteUniform(2, 10); MathDisplay.WriteLine(@"1. Initialize the new instance of the DiscreteUniform distribution class with parameters LowerBound = {0}, UpperBound = {1}", discreteUniform.LowerBound, discreteUniform.UpperBound); MathDisplay.WriteLine(); // 2. Distributuion properties: MathDisplay.WriteLine(@"2. {0} distributuion properties:", discreteUniform); // Cumulative distribution function MathDisplay.WriteLine(@"{0} - Сumulative distribution at location '3'", discreteUniform.CumulativeDistribution(3).ToString(" #0.00000;-#0.00000")); // Probability density MathDisplay.WriteLine(@"{0} - Probability mass at location '3'", discreteUniform.Probability(3).ToString(" #0.00000;-#0.00000")); // Log probability density MathDisplay.WriteLine(@"{0} - Log probability mass at location '3'", discreteUniform.ProbabilityLn(3).ToString(" #0.00000;-#0.00000")); // Entropy MathDisplay.WriteLine(@"{0} - Entropy", discreteUniform.Entropy.ToString(" #0.00000;-#0.00000")); // Largest element in the domain MathDisplay.WriteLine(@"{0} - Largest element in the domain", discreteUniform.Maximum.ToString(" #0.00000;-#0.00000")); // Smallest element in the domain MathDisplay.WriteLine(@"{0} - Smallest element in the domain", discreteUniform.Minimum.ToString(" #0.00000;-#0.00000")); // Mean MathDisplay.WriteLine(@"{0} - Mean", discreteUniform.Mean.ToString(" #0.00000;-#0.00000")); // Median MathDisplay.WriteLine(@"{0} - Median", discreteUniform.Median.ToString(" #0.00000;-#0.00000")); // Mode MathDisplay.WriteLine(@"{0} - Mode", discreteUniform.Mode.ToString(" #0.00000;-#0.00000")); // Variance MathDisplay.WriteLine(@"{0} - Variance", discreteUniform.Variance.ToString(" #0.00000;-#0.00000")); // Standard deviation MathDisplay.WriteLine(@"{0} - Standard deviation", discreteUniform.StdDev.ToString(" #0.00000;-#0.00000")); // Skewness MathDisplay.WriteLine(@"{0} - Skewness", discreteUniform.Skewness.ToString(" #0.00000;-#0.00000")); MathDisplay.WriteLine(); // 3. Generate 10 samples of the DiscreteUniform distribution MathDisplay.WriteLine(@"3. Generate 10 samples of the DiscreteUniform distribution"); for (var i = 0; i < 10; i++) { MathDisplay.Write(discreteUniform.Sample().ToString("N05") + @" "); } MathDisplay.FlushBuffer(); MathDisplay.WriteLine(); MathDisplay.WriteLine(); // <a href="http://en.wikipedia.org/wiki/Geometric_distribution">Geometric distribution</a> MathDisplay.WriteLine("<b>Geometric distribution</b>"); // 1. Initialize the new instance of the Geometric distribution class with parameter P = 0.2 var geometric = new Geometric(0.2); MathDisplay.WriteLine(@"1. Initialize the new instance of the Geometric distribution class with parameter P = {0}", geometric.P); MathDisplay.WriteLine(); // 2. Distributuion properties: MathDisplay.WriteLine(@"2. {0} distributuion properties:", geometric); // Cumulative distribution function MathDisplay.WriteLine(@"{0} - Сumulative distribution at location '3'", geometric.CumulativeDistribution(3).ToString(" #0.00000;-#0.00000")); // Probability density MathDisplay.WriteLine(@"{0} - Probability mass at location '3'", geometric.Probability(3).ToString(" #0.00000;-#0.00000")); // Log probability density MathDisplay.WriteLine(@"{0} - Log probability mass at location '3'", geometric.ProbabilityLn(3).ToString(" #0.00000;-#0.00000")); // Entropy MathDisplay.WriteLine(@"{0} - Entropy", geometric.Entropy.ToString(" #0.00000;-#0.00000")); // Largest element in the domain MathDisplay.WriteLine(@"{0} - Largest element in the domain", geometric.Maximum.ToString(" #0.00000;-#0.00000")); // Smallest element in the domain MathDisplay.WriteLine(@"{0} - Smallest element in the domain", geometric.Minimum.ToString(" #0.00000;-#0.00000")); // Mean MathDisplay.WriteLine(@"{0} - Mean", geometric.Mean.ToString(" #0.00000;-#0.00000")); // Median MathDisplay.WriteLine(@"{0} - Median", geometric.Median.ToString(" #0.00000;-#0.00000")); // Mode MathDisplay.WriteLine(@"{0} - Mode", geometric.Mode.ToString(" #0.00000;-#0.00000")); // Variance MathDisplay.WriteLine(@"{0} - Variance", geometric.Variance.ToString(" #0.00000;-#0.00000")); // Standard deviation MathDisplay.WriteLine(@"{0} - Standard deviation", geometric.StdDev.ToString(" #0.00000;-#0.00000")); // Skewness MathDisplay.WriteLine(@"{0} - Skewness", geometric.Skewness.ToString(" #0.00000;-#0.00000")); MathDisplay.WriteLine(); // 3. Generate 10 samples of the Geometric distribution MathDisplay.WriteLine(@"3. Generate 10 samples of the Geometric distribution"); for (var i = 0; i < 10; i++) { MathDisplay.Write(geometric.Sample().ToString("N05") + @" "); } MathDisplay.FlushBuffer(); MathDisplay.WriteLine(); MathDisplay.WriteLine(); // <a href="http://en.wikipedia.org/wiki/Hypergeometric_distribution">Hypergeometric distribution</a> MathDisplay.WriteLine("<b>Hypergeometric distribution</b>"); // 1. Initialize the new instance of the Hypergeometric distribution class with parameters PopulationSize = 10, M = 2, N = 8 var hypergeometric = new Hypergeometric(30, 15, 10); MathDisplay.WriteLine(@"1. Initialize the new instance of the Hypergeometric distribution class with parameters Population = {0}, Success = {1}, Draws = {2}", hypergeometric.Population, hypergeometric.Success, hypergeometric.Draws); MathDisplay.WriteLine(); // 2. Distributuion properties: MathDisplay.WriteLine(@"2. {0} distributuion properties:", hypergeometric); // Cumulative distribution function MathDisplay.WriteLine(@"{0} - Сumulative distribution at location '3'", hypergeometric.CumulativeDistribution(3).ToString(" #0.00000;-#0.00000")); // Probability density MathDisplay.WriteLine(@"{0} - Probability mass at location '3'", hypergeometric.Probability(3).ToString(" #0.00000;-#0.00000")); // Log probability density MathDisplay.WriteLine(@"{0} - Log probability mass at location '3'", hypergeometric.ProbabilityLn(3).ToString(" #0.00000;-#0.00000")); // Largest element in the domain MathDisplay.WriteLine(@"{0} - Largest element in the domain", hypergeometric.Maximum.ToString(" #0.00000;-#0.00000")); // Smallest element in the domain MathDisplay.WriteLine(@"{0} - Smallest element in the domain", hypergeometric.Minimum.ToString(" #0.00000;-#0.00000")); // Mean MathDisplay.WriteLine(@"{0} - Mean", hypergeometric.Mean.ToString(" #0.00000;-#0.00000")); // Mode MathDisplay.WriteLine(@"{0} - Mode", hypergeometric.Mode.ToString(" #0.00000;-#0.00000")); // Variance MathDisplay.WriteLine(@"{0} - Variance", hypergeometric.Variance.ToString(" #0.00000;-#0.00000")); // Standard deviation MathDisplay.WriteLine(@"{0} - Standard deviation", hypergeometric.StdDev.ToString(" #0.00000;-#0.00000")); // Skewness MathDisplay.WriteLine(@"{0} - Skewness", hypergeometric.Skewness.ToString(" #0.00000;-#0.00000")); MathDisplay.WriteLine(); // 3. Generate 10 samples of the Hypergeometric distribution MathDisplay.WriteLine(@"3. Generate 10 samples of the Hypergeometric distribution"); for (var i = 0; i < 10; i++) { MathDisplay.Write(hypergeometric.Sample().ToString("N05") + @" "); } MathDisplay.FlushBuffer(); MathDisplay.WriteLine(); MathDisplay.WriteLine(); // <a href="http://en.wikipedia.org/wiki/Negative_binomial">NegativeBinomial distribution</a> MathDisplay.WriteLine("<b>Negative Binomial distribution</b>"); // 1. Initialize the new instance of the NegativeBinomial distribution class with parameters P = 0.2, R = 20 var negativeBinomial = new NegativeBinomial(20, 0.2); MathDisplay.WriteLine(@"1. Initialize the new instance of the NegativeBinomial distribution class with parameters P = {0}, N = {1}", negativeBinomial.P, negativeBinomial.R); MathDisplay.WriteLine(); // 2. Distributuion properties: MathDisplay.WriteLine(@"2. {0} distributuion properties:", negativeBinomial); // Cumulative distribution function MathDisplay.WriteLine(@"{0} - Сumulative distribution at location '3'", negativeBinomial.CumulativeDistribution(3).ToString(" #0.00000;-#0.00000")); // Probability density MathDisplay.WriteLine(@"{0} - Probability mass at location '3'", negativeBinomial.Probability(3).ToString(" #0.00000;-#0.00000")); // Log probability density MathDisplay.WriteLine(@"{0} - Log probability mass at location '3'", negativeBinomial.ProbabilityLn(3).ToString(" #0.00000;-#0.00000")); // Largest element in the domain MathDisplay.WriteLine(@"{0} - Largest element in the domain", negativeBinomial.Maximum.ToString(" #0.00000;-#0.00000")); // Smallest element in the domain MathDisplay.WriteLine(@"{0} - Smallest element in the domain", negativeBinomial.Minimum.ToString(" #0.00000;-#0.00000")); // Mean MathDisplay.WriteLine(@"{0} - Mean", negativeBinomial.Mean.ToString(" #0.00000;-#0.00000")); // Mode MathDisplay.WriteLine(@"{0} - Mode", negativeBinomial.Mode.ToString(" #0.00000;-#0.00000")); // Variance MathDisplay.WriteLine(@"{0} - Variance", negativeBinomial.Variance.ToString(" #0.00000;-#0.00000")); // Standard deviation MathDisplay.WriteLine(@"{0} - Standard deviation", negativeBinomial.StdDev.ToString(" #0.00000;-#0.00000")); // Skewness MathDisplay.WriteLine(@"{0} - Skewness", negativeBinomial.Skewness.ToString(" #0.00000;-#0.00000")); MathDisplay.WriteLine(); // 3. Generate 10 samples of the NegativeBinomial distribution MathDisplay.WriteLine(@"3. Generate 10 samples of the NegativeBinomial distribution"); for (var i = 0; i < 10; i++) { MathDisplay.Write(negativeBinomial.Sample().ToString("N05") + @" "); } MathDisplay.FlushBuffer(); MathDisplay.WriteLine(); MathDisplay.WriteLine(); // <a href="http://en.wikipedia.org/wiki/Poisson_distribution">Poisson distribution</a> MathDisplay.WriteLine("<b>Poisson distribution</b>"); // 1. Initialize the new instance of the Poisson distribution class with parameter Lambda = 1 var poisson = new Poisson(1); MathDisplay.WriteLine(@"1. Initialize the new instance of the Poisson distribution class with parameter Lambda = {0}", poisson.Lambda); MathDisplay.WriteLine(); // 2. Distributuion properties: MathDisplay.WriteLine(@"2. {0} distributuion properties:", poisson); // Cumulative distribution function MathDisplay.WriteLine(@"{0} - Сumulative distribution at location '3'", poisson.CumulativeDistribution(3).ToString(" #0.00000;-#0.00000")); // Probability density MathDisplay.WriteLine(@"{0} - Probability mass at location '3'", poisson.Probability(3).ToString(" #0.00000;-#0.00000")); // Log probability density MathDisplay.WriteLine(@"{0} - Log probability mass at location '3'", poisson.ProbabilityLn(3).ToString(" #0.00000;-#0.00000")); // Entropy MathDisplay.WriteLine(@"{0} - Entropy", poisson.Entropy.ToString(" #0.00000;-#0.00000")); // Largest element in the domain MathDisplay.WriteLine(@"{0} - Largest element in the domain", poisson.Maximum.ToString(" #0.00000;-#0.00000")); // Smallest element in the domain MathDisplay.WriteLine(@"{0} - Smallest element in the domain", poisson.Minimum.ToString(" #0.00000;-#0.00000")); // Mean MathDisplay.WriteLine(@"{0} - Mean", poisson.Mean.ToString(" #0.00000;-#0.00000")); // Median MathDisplay.WriteLine(@"{0} - Median", poisson.Median.ToString(" #0.00000;-#0.00000")); // Mode MathDisplay.WriteLine(@"{0} - Mode", poisson.Mode.ToString(" #0.00000;-#0.00000")); // Variance MathDisplay.WriteLine(@"{0} - Variance", poisson.Variance.ToString(" #0.00000;-#0.00000")); // Standard deviation MathDisplay.WriteLine(@"{0} - Standard deviation", poisson.StdDev.ToString(" #0.00000;-#0.00000")); // Skewness MathDisplay.WriteLine(@"{0} - Skewness", poisson.Skewness.ToString(" #0.00000;-#0.00000")); MathDisplay.WriteLine(); // 3. Generate 10 samples of the Poisson distribution MathDisplay.WriteLine(@"3. Generate 10 samples of the Poisson distribution"); for (var i = 0; i < 10; i++) { MathDisplay.Write(poisson.Sample().ToString("N05") + @" "); } MathDisplay.FlushBuffer(); MathDisplay.WriteLine(); MathDisplay.WriteLine(); // <a href="http://en.wikipedia.org/wiki/Zipf_distribution">Zipf distribution</a> MathDisplay.WriteLine("<b>Zipf distribution</b>"); // 1. Initialize the new instance of the Zipf distribution class with parameters S = 5, N = 10 var zipf = new Zipf(5, 10); MathDisplay.WriteLine(@"1. Initialize the new instance of the Zipf distribution class with parameters S = {0}, N = {1}", zipf.S, zipf.N); MathDisplay.WriteLine(); // 2. Distributuion properties: MathDisplay.WriteLine(@"2. {0} distributuion properties:", zipf); // Cumulative distribution function MathDisplay.WriteLine(@"{0} - Сumulative distribution at location '3'", zipf.CumulativeDistribution(3).ToString(" #0.00000;-#0.00000")); // Probability density MathDisplay.WriteLine(@"{0} - Probability mass at location '3'", zipf.Probability(3).ToString(" #0.00000;-#0.00000")); // Log probability density MathDisplay.WriteLine(@"{0} - Log probability mass at location '3'", zipf.ProbabilityLn(3).ToString(" #0.00000;-#0.00000")); // Entropy MathDisplay.WriteLine(@"{0} - Entropy", zipf.Entropy.ToString(" #0.00000;-#0.00000")); // Largest element in the domain MathDisplay.WriteLine(@"{0} - Largest element in the domain", zipf.Maximum.ToString(" #0.00000;-#0.00000")); // Smallest element in the domain MathDisplay.WriteLine(@"{0} - Smallest element in the domain", zipf.Minimum.ToString(" #0.00000;-#0.00000")); // Mean MathDisplay.WriteLine(@"{0} - Mean", zipf.Mean.ToString(" #0.00000;-#0.00000")); // Mode MathDisplay.WriteLine(@"{0} - Mode", zipf.Mode.ToString(" #0.00000;-#0.00000")); // Variance MathDisplay.WriteLine(@"{0} - Variance", zipf.Variance.ToString(" #0.00000;-#0.00000")); // Standard deviation MathDisplay.WriteLine(@"{0} - Standard deviation", zipf.StdDev.ToString(" #0.00000;-#0.00000")); // Skewness MathDisplay.WriteLine(@"{0} - Skewness", zipf.Skewness.ToString(" #0.00000;-#0.00000")); MathDisplay.WriteLine(); // 3. Generate 10 samples of the Zipf distribution MathDisplay.WriteLine(@"3. Generate 10 samples of the Zipf distribution"); for (var i = 0; i < 10; i++) { MathDisplay.Write(zipf.Sample().ToString("N05") + @" "); } MathDisplay.FlushBuffer(); MathDisplay.WriteLine(); MathDisplay.WriteLine(); }
public void ValidateMedianThrowsNotSupportedException() { var d = new Zipf(1.0, 5); Assert.Throws<NotSupportedException>(() => { var m = d.Median; }); }