public void RandomAllRanges() { for (int n = 3; n < 20; n++) { var data = new RandomDistribution(42).IntegerUniform(n, 0, 100).Select(x => (double)x).ToArray(); Output.WriteLine("[DATA] " + string.Join("; ", data)); var buffer = new double[data.Length]; var rqq = new Rqq(data); for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { for (int k = 0; k < j - i; k++) { double actual = rqq.Select(i, j, k); Array.Copy(data, i, buffer, 0, j - i + 1); Array.Sort(buffer, 0, j - i + 1); double expected = buffer[k]; Output.WriteLine($"n = {n}, i = {i}, j = {j}, k = {k}, expected = {expected}, actual = {actual}"); if (actual != expected) { DumpRqqTree(rqq); } Assert.Equal(expected, actual); } } } } }
private void InitializeSyllables() { nameSyllables = new RandomDistribution<string>(); var longSyllables = new StringCombinator(); longSyllables.AddSet("b", "d", "g", "n", "r", "t"); longSyllables.AddSet("o", "u"); longSyllables.AddSet("f", "g", "l", "k", "m", "n", "s", "r"); foreach (var s in longSyllables.Enumerate()) { if (s.StartsWith("f") || s.StartsWith("s")) nameSyllables.Set(s, 0.4); else nameSyllables.Set(s, 1.0); } var shortSyllables = new StringCombinator(); shortSyllables.AddSet("a", "i", "e", "o", "u"); shortSyllables.AddSet("f", "g", "l", "k", "m", "n", "s", "r"); foreach (var s in shortSyllables.Enumerate()) { if (s.EndsWith("f") || s.EndsWith("s")) nameSyllables.Set(s, 1.0); else nameSyllables.Set(s, 3.5); } }
/// <summary> /// Returns a random number [0f,1f) with linear probability /// </summary> public float Next(RandomDistribution distribution = RandomDistribution.Linear) { if (!_initialzed) { throw new Exception($"{typeof(GlobalPRNG).Name} needs to be initialized. Call Init() first"); } switch (distribution) { case RandomDistribution.Linear: return(Linear()); break; case RandomDistribution.EaseInEaseOut: return(EaseInEaseOut(2)); break; case RandomDistribution.EaseInEaseOutCubic: return(EaseInEaseOut(3)); break; case RandomDistribution.Cubic: return(Cubic()); break; default: throw new ArgumentOutOfRangeException(nameof(distribution), distribution, null); } }
public void Run() { var random = new RandomDistribution(42); var data = new List <double>(); const int n = 20; for (int i = 0; i < n; i++) { data.AddRange(random.Gaussian(100, mean: 20 * i, stdDev: 5)); } var rqqIndexes = RqqPeltChangePointDetector.Instance.GetChangePointIndexes(data.ToArray()); var edIndexes = EdPeltChangePointDetector.Instance.GetChangePointIndexes(data.ToArray()); Console.WriteLine("RqqPelt EdPelt"); for (int i = 0, j = 0, k = 1; k < n; k++) { string rqqIndex = "-", edIndex = "-"; if (i < rqqIndexes.Length && rqqIndexes[i] < k * 100 + 10) { rqqIndex = rqqIndexes[i++].ToString(); } if (j < edIndexes.Length && edIndexes[j] < k * 100 + 10) { edIndex = edIndexes[j++].ToString(); } Console.WriteLine($"{rqqIndex.PadLeft(7)} {edIndex.PadLeft(6)}"); } }
private void InitializeLengths() { nameLengths = new RandomDistribution<int>(); nameLengths.Set(2, 0.70); nameLengths.Set(3, 0.29); nameLengths.Set(4, 0.01); }
void Initialize() { // dirty find distribution to visualize if none is set if (visualizeDistribution == null) { visualizeDistribution = FindObjectOfType <RandomDistribution>(); } numberLabels = GetComponentsInChildren <Text>(); }
public void Run() { var random = new RandomDistribution(42); var data = new List <double>(); data.AddRange(random.Gaussian(200, mean: 20, stdDev: 1)); data.AddRange(random.Gaussian(200, mean: 22, stdDev: 1)); const double binSize = 0.5; Console.WriteLine("*** Simple Histogram ***"); Console.WriteLine(SimpleHistogramBuilder.Instance.Build(data, binSize).ToString()); Console.WriteLine("*** Adaptive Histogram ***"); Console.WriteLine(AdaptiveHistogramBuilder.Instance.Build(data, binSize).ToString()); }
public void GaussianMeanProgression(int count, int meanFactor, int stdDev, int error) { var random = new RandomDistribution(42); var data = new List <double>(); for (int i = 0; i < count; i++) { data.AddRange(random.Gaussian(100, mean: meanFactor * i, stdDev: stdDev)); } var indexes = detector.GetChangePointIndexes(data.ToArray(), 20); Check100(count, error, indexes); }
void OnEnable() { // get target script targetScript = (RandomDistribution)target; serializedScript = new SerializedObject(targetScript); // get serialized properties distributionCurve = serializedScript.FindProperty("distributionCurve"); randomizeMode = serializedScript.FindProperty("randomizeMode"); prebakeResolution = serializedScript.FindProperty("prebakeResolution"); // instantiate the gui contents only once contentRandomizeMode = new GUIContent("Algorithm", "Pregenerate will generate a set of numbers on initialization. Brute Force does not do that, but may have worse performance."); contentPrebakeResolution = new GUIContent("Pregeneration Resolution"); }
public void GaussianStdDevProgression(int error, [NotNull] string stdDevValuesString) { var random = new RandomDistribution(42); var stdDevValues = stdDevValuesString.Split(';').Select(double.Parse).ToArray(); var data = new List <double>(); foreach (double stdDev in stdDevValues) { data.AddRange(random.Gaussian(100, mean: 0, stdDev: stdDev)); } var indexes = detector.GetChangePointIndexes(data.ToArray(), 20); Check100(stdDevValues.Length, error, indexes); }
public void BimodalProgression(int count, int meanFactor, int stdDev, int error) { var random = new RandomDistribution(42); var shuffler = new Shuffler(42); var data = new List <double>(); for (int i = 0; i < count; i++) { data.AddRange(random.Gaussian(30, 0, stdDev)); data.AddRange(random.Gaussian(70, (i + 1) * meanFactor, stdDev)); shuffler.Shuffle(data, i * 100, 100); } var indexes = detector.GetChangePointIndexes(data.ToArray(), 20); Check100(count, error, indexes); }
public void Run() { var random = new RandomDistribution(42); var data = new List <double>(); data.AddRange(random.Gaussian(200, mean: 20)); data.AddRange(random.Gaussian(200, mean: 22)); List <double> unimodal = new List <double>(), bimodal = new List <double>(), trimodal = new List <double>(); unimodal.AddRange(random.Gaussian(200, mean: 20)); bimodal.AddRange(random.Gaussian(200, mean: 20)); bimodal.AddRange(random.Gaussian(200, mean: 30)); trimodal.AddRange(random.Gaussian(200, mean: 20)); trimodal.AddRange(random.Gaussian(200, mean: 30)); trimodal.AddRange(random.Gaussian(200, mean: 40)); Console.WriteLine("Unimodal : " + MValueCalculator.Calculate(unimodal)); Console.WriteLine("Bimodal : " + MValueCalculator.Calculate(bimodal)); Console.WriteLine("Trimodal : " + MValueCalculator.Calculate(trimodal)); }
public void SetRandomDistribution(RandomDistribution distribution) { TCOD_random_set_distribution(Handle, distribution); }
private extern static void TCOD_random_set_distribution(IntPtr mersenne, RandomDistribution distribution);
private void InitializeTitles() { titleBearing = new RandomDistribution<bool>(); titleBearing.Set(true, 0.2); titleBearing.Set(false, 0.8); var monikers = new StringCombinator(); monikers.AddSet("rock", "stone", "mountain", "ale", "battle", "axe", "hammer", "shield", "blood", "iron", "steel"); monikers.AddSet("smasher", "climber", "hunter", "drinker", "seeker", "bearer", "cracker", "thirsty", "fist", "head", "skin", "foot", "beard"); titles = new RandomDistribution<string>(); foreach (var m in monikers.Enumerate()) titles.Set(string.Concat("the ", m.Capitalize()), 1.0); }