public void TestMutateInsertDelete() { var stopwatch = new Stopwatch(); var origList = Enumerable.Repeat(0, 1000).ToList(); var randoMutate = Rando.Fast(123); var randoInsert = Rando.Fast(1234); var randoDelete = Rando.Fast(12345); stopwatch.Start(); for (var i = 0; i < 1000; i++) { var insertedList = origList.MutateInsertDelete ( doMutation: randoMutate.ToBoolEnumerator(0.1), doInsertion: randoInsert.ToBoolEnumerator(0.1), doDeletion: randoDelete.ToBoolEnumerator(0.1), mutator: x => 0, inserter: x => 1, paddingFunc: x => 100000 ).ToList(); var sum = insertedList.Sum(t => t); Assert.AreEqual(insertedList.Count, 1000); } stopwatch.Stop(); Debug.WriteLine("Time(ms): {0}", stopwatch.ElapsedMilliseconds); }
public static ILayer <ISorterGenome> Recombinate ( this ILayer <ISorterGenome> sorterGenomeLayer, double recombinationRate, int seed ) { var rando = Rando.Fast(seed); var listGenomes = sorterGenomeLayer.Genomes .ToList(); var pairedGenomes = listGenomes.PairRandomly(rando.Spawn()); var recombinedGenomes = pairedGenomes.Select(p => p.Recombine(rando.Spawn(), recombinationRate)) .SelectMany(rp => new[] { rp.Item1, rp.Item2 }) .ToList(); //System.Diagnostics.Debug.WriteLine(recombinedGenomes.Select(g=>g.ParentGuid).Aggregate(string.Empty, (o,n) => o + " " + n.ToString())); return(Make ( recombinedGenomes, sorterGenomeLayer.Generation )); }
private ISorterCompParaPoolWorkflow UpdateGenomesStep(int seed) { var rando = Rando.Fast(seed); return(new SorterCompParaPoolWorkflowImpl ( compWorkflowState: CompWorkflowState.ReproGenomes, sorterLayer: Layer.Make( generation: Generation + 1, genomes: SorterLayerEval.GenomeEvals .SubSortShuffle(t => t.Score, rando.NextInt()) .Select(e => e.Genome) .Take(SorterCompParaPoolParams.PopulationSize) ), switchableGroupLayer: Layer.Make( generation: Generation + 1, genomes: SwitchableGroupLayerEval.GenomeEvals .SubSortShuffle(t => t.Score, rando.NextInt()) .Select(e => e.Genome) .Take(SorterCompParaPoolParams.SwitchableLayerStartingGenomeCount) ), compParaPool: null, sorterLayerEval: null, switchableGroupLayerEval: null, sorterCompParaPoolParams: SorterCompParaPoolParams, generation: Generation + 1 )); }
public static ISorterCompParaPoolWorkflow Make( int seed, SwitchableGroupGenomeType switchableGroupGenomeType, int keyCount, int keyPairCount, int switchableGroupSize, SorterCompParaPoolParams sorterCompParaPoolParams ) { var randy = Rando.Fast(seed); return(new SorterCompParaPoolWorkflowImpl ( sorterLayer: SorterLayer.Create ( seed: randy.NextInt(), genomeCount: sorterCompParaPoolParams.PopulationSize, keyCount: keyCount, keyPairCount: keyPairCount ), switchableGroupLayer: SwitchableLayer.Create ( seed: randy.NextInt(), switchableGroupGenomeType: switchableGroupGenomeType, genomeCount: sorterCompParaPoolParams.SwitchableLayerStartingGenomeCount, keyCount: keyCount, groupSize: switchableGroupSize ), sorterCompParaPoolParams: sorterCompParaPoolParams, generation: 0 )); }
public static Func <ISwitchableGroupGenome, int, Guid, ISwitchableGroupGenome> SwitchableGroupPropigator ( double mutationRate, double insertionRate, double deletionRate ) { return((sg, i, guid) => { var randy = Rando.Fast(i); return SwitchableGroupGenome.Make ( guid: guid, parentGuid: sg.Guid, keyCount: sg.KeyCount, chromosome: sg.CopyChromosome ( randy: randy, mutationRate: mutationRate, insertionRate: insertionRate, deletionRate: deletionRate ), switchableGroupGenomeType: sg.SwitchableGroupGenomeType, groupCount: sg.GroupCount ); }); }
public void TestSorterSpeed() { var stopwatch = new Stopwatch(); const int keyCount = 16; const int keyPairCount = 6400; const int sorterCount = 6000; const int switchableCount = 100; const int switchableGroupCount = 40; var rando = Rando.Fast(1243); //var sorter = Rando.Fast(1243).ToRandomEnumerator() // .Select(t => t.ToSorter(keyCount, keyPairCount, Guid.NewGuid())) // .First(); stopwatch.Start(); for (var i = 0; i < 10; i++) { var sorter = rando.Spawn().ToSorter2(keyCount, keyPairCount, Guid.NewGuid()); } stopwatch.Stop(); Debug.WriteLine("Time(ms): {0}", stopwatch.ElapsedMilliseconds); }
private IScpWorkflow ReproStep(int seed) { var randy = Rando.Fast(seed); var sorterLayer1 = SorterLayer0.Reproduce ( seed: randy.NextInt(), newGenomeCount: ScpParams.ChildCount, mutationRate: ScpParams.SorterMutationRate, insertionRate: ScpParams.SorterMutationRate, deletionRate: ScpParams.SorterDeletionRate ); //sorterLayer1 = sorterLayer1.Recombinate(ScpParams.SorterRecombinationRate, randy.NextInt()); return(new ScpWorkflowImpl ( compWorkflowState: CompWorkflowState.RunCompetition, sorterLayer0: _sorterLayer0, sorterLayer1: sorterLayer1, compPool: CompPool, sorterLayerEval: SorterLayerEval, scpParams: ScpParams, generation: Generation, report: string.Empty )); }
public void TestListPropigatorMutate() { const int startLen = 40; const int finalLen = 40; var lp = new ListPropigator <int> ( deletor: Deletor, deletionFrequency: 0.0, inserter: Inserter, insertionFrequency: 0.0, mutator: Mutator, mutationFrequency: 1.0, finalIndex: finalLen ); var randy = Rando.Fast(123); var track = new Tuple <IImmutableList <int>, int> ( ImmutableList <int> .Empty.AddRange(Enumerable.Range(0, startLen)), 0 ); while (track.Item2 < lp.FinalIndex) { track = lp.Propigate(track.Item1, randy, track.Item2); } Assert.AreEqual(track.Item1.Count, finalLen); Assert.IsTrue(track.Item1.All(t => t == 55)); }
public void TestUpdateWithMergeAndTrack() { var tracker = ScpWorkflowTracker.Make(); var builder = ScpWorkflowBuilder.Make ( workFlowGuid: Guid.NewGuid(), repository: TestRepository.EntityRepository, sorterGroupGuid: TestRepository.SorterLayerGuid, scpParamsGuid: TestRepository.ScpParamsGuid ); var updatedBuilder = builder; for (var i = 0; i < 5000; i++) { var seeds = Rando.Fast(i * 17).ToIntEnumerator().Take(5).ToList(); updatedBuilder = ScpWorkflowBuilder.UpdateAndTrack( builder: updatedBuilder, seeds: seeds, mergeWithPrev: true, tracker: tracker ); System.Diagnostics.Debug.WriteLine(tracker.PoolReport); tracker = tracker.Trim(1000); } Assert.AreEqual(updatedBuilder.InputEntities.Count, 3); Assert.IsNotNull(updatedBuilder.Entity); Assert.AreEqual(updatedBuilder.Seeds.Count(), 25); }
public void MutateChromosome() { const uint symbolCount = 32; const int sequenceLength = 10000; var chromo = Rando.Fast(123) .ToUintEnumerator(symbolCount) .Take(sequenceLength) .ToList() .ToChromosomeUint(symbolCount); const int seed = 1234; const double mutationRate = 0.1; const double insertionRate = 0.0; const double deletionRate = 0.0; var newChromo = chromo.StandardPropigate ( rando: Rando.Fast(seed), mutationRate: mutationRate, insertionRate: insertionRate, deletionRate: deletionRate ); var diffCount = newChromo.Sequence.GetDifferentItems(chromo.Sequence).Count(); Assert.AreEqual(newChromo.Sequence.Count, sequenceLength); Assert.IsTrue(diffCount < sequenceLength * mutationRate * 1.1); Assert.IsTrue(diffCount > sequenceLength * mutationRate * 0.9); }
public void TestGuidHashErgodictiy() { var guidsAndKeys = new Dictionary <Guid, int>(); var curGuid = Guid.NewGuid(); for (var i = 0; i < 100000; i++) { var curSeed = curGuid.ToHash(); guidsAndKeys[curGuid] = curSeed; var randy = Rando.Fast(curSeed); curGuid = randy.NextGuid(); guidsAndKeys[curGuid] = curSeed; curGuid = randy.NextGuid(); guidsAndKeys[curGuid] = curSeed; curGuid = randy.NextGuid(); guidsAndKeys[curGuid] = curSeed; curGuid = randy.NextGuid(); guidsAndKeys[curGuid] = curSeed; curGuid = randy.NextGuid(); guidsAndKeys[curGuid] = curSeed; curGuid = randy.NextGuid(); guidsAndKeys[curGuid] = curSeed; curGuid = randy.NextGuid(); } }
public static ISgMutantProfile ToSgMutantProfile ( this ISorterGenomeEval parentGenomeEval, ISorterMutateParams sorterMutateParams ) { var rando = Rando.Fast(sorterMutateParams.Seed); var layer = SorterLayer.Make(new[] { parentGenomeEval.SorterGenome }, 0) .Reproduce( seed: rando.NextInt(), newGenomeCount: sorterMutateParams.MutantCount, mutationRate: sorterMutateParams.SorterMutationRate, insertionRate: sorterMutateParams.SorterInsertionRate, deletionRate: sorterMutateParams.SorterDeletionRate ); var compPool = CompPool.MakeEmpty(parentGenomeEval.SorterGenome.KeyCount) .AddSorterEvalsParallel(layer.Genomes.Select(g => g.ToSorter())); return(new SgMutantProfileImpl( parentGenomeEval: parentGenomeEval, sorterGenomeEvals: compPool.SorterEvals.Where(ev => ev.SwitchUseCount <= sorterMutateParams.MaxScore) .Select(ev => SorterGenomeEval.Make ( sorterGenome: layer.GetGenome(ev.Sorter.Guid), parentGenomeEval: parentGenomeEval, sorterEval: ev, generation: 1, success: ev.Success )), scores: compPool.SorterEvals.Select(ev => (double)ev.SwitchUseCount), sorterMutateParams: sorterMutateParams )); }
public static List <Brush> RandomSolidBrushes(int seed, int brushCount) { if (_randomSolidBrushes != null) { return(_randomSolidBrushes); } _randomSolidBrushes = new List <Brush>(); var randy = Rando.Fast(seed); for (int i = 0; i < brushCount; i++) { var scb = new SolidColorBrush( new Color { ScA = (float)1.0, ScB = (float)randy.NextDouble(), ScG = (float)randy.NextDouble(), ScR = (float)randy.NextDouble() }); scb.Freeze(); _randomSolidBrushes.Add(scb); } return(_randomSolidBrushes); }
public void TestMethod2() { const int keyCount = 13; for (var numKeyPairs = 4; numKeyPairs < 30; numKeyPairs += 2) { for (var numSwitchables = 10; numSwitchables < 100; numSwitchables += 10) { var rando = Rando.Fast(numSwitchables + 377); IReadOnlyList <IKeyPair> sorterStage = KeyPairRepository.RandomKeyPairs(13, numKeyPairs, rando.NextInt()).ToList(); for (var rep = 0; rep < 10; rep++) { var reducedSorterStage = sorterStage.ToReducedSorterStage( rando.Spawn().ToSwitchableGroup <uint>(Guid.NewGuid(), keyCount, numSwitchables) ); //if (reducedSorterStage.KeyPairs.Count > 6) //{ // System.Diagnostics.Debug.WriteLine(sorterStage.Aggregate("\n", (o, n) => o + " [" + n.LowKey + "," + n.HiKey + "]")); // System.Diagnostics.Debug.WriteLine(reducedSorterStage.KeyPairs.Aggregate(String.Empty, (o,n)=> o + " [" + n.LowKey + "," + n.HiKey + "]" )); //} System.Diagnostics.Debug.WriteLine(String.Format("{0}\t{1}\t{2}\t{3}\t{4}", numKeyPairs, numSwitchables, reducedSorterStage.KeyPairs.Count, sorterStage.Aggregate("", (o, n) => o + " [" + n.LowKey + "," + n.HiKey + "]"), reducedSorterStage.KeyPairs.Aggregate(String.Empty, (o, n) => o + " [" + n.LowKey + "," + n.HiKey + "]") )); } } } }
public void TestCompParaPool() { var stopwatch = new Stopwatch(); const int keyCount = 16; const int keyPairCount = 1000; const int sorterCount = 100; const int switchableCount = 100; const int switchableGroupCount = 100; var sorters = Rando.Fast(123).ToRandomEnumerator() .Select(t => t.ToSorter(keyCount, keyPairCount, Guid.NewGuid())) .Take(sorterCount) .ToList(); var switchableGroups = Enumerable.Range(77, switchableGroupCount) .Select(i => Rando.Fast(1234 + i).ToSwitchableGroup <uint>(Guid.NewGuid(), keyCount, switchableCount)) .ToList(); stopwatch.Start(); var compParaPool = sorters.ToCompParaPoolParallel(switchableGroups); stopwatch.Stop(); Debug.WriteLine("Time(ms): {0}", stopwatch.ElapsedMilliseconds); }
public void TestUlongWithLimit() { const ulong maxVal = 100000000000; var avg = Rando.Fast(8823).ToUlongEnumerator(maxVal).Take(10000).Average(t => (long)t); Assert.IsTrue(avg < (maxVal * 0.53)); Assert.IsTrue(avg > (maxVal * 0.47)); }
public IList <Tuple <int, double> > NumTuples() { var rando = Rando.Fast(123); return(Enumerable.Range(0, 5).Repeat().Take(25) .Select(i => new Tuple <int, double>(i, rando.NextDouble())) .ToList()); }
public void TestUintWithLimit() { const uint maxVal = 100; var avg = Rando.Fast(8823).ToUintEnumerator(maxVal).Take(10000).Average(t => t); Assert.IsTrue(avg < (maxVal / 2)); Assert.IsTrue(avg > (maxVal / 2 - 1)); }
public static IEnumerable <IKeyPair> RandomKeyPairs(int keyCount, int numKeyPairs, int seed) { var rando = Rando.Fast(seed); for (var i = 0; i < numKeyPairs; i++) { yield return(AtIndex(rando.NextInt(KeyPairSetSizeForKeyCount(keyCount)))); } }
public void TestMutator() { var origList = Enumerable.Repeat(0, 10000).ToList(); var mutatedList = origList.Mutate(Rando.Fast(123).ToBoolEnumerator(0.1), t => 1).ToList(); var sum = mutatedList.Sum(t => t); Assert.IsTrue(sum < 1200); Assert.IsTrue(sum > 800); }
public void TestMutateInsertDelete2() { var stopwatch = new Stopwatch(); var origList = Enumerable.Repeat(0, 1000) .Select(i => new Tuple <int, int, int>(0, 0, 0)) .ToList(); var randoMutate = Rando.Fast(123); var randoInsert = Rando.Fast(1234); var randoDelete = Rando.Fast(12345); stopwatch.Start(); for (var i = 0; i < 1000; i++) { var insertedList = origList.MutateInsertDelete ( doMutation: randoMutate.ToBoolEnumerator(0.1), doInsertion: randoInsert.ToBoolEnumerator(0.1), doDeletion: randoDelete.ToBoolEnumerator(0.1), mutator: x => new Tuple <int, int, int>(1, x.Item2, x.Item3), inserter: x => new Tuple <int, int, int>(x.Item1, 1, x.Item3), paddingFunc: x => new Tuple <int, int, int>(0, 0, 1) ).ToList(); //for (var j = 0; j < 1000; j++) //{ // var tupy = insertedList[j]; // System.Diagnostics.Debug.WriteLine("{0}{1}{2}", tupy.Item1, tupy.Item2, tupy.Item3); //} //System.Diagnostics.Debug.WriteLine("***************"); //System.Diagnostics.Debug.WriteLine("***************"); //System.Diagnostics.Debug.WriteLine("***************"); //System.Diagnostics.Debug.WriteLine("***************"); Assert.AreEqual(insertedList.Count, 1000); var mutationSum = insertedList.Sum(t => t.Item1); Assert.IsTrue(mutationSum < 150); Assert.IsTrue(mutationSum > 50); var insertionSum = insertedList.Sum(t => t.Item2); Assert.IsTrue(insertionSum < 150); Assert.IsTrue(insertionSum > 50); var deletionSum = insertedList.Sum(t => t.Item3); Assert.IsTrue(deletionSum < 50); } stopwatch.Stop(); Debug.WriteLine("Time(ms): {0}", stopwatch.ElapsedMilliseconds); }
static IEnumerable <ISorter> RandomSorters(int seed, int keyCount, int switchLength) { var rando = Rando.Fast(seed); var randoK = rando.Spawn(); while (true) { yield return(rando.ToSorter2(keyCount, switchLength, randoK.NextGuid())); } }
public void TestRandomSorterGenome() { const int keyCount = 16; const int keyPairCount = 300; const int seed = 1222; var sorterGenome = Rando.Fast(seed).ToSorterGenome(keyCount, keyPairCount); Assert.IsTrue(sorterGenome.Chromosome.Sequence.Count == keyPairCount); }
public void TestRandomMake() { const int keyCount = 16; const int switchableCount = 100; var switchableGroup = Rando.Fast(123).ToSwitchableGroup <uint>(Guid.NewGuid(), keyCount, switchableCount); Assert.AreEqual(switchableGroup.KeyCount, keyCount); Assert.AreEqual(switchableGroup.Switchables.Count, switchableCount); }
public void TestRandomUintForSorted() { var randy = Rando.Fast(322); for (var i = 0; i < 10000; i++) { var testNum = (uint)randy.NextInt(); var testArray = testNum.ToBits(); Assert.AreEqual(SortedNumberEval.IsSorted(testNum), testArray.IsSorted()); } }
public void MakeChromosome() { const uint symbolCount = 32; const int sequenceLength = 1000; var chromo = Rando.Fast(123) .ToUintEnumerator(symbolCount) .Take(sequenceLength) .ToList() .ToChromosomeUint(symbolCount); Assert.AreEqual(chromo.Sequence.Count, sequenceLength); }
public void TestModNBlockUlong() { const int maxBits = 60; foreach (var value in Rando.Fast(123).ToUlongEnumerator(((ulong)1) << (maxBits - 1)).Take(50)) { var longBlock = GeneUlongModN.Make(value, maxBits); var serialized = longBlock.ToIntStream.ToArray(); var longBack = GeneUlongModN.Make(serialized, maxBits); Assert.AreEqual(longBack.Val, value); } }
public void UlongUintEnumerTest() { var startUlongs = Rando.Fast(123).ToUlongEnumerator() .Take(100).ToList(); var convUints = startUlongs.ToUints().ToList(); var endUlongs = convUints.ToUlongs().ToList(); var diffs = startUlongs.GetDiffs(endUlongs).ToList(); Assert.AreEqual(diffs.Count, 0); }
public void TestMethod1() { const int keyCount = 16; var sorterStage = Rando.Fast(123).ToPermutations(keyCount) .First() .Values .ToTuples() .ToKeyPairs(false) .ToSorterStage(keyCount); var layouts = sorterStage.ToStageLayouts().ToList(); }
public void PairRandomlyTest() { var aList = new List <string> { "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7" }; var bList = new List <string> { "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7" }; var outPairs = aList.Concat(bList).ToList().PairRandomly(Rando.Fast(123)).ToList(); Assert.AreEqual(outPairs.Count, aList.Count); }