public Genome(int size) { Random rnd = new Random(); weights = new float[size]; skills = new int[skillCount]; for (int i = 0; i < size; i++) { weights[i] = NN.NextDoubleRange(rnd, -1f, 1f); } }
public void Mutate(float value) { Random rnd = new Random(); for (int i = 0; i < weights.Length; i++) { if (NN.NextDoubleRange(rnd, 0, 1f) < 0.1) { weights[i] += NN.NextDoubleRange(rnd, -value, value); } } for (int i = 0; i < skillCount; i++) { if (NN.NextDoubleRange(rnd, 0, 1f) < 0.05) { skills[i] = rnd.Next(0, 4); } } }
public NN(params int[] sizes) { Random rnd = new Random(); layers = new Layer[sizes.Length]; for (int i = 0; i < sizes.Length; i++) { int nextSize = 0; if (i < sizes.Length - 1) { nextSize = sizes[i + 1]; } layers[i] = new Layer(sizes[i], nextSize); for (int j = 0; j < sizes[i]; j++) { for (int k = 0; k < nextSize; k++) { layers[i].weights[j, k] = NN.NextDoubleRange(rnd, -1f, 1f); } } } }