public static void mutateOverride(TablePredictor destination, TablePredictor original, Random rdm, double intensity) { original.table.CopyTo(destination.table, 0); destination.FactoryReset(); destination.species = original.species; destination.speciesDepth = original.speciesDepth + 1; //not very optimal int mutationCount = rdm.Next(2 + (int)(original.table.Length * intensity)); destination.mutationLeap = mutationCount; //int mutationCount = rdm.Next((int)(1 + original.table.Length * 0.3f)); int index; for (int i = 0; i < mutationCount; i++) { index = rdm.Next(destination.table.Length); if (index % 2 == 0) { destination.table[index] = (byte)rdm.Next(destination.symbolSize); } else { destination.table[index] = (byte)rdm.Next(destination.stateSize); } //inputIndex = rdm.Next(original.symbolSize); //stateIndex = rdm.Next(original.stateSize); //outputChange = (rdm.NextDouble() < 0.5f) ? 1 : 0; //Optimize this, for %2 check //if(outputChange == 0) // destination.table[inputIndex * original.tableStride + stateIndex * 2 + outputChange] = (byte)rdm.Next(destination.symbolSize); //else // destination.table[inputIndex * original.tableStride + stateIndex * 2 + outputChange] = (byte)rdm.Next(destination.stateSize); } destination.origin = OriginType.Mutation; }
public static void crossOverride(TablePredictor destination, TablePredictor parent1, TablePredictor parent2, Random rdm) { parent1.table.CopyTo(destination.table, 0); destination.FactoryReset(); //not very optimal int parent2Count = rdm.Next(destination.table.Length); destination.species = (parent2Count > destination.table.Length / 2) ? parent2.species : parent1.species; destination.speciesDepth = (parent1.speciesDepth > parent2.speciesDepth) ? parent1.speciesDepth : parent2.speciesDepth; int index; for (int i = 0; i < parent2Count; i++) { index = rdm.Next(destination.table.Length); destination.table[index] = parent2.table[index]; } destination.origin = OriginType.Cross; }
public static void randomOverride(TablePredictor destination, Random rdm) { destination.FactoryReset(); speciesCounter++; destination.species = speciesCounter; destination.speciesDepth = 0; for (int i = 0; i < destination.table.Length; i++) { //Check if slot is prediction output, or new state output if (i % 2 == 0) { destination.table[i] = (byte)rdm.Next(destination.symbolSize); } else { destination.table[i] = (byte)rdm.Next(destination.stateSize); } } destination.origin = OriginType.Random; }