GoalRefinement GenerateGoalRefinement(Goal parent) { var mode = (_options.MinGoalBranchingFactor + _options.MaxGoalBranchingFactor) / 2; var nbchild = Triangular.Sample(_random, _options.MinGoalBranchingFactor, _options.MaxGoalBranchingFactor, mode); var refinement = new GoalRefinement(_model) { ParentGoalIdentifier = parent.Identifier }; do { refinement.RefinementPattern = _faker.PickRandom <RefinementPattern> (); } while (refinement.RefinementPattern == RefinementPattern.None || refinement.RefinementPattern == RefinementPattern.Case); for (int i = 0; i < nbchild; i++) { var c = GenerateGoal(); refinement.Add(c); } _model.Add(refinement); return(refinement); }
public void ValidateToString() { System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; var n = new Triangular(0d, 2d, 1d); Assert.AreEqual("Triangular(Lower = 0, Upper = 2, Mode = 1)", n.ToString()); }
public string Run() { var triangulars = new Triangular().GenerateWhileLessThan(TWO_MILLION + 1001).ToList(); long area = 0; long minDiff = long.MaxValue; int lowindex = 1; long est; int estIdx = int.MaxValue; while (lowindex < estIdx) { est = TWO_MILLION / triangulars[lowindex]; estIdx = triangulars.BinarySearch(est); if (estIdx < 0) { estIdx = -estIdx; } estIdx--; if (Math.Abs(TWO_MILLION - triangulars[lowindex] * triangulars[estIdx]) < minDiff) { minDiff = Math.Abs(TWO_MILLION - triangulars[lowindex] * triangulars[estIdx]); area = lowindex * estIdx; } if (Math.Abs(TWO_MILLION - triangulars[lowindex] * triangulars[estIdx + 1]) < minDiff) { minDiff = Math.Abs(TWO_MILLION - triangulars[lowindex] * triangulars[estIdx + 1]); area = lowindex * estIdx + lowindex; } lowindex++; } return(area.ToString()); }
public void CanSampleSequence() { var n = new Triangular(0.1, 0.3, 0.2); var ied = n.Samples(); GC.KeepAlive(ied.Take(5).ToArray()); }
public Distribution(String DistributionName, params double[] vs) // 构造函数 根据名字初始化分布 { switch (DistributionName.ToUpper()) { case "NORMAL": normalDis = new Normal(vs[0], vs[1]); // double mean, double stddev break; case "CONTINUOUS": continuousUniformDis = new ContinuousUniform(vs[0], vs[1]); // int lower, int upper break; case "TRIANGULAR": triangularDis = new Triangular(vs[0], vs[1], vs[2]); //double lower, double upper, double mode (lower ≤ mode ≤ upper) break; case "STUDENTT": studentTDis = new StudentT(vs[0], vs[1], vs[2]); //double location, double scale, double freedom break; case "BERNOULLI": bernoulliDis = new Bernoulli(vs[0]); break; case "DISCRETEUNIFORM": discreteUniform = new DiscreteUniform((int)vs[0], (int)vs[1]); // int lower, int upper break; } this.DistributionName = DistributionName; }
public static double estimationDepensVD(double vl) { double dMin, dMax, vlMin, vlMax; if (vl < 0) { throw new ArgumentOutOfRangeException("valeur litigieuse inférieure à zero"); } else if (vl >= 0 && vl < 30000) { dMin = 1000; dMax = 9000; vlMin = 0; vlMax = 30000; } else if (vl >= 30000 && vl < 100000) { dMin = 3000; dMax = 15000; vlMin = 30000; vlMax = 100000; } else if (vl >= 100000 && vl < 250000) { dMin = 6000; dMax = 25000; vlMin = 100000; vlMax = 250000; } else if (vl >= 250000 && vl < 500000) { dMin = 9000; dMax = 40000; vlMin = 250000; vlMax = 500000; } else { throw new NotImplementedException(String.Format("Pas de formule pour les dépens pour VD pour VL={0}", vl)); } double dMode = dMin + 0.5 * (dMax - dMin) * (vl - vlMin) / (vlMax - vlMin); return(Triangular.Sample(dMin, dMax, dMode)); }
protected override PixelShaderInput InterpolatePoint(PixelShaderInput va, PixelShaderInput vb, PixelShaderInput vc, Vector2 p, out bool outOfRange) { var v = new PixelShaderInput(); var vatp = va.TransformedPosition; var vbtp = vb.TransformedPosition; var vctp = vc.TransformedPosition; var wp = Triangular.GetInterpolatedW(p, vatp, vbtp, vctp, out var successful); outOfRange = !successful; v.TransformedPosition = Triangular.InterpolateTransformedPosition(p, wp, vatp, vbtp, vctp, out successful); if (!outOfRange) { outOfRange = !successful; } v.TexCoords = Triangular.Interpolate(va.TexCoords, vb.TexCoords, vc.TexCoords, p, wp, vatp, vbtp, vctp, out successful); if (!outOfRange) { outOfRange = !successful; } return(v); }
public void CanSampleSequenceStatic() { var ied = Triangular.Samples(new Random(0), 2.0, 3.0, 2.5); GC.KeepAlive(ied.Take(5).ToArray()); ied = Triangular.Samples(10.0, 100.0, 30.0); GC.KeepAlive(ied.Take(5).ToArray()); }
public void CanCreateTriangular(double lower, double upper, double mode) { var n = new Triangular(lower, upper, mode); Assert.AreEqual(lower, n.LowerBound); Assert.AreEqual(upper, n.UpperBound); Assert.AreEqual(mode, n.Mode); }
public static double[] triangular(double v1, double v2, double v3, int num) { var t = new Triangular(v1, v2, v3); double[] ret = new double[num]; t.Samples(ret); return(ret); }
public void ResetAll() { Uniform.Reset(); Gaussian.Reset(); DoubleGaussian.Reset(); Exponential.Reset(); Triangular.Reset(); Sequence.Reset(); Grid.Reset(); Perlin.Reset(); GoldenRatio.Reset(); }
public double RandomValue(Estimate estimate) { // All values are the same, return the value if (estimate.Max - estimate.Min <= 0) { return(estimate.Max); } var triangle = new Triangular(estimate.Min, estimate.Max, estimate.Mode); return(triangle.Sample()); }
public void OnCollisionStay2D(Collision2D collision) { if (collision.collider.tag == "Player") { monsterSpeed = 0; } else { monsterSpeed = maxMonsterSpeed; } if (collision.collider.tag == "Magic") { Destroy(collision.gameObject); AnimatorStateInfo monsterName = gameObject.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0); int armor = 0; if (monsterName.IsName("Deserto0") || monsterName.IsName("Floresta0") || monsterName.IsName("Noturno0") || monsterName.IsName("Gelado0")) { armor = 25; } else if (monsterName.IsName("Deserto1") || monsterName.IsName("Floresta1") || monsterName.IsName("Noturno1") || monsterName.IsName("Gelado1")) { armor = 50; } else if (monsterName.IsName("Deserto2") || monsterName.IsName("Floresta2") || monsterName.IsName("Noturno2") || monsterName.IsName("Gelado2")) { armor = 75; } else if (monsterName.IsName("Deserto3") || monsterName.IsName("Floresta3") || monsterName.IsName("Noturno3") || monsterName.IsName("Gelado3")) { armor = 100; } int min_attack = 1; int max_attack = 100; int mode = (max_attack - armor <= min_attack ? min_attack : max_attack - armor); int damage = (int)Triangular.Sample(min_attack, max_attack, mode); healthbar.SetLife(healthbar.getLife() - damage); if (healthbar.getLife() == 0) { gameObject.SetActive(false); healthbar.SetLife(healthbar.getMaxLife()); healthbar.gameObject.SetActive(false); score_time.addScore(armor); } } }
public static int GetRandomTriangularFavoredIndex(int length) { if (length > Triangular.MaxInt32) { throw new ArgumentOutOfRangeException(nameof(length), length, $"Exceeds maximum Int32 value of {Triangular.MaxInt32}."); } var possibilities = (int)Triangular.Forward(length); var selected = RandomUtilities.Random.Next(possibilities); var r = Triangular.Reverse(selected); Debug.Assert(r < length); return(r); }
public static double estimateHonoraires(double valeurLitigieuse) { double min = 5 * 180 * 1.05 * 1.077; // 5h au tarif AJ, + débours et TVA double max = (61.38 / 100) * valeurLitigieuse; if (max < min) { return(min); // case where valeurLitigieuse is so small } else { return(Triangular.Sample(min, max, (max + min) / 2)); } }
public bool ShareVertex(Triangular t) { foreach (var v in p) { foreach (var tv in t.p) { if (v.Equals(tv)) { return(true); } } } return(false); }
public void GenerateDistPoints() { var N = 100000; var dt = new DataTable("data"); dt.Columns.Add("trig", typeof(double)); for (int i = 1; i < N; i++) { dt.Rows.Add( Triangular.Random(10, 50, 15) ); } Csv.Write(dt, fo2); }
public void Setup() { // Debug // Random rnd = new Random(0); // for repetability // Triangular.Samples(rnd, damageJitter, 0.9, 1.1, 1.0); Triangular.Samples(damageJitter, 0.9, 1.1, 1.0); for (int i = 5000; i < 25000; i += 2500) { multipliersLarge.Add(i); } for (int i = 500; i < 3500; i += 500) { multipliers.Add(i); } }
public void TestMeanAndVariacneConsistency() { const int numSamples = 100000; double mean, stdev; RunningStat rs = new RunningStat(); Random defaultrs = new Random(); Triangular tri = new Triangular(); rs.Clear(); var a = tri.LowerBound; var b = tri.UpperBound; var c = tri.Mode; mean = (a + b + c) / 3; stdev = Math.Sqrt((a * a + b * b + c * c - a * b - a * c - b * c) / 18); for (int i = 0; i < numSamples; ++i) { rs.Push(tri.Sample(defaultrs)); } PrintResult.CompareMeanAndVariance("Triangular", mean, stdev * stdev, rs.Mean(), rs.Variance()); }
ObstacleRefinement GenerateObstacleRefinement(Obstacle parent) { var mode = (_options.MinObstacleANDBranchingFactor + _options.MaxObstacleANDBranchingFactor) / 2; var nbchild = Triangular.Sample(_random, _options.MinObstacleANDBranchingFactor, _options.MaxObstacleANDBranchingFactor, mode); var refinement = new ObstacleRefinement(_model) { ParentObstacleIdentifier = parent.Identifier }; for (int i = 0; i < nbchild; i++) { var c = GenerateObstacle(); refinement.Add(c); } _model.Add(refinement); return(refinement); }
private Dictionary <double, double> GetOverlayData(double step, Chart cherte) { var min = cherte.Series[0].Points.Min(x => x.XValue); var max = cherte.Series[0].Points.Max(x => x.XValue); var overlayData = new Dictionary <double, double>(); Func <int, double, double> g = (tb, x) => { switch (tabControl.SelectedIndex) { case 0: return(1); case 1: return(1 / (max - min)); case 2: return(Triangular.PDF(Convert.ToDouble(tb_tre_max.Text), Convert.ToDouble(tb_tre_min.Text), Convert.ToDouble(tb_tre_moda.Text), x)); case 3: return(Erlang.PDF(Convert.ToInt32(nUD_erl_kol_norm.Value), 1.0 / Convert.ToDouble(tb_erl_moda.Text), x)); case 4: return(Poisson.PMF(Convert.ToDouble(tb_puas_lambd.Text), (int)x)); case 5: return(Normal.PDF(Convert.ToDouble(tb_norm_m.Text), Convert.ToDouble(tb_norm_d.Text), x)); case 6: return(Exponential.PDF(1.0 / Convert.ToDouble(tb_exp_m.Text), x)); default: return(double.NaN); } }; for (var x = min; x <= max; x += step) { overlayData[x] = g(tabControl.SelectedIndex, x); } return(overlayData); }
private ISimulationResult ToggleDistribution(DistributionInput distributionInput, DistributionType distributionType) { ISimulationResult distributions = null; switch (distributionType) { case DistributionType.Uniform: distributions = new Uniform().GetDistribution(distributionInput.Delegate, distributionInput.Iteration, distributionInput.UncertaintyArray); break; case DistributionType.Triangular: distributions = new Triangular().GetDistribution(distributionInput.Delegate, distributionInput.Iteration, distributionInput.UncertaintyArray); break; case DistributionType.Normal: break; case DistributionType.Log_Normal: break; } return(distributions); }
public void TriangularCompositeTest() { // First search for the lowest HCN that has more than 500 divisors. // Any number less that than, triangular or not, will have no more than 500 divisors, by definition of HCN. var index = 0; while (HighComposites.Singleton[index].CountOfDivisors <= 500) { index++; } Console.WriteLine($"First HCN with over 500 divisors is {HighComposites.Singleton[index].Value} with {HighComposites.Singleton[index].CountOfDivisors} divisors."); var triangular = Triangular.ClosestTriangularNumber(HighComposites.Singleton[index].Value); Console.WriteLine($"Jump-starting the search at triangular number of order {triangular.Order} and value {triangular.Value}."); while (triangular.Value.CountOfDivisors() < 500) { triangular = triangular.NextTriangularNumber(); } Console.WriteLine($"The secret number is the triangular number of order {triangular.Order} and value {triangular.Value}."); }
public void ValidateToString() { var n = new Triangular(0d, 2d, 1d); Assert.AreEqual("Triangular(Lower = 0, Upper = 2, Mode = 1)", n.ToString()); }
public void CanSample() { var n = new Triangular(0.1, 0.3, 0.2); n.Sample(); }
public void FailSampleSequenceStatic() { Assert.That(() => Triangular.Samples(new Random(0), 1.0, -1.0, 0.1).First(), Throws.ArgumentException); }
public void CanSampleStatic() { Triangular.Sample(new Random(0), 2.0, 3.0, 2.5); Triangular.Sample(10.0, 100.0, 30.0); }
/// <summary> /// Triangular Kernel: /// x => Math.Abs(x) <= 1.0 ? (1.0-Math.Abs(x)) : 0.0 /// </summary> public static double TriangularKernel(double x) { return(Triangular.PDF(-1.0, 1.0, 0.0, x)); }
/// <summary> /// Run example /// </summary> /// <a href="https://en.wikipedia.org/wiki/Triangular_distribution">Triangular distribution</a> public void Run() { // 1. Initialize var triangular = new Triangular(0, 1, 0.3); Console.WriteLine(@"1. Initialize the new instance of the Triangular distribution class with parameters Lower = {0}, Upper = {1}, Mode = {2}", triangular.LowerBound, triangular.UpperBound, triangular.Mode); Console.WriteLine(); // 2. Distributuion properties: Console.WriteLine(@"2. {0} distributuion properties:", triangular); // Cumulative distribution function Console.WriteLine(@"{0} - Сumulative distribution at location '0.3'", triangular.CumulativeDistribution(0.3).ToString(" #0.00000;-#0.00000")); // Probability density Console.WriteLine(@"{0} - Probability density at location '0.3'", triangular.Density(0.3).ToString(" #0.00000;-#0.00000")); // Log probability density Console.WriteLine(@"{0} - Log probability density at location '0.3'", triangular.DensityLn(0.3).ToString(" #0.00000;-#0.00000")); // Entropy Console.WriteLine(@"{0} - Entropy", triangular.Entropy.ToString(" #0.00000;-#0.00000")); // Largest element in the domain Console.WriteLine(@"{0} - Largest element in the domain", triangular.Maximum.ToString(" #0.00000;-#0.00000")); // Smallest element in the domain Console.WriteLine(@"{0} - Smallest element in the domain", triangular.Minimum.ToString(" #0.00000;-#0.00000")); // Mean Console.WriteLine(@"{0} - Mean", triangular.Mean.ToString(" #0.00000;-#0.00000")); // Median Console.WriteLine(@"{0} - Median", triangular.Median.ToString(" #0.00000;-#0.00000")); // Mode Console.WriteLine(@"{0} - Mode", triangular.Mode.ToString(" #0.00000;-#0.00000")); // Variance Console.WriteLine(@"{0} - Variance", triangular.Variance.ToString(" #0.00000;-#0.00000")); // Standard deviation Console.WriteLine(@"{0} - Standard deviation", triangular.StdDev.ToString(" #0.00000;-#0.00000")); // Skewness Console.WriteLine(@"{0} - Skewness", triangular.Skewness.ToString(" #0.00000;-#0.00000")); Console.WriteLine(); // 10 samples Console.WriteLine(@"3. Generate 10 samples of the Triangular distribution"); for (var i = 0; i < 10; i++) { Console.Write(triangular.Sample().ToString("N05") + @" "); } Console.WriteLine(); Console.WriteLine(); // 10000 samples with starting parameters Console.WriteLine(@"4. Generate 100000 samples of the Triangular({0}, {1}, {2}) distribution and display histogram", triangular.LowerBound, triangular.UpperBound, triangular.Mode); var data = new double[100000]; for (var i = 0; i < data.Length; i++) { data[i] = triangular.Sample(); } ConsoleHelper.DisplayHistogram(data); Console.WriteLine(); // 10000 with different parameters triangular.UpperBound = 10; triangular.Mode = 8; triangular.LowerBound = 2; Console.WriteLine(@"4. Generate 100000 samples of the Triangular({0}, {1}, {2}) distribution and display histogram", triangular.LowerBound, triangular.UpperBound, triangular.Mode); for (var i = 0; i < data.Length; i++) { data[i] = triangular.Sample(); } ConsoleHelper.DisplayHistogram(data); }
public static void triangular_cdf_test() //****************************************************************************80 // // Purpose: // // TRIANGULAR_CDF_TEST tests TRIANGULAR_CDF. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 31 March 2016 // // Author: // // John Burkardt // { int i; int seed = 123456789; Console.WriteLine(""); Console.WriteLine("TRIANGULAR_CDF_TEST"); Console.WriteLine(" TRIANGULAR_CDF evaluates the Triangular CDF;"); Console.WriteLine(" TRIANGULAR_CDF_INV inverts the Triangular CDF."); Console.WriteLine(" TRIANGULAR_PDF evaluates the Triangular PDF;"); double a = 1.0; double b = 10.0; Console.WriteLine(""); Console.WriteLine(" PDF parameter A = " + a + ""); Console.WriteLine(" PDF parameter B = " + b + ""); if (!Triangular.triangular_check(a, b)) { Console.WriteLine(""); Console.WriteLine("TRIANGULAR_CDF_TEST - Fatal error!"); Console.WriteLine(" The parameters are not legal."); return; } Console.WriteLine(""); Console.WriteLine(" X PDF CDF CDF_INV"); Console.WriteLine(""); for (i = 1; i <= 10; i++) { double x = Triangular.triangular_sample(a, b, ref seed); double pdf = Triangular.triangular_pdf(x, a, b); double cdf = Triangular.triangular_cdf(x, a, b); double x2 = Triangular.triangular_cdf_inv(cdf, a, b); 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) + ""); } }