static ZergCharacter() { GOAL_PRIORITIES = new Dictionary<State, byte>(){ {State.AttackGoal, 16}, {State.FeedGoal, 8}, {State.RetreatGoal, 1}, {State.ServeGoal, 2} }; var goals = new Stack<State>(); var goalEnums = (State[])Enum.GetValues(typeof(State)); foreach (var enumValue in goalEnums) { for (int i = 0; i < GOAL_PRIORITIES[enumValue]; i++) { goals.Push(enumValue); } } int count = goals.Count; RND = new DiscreteUniform(0, count - 1); GOALS_LOOKUP_TABLE = new State[count]; var rnd = new ContinuousUniform(0.0, 1.0); while (goals.Any()) { int idx = (int)Math.Round(rnd.Sample() * (--count), 0); GOALS_LOOKUP_TABLE[idx] = goals.Pop(); } }
private void CreateUniformFromString(string distributionString) { var regex = new Regex(@"Uniform\(\s*(\d+)\s*,\s*(\d+)\s*\)", RegexOptions.IgnoreCase); var match = regex.Match(distributionString); var min = int.Parse(match.Groups[1].Value); var max = int.Parse(match.Groups[2].Value); _discreteUniform = new DiscreteUniform(min, max); }
public void SetupDistributions() { dists = new IDistribution[8]; dists[0] = new Beta(1.0, 1.0); dists[1] = new ContinuousUniform(0.0, 1.0); dists[2] = new Gamma(1.0, 1.0); dists[3] = new Normal(0.0, 1.0); dists[4] = new Bernoulli(0.6); dists[5] = new Weibull(1.0, 1.0); dists[6] = new DiscreteUniform(1, 10); dists[7] = new LogNormal(1.0, 1.0); }
/// <summary> /// Run example /// </summary> /// <a href="http://en.wikipedia.org/wiki/Discrete_uniform">DiscreteUniform distribution</a> public void Run() { // 1. Initialize the new instance of the DiscreteUniform distribution class with parameters LowerBound = 2, UpperBound = 10 var discreteUniform = new DiscreteUniform(2, 10); Console.WriteLine(@"1. Initialize the new instance of the DiscreteUniform distribution class with parameters LowerBound = {0}, UpperBound = {1}", discreteUniform.LowerBound, discreteUniform.UpperBound); Console.WriteLine(); // 2. Distributuion properties: Console.WriteLine(@"2. {0} distributuion properties:", discreteUniform); // Cumulative distribution function Console.WriteLine(@"{0} - Сumulative distribution at location '3'", discreteUniform.CumulativeDistribution(3).ToString(" #0.00000;-#0.00000")); // Probability density Console.WriteLine(@"{0} - Probability mass at location '3'", discreteUniform.Probability(3).ToString(" #0.00000;-#0.00000")); // Log probability density Console.WriteLine(@"{0} - Log probability mass at location '3'", discreteUniform.ProbabilityLn(3).ToString(" #0.00000;-#0.00000")); // Entropy Console.WriteLine(@"{0} - Entropy", discreteUniform.Entropy.ToString(" #0.00000;-#0.00000")); // Largest element in the domain Console.WriteLine(@"{0} - Largest element in the domain", discreteUniform.Maximum.ToString(" #0.00000;-#0.00000")); // Smallest element in the domain Console.WriteLine(@"{0} - Smallest element in the domain", discreteUniform.Minimum.ToString(" #0.00000;-#0.00000")); // Mean Console.WriteLine(@"{0} - Mean", discreteUniform.Mean.ToString(" #0.00000;-#0.00000")); // Median Console.WriteLine(@"{0} - Median", discreteUniform.Median.ToString(" #0.00000;-#0.00000")); // Mode Console.WriteLine(@"{0} - Mode", discreteUniform.Mode.ToString(" #0.00000;-#0.00000")); // Variance Console.WriteLine(@"{0} - Variance", discreteUniform.Variance.ToString(" #0.00000;-#0.00000")); // Standard deviation Console.WriteLine(@"{0} - Standard deviation", discreteUniform.StdDev.ToString(" #0.00000;-#0.00000")); // Skewness Console.WriteLine(@"{0} - Skewness", discreteUniform.Skewness.ToString(" #0.00000;-#0.00000")); Console.WriteLine(); // 3. Generate 10 samples of the DiscreteUniform distribution Console.WriteLine(@"3. Generate 10 samples of the DiscreteUniform distribution"); for (var i = 0; i < 10; i++) { Console.Write(discreteUniform.Sample().ToString("N05") + @" "); } Console.WriteLine(); Console.WriteLine(); // 4. Generate 100000 samples of the DiscreteUniform(2, 10) distribution and display histogram Console.WriteLine(@"4. Generate 100000 samples of the DiscreteUniform(2, 10) distribution and display histogram"); var data = new double[100000]; for (var i = 0; i < data.Length; i++) { data[i] = discreteUniform.Sample(); } ConsoleHelper.DisplayHistogram(data); Console.WriteLine(); // 5. Generate 100000 samples of the DiscreteUniform(-10, 10) distribution and display histogram Console.WriteLine(@"5. Generate 100000 samples of the DiscreteUniform(-10, 10) distribution and display histogram"); discreteUniform.LowerBound = -10; discreteUniform.UpperBound = 10; for (var i = 0; i < data.Length; i++) { data[i] = discreteUniform.Sample(); } ConsoleHelper.DisplayHistogram(data); Console.WriteLine(); // 6. Generate 100000 samples of the DiscreteUniform(0, 40) distribution and display histogram Console.WriteLine(@"6. Generate 100000 samples of the DiscreteUniform(0, 40) distribution and display histogram"); discreteUniform.LowerBound = 0; discreteUniform.UpperBound = 40; for (var i = 0; i < data.Length; i++) { data[i] = discreteUniform.Sample(); } ConsoleHelper.DisplayHistogram(data); }
public void ValidateEntropy(int l, int u, double e) { var du = new DiscreteUniform(l, u); AssertHelpers.AlmostEqualRelative(e, du.Entropy, 14); }
public void CanCreateDiscreteUniform(int l, int u) { var du = new DiscreteUniform(l, u); Assert.AreEqual(l, du.LowerBound); Assert.AreEqual(u, du.UpperBound); }
public void ValidateToString() { var b = new DiscreteUniform(0, 10); Assert.AreEqual("DiscreteUniform(Lower = 0, Upper = 10)", b.ToString()); }
public void CanSampleSequence() { var n = new DiscreteUniform(0, 10); var ied = n.Samples(); GC.KeepAlive(ied.Take(5).ToArray()); }
public void ValidateCumulativeDistribution(int l, int u, double x, double cdf) { var b = new DiscreteUniform(l, u); Assert.AreEqual(cdf, b.CumulativeDistribution(x)); }
public void CanSample() { var n = new DiscreteUniform(0, 10); n.Sample(); }
public void ValidateProbabilityLn(int l, int u, int x, double dln) { var b = new DiscreteUniform(l, u); Assert.AreEqual(dln, b.ProbabilityLn(x)); }
public void ValidateMaximum() { var b = new DiscreteUniform(-10, 10); Assert.AreEqual(10, b.Maximum); }
public void ValidateMean(int l, int u, int m) { var du = new DiscreteUniform(l, u); Assert.AreEqual(m, du.Mean); }
public void ValidateSkewness(int l, int u) { var du = new DiscreteUniform(l, u); Assert.AreEqual(0.0, du.Skewness); }