public static NNChromosome[] MixChromosomes(NNChromosome a, NNChromosome b) { NNChromosome[] result = new NNChromosome[2]; result[0] = new NNChromosome(); result[1] = new NNChromosome(); for (int i = 0; i < a._chromosome.Count / 2; i++) { result[0]._chromosome.Add(a._chromosome[i]); } for (int i = a._chromosome.Count / 2; i < a._chromosome.Count; i++) { result[0]._chromosome.Add(b._chromosome[i]); } for (int i = 0; i < a._chromosome.Count / 2; i++) { result[1]._chromosome.Add(b._chromosome[i]); } for (int i = a._chromosome.Count / 2; i < a._chromosome.Count; i++) { result[1]._chromosome.Add(a._chromosome[i]); } return(result); }
public void SetWeights(NNChromosome newWeights) { int aux = 0; for (int i = 0; i < _layers.Count; i++) { for (int f = 0; f < _layers[i]._neuronsCount; f++) { for (int g = 0; g < _layers[i]._neurons[f]._weights.Count; g++) { _layers[i]._neurons[f]._weights[g] = newWeights._chromosome[aux]._weight; aux++; } } } }
public NNChromosome GetWeights() { NNChromosome _weights = new NNChromosome(); foreach (NeuronLayer layer in _layers) { foreach (Neuron neuron in layer._neurons) { foreach (float weight in neuron._weights) { _weights._chromosome.Add(new NNChromosome.Gen(weight)); } } } return(_weights); }
void Awake() { _brain = new NeuronalNetwork(inputs, outputs, hiddenLayers, neuronsPerLayer, linearGrade, bias); _brain.CreateNet(); _genome = _brain.GetWeights(); }