static void BuildLinearCase(int start, int stop, out double[] x, out double[] y, out double[] xtest, out double[] ytest) { const double yOffset = 2.0; int samples = stop - start + 1; ContinuousUniformDistribution uniform = new ContinuousUniformDistribution(); // build linear samples x = new double[samples]; y = new double[samples]; for (int i = 0; i < x.Length; i++) { int z = start + i; x[i] = z; y[i] = z + yOffset; // arbitrary small y-axis offset } // build linear test vectors randomly between the sample points xtest = new double[samples + 1]; ytest = new double[samples + 1]; if (samples == 1) { xtest[0] = start - uniform.NextDouble(); xtest[1] = start + uniform.NextDouble(); ytest[0] = ytest[1] = start + yOffset; } else { for (int i = 0; i < xtest.Length; i++) { double z = (i - 1) + uniform.NextDouble(); xtest[i] = z; ytest[i] = z + yOffset; } } }
public void ResetSampleGeneration() { phi1 = new double[frequencyIntervals, frequencyIntervals]; phi2 = new double[frequencyIntervals, frequencyIntervals]; var Phi = new ContinuousUniformDistribution(0d, 2d * Math.PI); for (int i = 0; i < frequencyIntervals; i++) { for (int j = 0; j < frequencyIntervals; j++) { phi1[i, j] = Phi.NextDouble(); phi2[i, j] = Phi.NextDouble(); } } }
public static double ContinuousUniformZeroToOne() { double value = zeroToOne.NextDouble(); Debug.Assert(value >= 0.0 && value <= 1.0); return(value); }
public void TryToSort() { if (mContUniformDist.NextDouble() > 0.5) { SortWordsByFrequency(); } }
private void precomputeSeeds(int seed, int amount) { var g = new MT19937Generator(seed); ContinuousUniformDistribution rand = new ContinuousUniformDistribution(g); seedList = new int[amount]; for (int i = 0; i < seedList.Length; i++) { seedList[i] = (int)(rand.NextDouble() * MAX); } }
public static async Task <List <(double, double)> > GenerateLineInsideCircle(int sizeOfCluster = 100, double circleRadius = 1.0) { var returnValue = GenerateRandomArray(sizeOfCluster, circleRadius); var randomAngles = new List <double>(); var distributor = new ContinuousUniformDistribution(); await Task.Run(() => { for (var i = 0; i < sizeOfCluster; ++i) { randomAngles.Add(distributor.NextDouble() * 1337); returnValue[i] = (returnValue[i].Item1 + Math.Sin(randomAngles[i]) * circleRadius, returnValue[i].Item2 + Math.Cos(randomAngles[i]) * circleRadius); } }); returnValue.AddRange(GenerateRandomArray(sizeOfCluster, circleRadius, false)); return(returnValue); }
public void UniformDistribution(double alpha, double beta) { var n = new ContinuousUniformDistribution(alpha, beta); var t = 0.0; foreach (var x in Enumerable.Range(0, RepetitionCount).Select(i => n.NextDouble())) { t += x; BoundRecorder.Observe(x); UnboundRecorder.Observe(x); } ApproxEquals(RepetitionCount, BoundRecorder.Count); ApproxEquals(RepetitionCount, UnboundRecorder.Count); ApproxEquals(t, BoundRecorder.Total()); ApproxEquals(t, UnboundRecorder.Total()); ApproxEquals(n.Mean, BoundRecorder.Mean()); ApproxEquals(n.Mean, UnboundRecorder.Mean()); ApproxEquals(n.Variance, BoundRecorder.Variance()); ApproxEquals(n.Variance, UnboundRecorder.Variance()); ApproxEquals(Math.Sqrt(n.Variance), BoundRecorder.StdDev()); ApproxEquals(Math.Sqrt(n.Variance), UnboundRecorder.StdDev()); }
public void UniformDistribution_WithUniformTimes(double alpha, double beta) { var n = new ContinuousUniformDistribution(alpha, beta); var t = 0.0; foreach (var i in Enumerable.Range(1, RepetitionCount)) { var x = n.NextDouble(); t += x; BoundRecorder.Observe(x, i); UnboundRecorder.Observe(x, i); } ApproxEquals(RepetitionCount, BoundRecorder.Count); ApproxEquals(RepetitionCount, UnboundRecorder.Count); ApproxEquals(t, BoundRecorder.Total()); ApproxEquals(t, UnboundRecorder.Total()); ApproxEquals(n.Mean, BoundRecorder.TimeMean(RepetitionCount + 1)); ApproxEquals(n.Mean, UnboundRecorder.TimeMean(RepetitionCount + 1)); ApproxEquals(n.Variance, BoundRecorder.TimeVariance(RepetitionCount + 1)); ApproxEquals(n.Variance, UnboundRecorder.TimeVariance(RepetitionCount + 1)); ApproxEquals(Math.Sqrt(n.Variance), BoundRecorder.TimeStdDev(RepetitionCount + 1)); ApproxEquals(Math.Sqrt(n.Variance), UnboundRecorder.TimeStdDev(RepetitionCount + 1)); }
private void placeAgents() { NormalDistribution normal = new NormalDistribution(); normal.Mu = 1.2; normal.Sigma = Math.Sqrt(0.3); MT19937Generator generator = new MT19937Generator(); StandardGenerator sg = new StandardGenerator(); ContinuousUniformDistribution x_distribution = new ContinuousUniformDistribution(generator); NormalDistribution y_distribution = new NormalDistribution(generator); y_distribution.Mu = corridor_width_ / 2; y_distribution.Sigma = sim_.getDefaultRadius(); for (int ped = 0; ped < ped_num_; ped++) { // Place Agent float x = (float)x_distribution.NextDouble() * corridor_length_ % corridor_length_; float y = (float)((y_distribution.NextDouble() * corridor_width_) - 9) % corridor_width_; Vector2 position = new Vector2(x, Math.Abs(y)); position = Vector2.rotation(position, corridor_angle_); sim_.addAgent(position, model_type_, follow_, group_); addAgent(prefab, new Vector3(position.x(), 0, position.y()), sim_.getDefaultRadius()); step_stop.Add(0); // Set agent max speeds sim_.setAgentMaxSpeed(ped, (float)normal.NextDouble()); if (sim_.getAgentMaxSpeed(ped) > 2.0f) { sim_.setAgentMaxSpeed(ped, 2.0f); } if (sim_.getAgentMaxSpeed(ped) < 0.3f) { sim_.setAgentMaxSpeed(ped, 0.3f); } // Set agent's goal /* Change the switch in case 2 like : * Instantiate 2 Agents (one at each side) in a geometric way * Add color and goals. */ switch (fluxes_) { case 1: { Vector2 corridor_end = new Vector2(corridor_length_ + 100, y); //Vector2 corridor_end = new Vector2(corridor_length_ + 12, y); corridor_end = Vector2.rotation(corridor_end, corridor_angle_); sim_.setAgentGoal(ped, corridor_end); break; } case 2: { if (ped < ped_num_ / 2) { Vector2 corridor_end = new Vector2(corridor_length_ + 1, y); corridor_end = Vector2.rotation(corridor_end, corridor_angle_); agents[ped].transform.GetComponent <MeshRenderer>().material.color = new Color(1, 0, 0); sim_.setAgentGoal(ped, corridor_end); } else { Vector2 corridor_start = new Vector2(-100, y); corridor_start = Vector2.rotation(corridor_start, corridor_angle_); agents[ped].transform.GetComponent <MeshRenderer>().material.color = new Color(0, 0, 1); sim_.setAgentGoal(ped, corridor_start); } break; } default: break; } } }
public override void setupScenario() { mainCam = GameObject.Find("Main Camera"); mainCam.transform.position = new Vector3(corridor_lenght / 2, 100, corridor_width / 2); sim_.setTimeStep(0.125f); sim_.setAgentDefaults(15.0f, 10, 5.0f, 5.0f, ped_radius_, 1.0f, new RVO.Vector2(0.0f, 0.0f)); plane.transform.localScale = new Vector3(corridor_lenght / 10, 1, corridor_width / 10); plane.transform.position = new Vector3(corridor_lenght / 2, 0, corridor_width / 2); NormalDist normal = new NormalDist(1.2, 0.3); System.Random generator_ = new System.Random(); MT19937Generator generator = new MT19937Generator(); StandardGenerator sg = new StandardGenerator(); ContinuousUniformDistribution x_distribution = new ContinuousUniformDistribution(generator); NormalDistribution y_distribution = new NormalDistribution(generator); y_distribution.Mu = corridor_width / 2; y_distribution.Sigma = sim_.getDefaultRadius(); for (int i = 0; i < agents_number; ++i) { float x = (float)x_distribution.NextDouble() * corridor_lenght % corridor_lenght; float y = (float)((y_distribution.NextDouble() * corridor_width) - 9) % corridor_width; RVO.Vector2 position = new RVO.Vector2(x, y); sim_.addAgent(position, 0, true, true, 15.0f, 10, 5.0f, 5.0f, 1, 1.0f, new RVO.Vector2(0, 0)); sim_.setAgentGoal(i, new RVO.Vector2(corridor_lenght * 4, y)); } IList <RVO.Vector2> north_Wall = new List <RVO.Vector2>(); north_Wall.Add(rotation(new RVO.Vector2(-100.0f, corridor_width), 0f)); north_Wall.Add(rotation(new RVO.Vector2(-100.0f, corridor_width + 1), 0f)); north_Wall.Add(rotation(new RVO.Vector2(100.0f + corridor_lenght, corridor_width + 1), 0f)); north_Wall.Add(rotation(new RVO.Vector2(100.0f + corridor_lenght, corridor_width), 0f)); sim_.addObstacle(north_Wall); GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = new Vector3(corridor_lenght / 2, 0, corridor_width + 0.5f); cube.transform.localScale = new Vector3(corridor_lenght - 0, 4, 1); IList <RVO.Vector2> south_Wall = new List <RVO.Vector2>(); south_Wall.Add(new RVO.Vector2(100 + corridor_lenght, 0)); south_Wall.Add(new RVO.Vector2(100 + corridor_lenght, -1)); south_Wall.Add(new RVO.Vector2(-100, -1)); south_Wall.Add(new RVO.Vector2(-100, 0)); sim_.addObstacle(south_Wall); List <RVO.Vector2> north_neck = new List <RVO.Vector2>(); north_neck.Add(rotation(new RVO.Vector2(corridor_lenght - corridor_width / 2, corridor_width), 90f)); north_neck.Add(rotation(new RVO.Vector2(corridor_lenght - corridor_width / 2, corridor_width + 1), 90f)); north_neck.Add(rotation(new RVO.Vector2(corridor_lenght + corridor_width / 2, corridor_width + 1), 90f)); north_neck.Add(rotation(new RVO.Vector2(corridor_lenght + corridor_width / 2, corridor_width), 90f)); sim_.addObstacle(north_neck); GameObject cube2 = GameObject.CreatePrimitive(PrimitiveType.Cube); cube2.transform.position = new Vector3(corridor_lenght / 2, 0, -0.5f); cube2.transform.localScale = new Vector3(corridor_lenght - 0, 4, 1); sim_.processObstacles(); sim_.kdTree_.buildAgentTree(false); }
public ScalarValue Function() { return(new ScalarValue(Distribution.NextDouble())); }
public float NextF() { return((float)cud.NextDouble()); }
public ScalarValue Function() { return(new ScalarValue(ran.NextDouble())); }