/// <summary> /// compare the fitnesses of the two networks, save the best genes /// </summary> private void CalculateFitness() { fitnessSum = 0; DNA best = Population[0]; for (int i = 0; i < Population.Count; i++) { fitnessSum += Population[i].CalculateFitness(i); if (Generation > 1 && Population[i].Fitness >= 0 && !float.IsNaN(Population[i].Fitness) && !Population[i].Equals(null) && Generation > 1 && Population[i].Fitness <= 1) { Console.WriteLine("Current Fitness: {0},", Population[i].Fitness); FitnessList.Add(Population[i].Fitness); } if (Population[i].Fitness >= best.Fitness && Generation > 1) { best = Population[i]; best.Genes.minifiedPrint(); best.Genes.OutputSet.ForEach(x => Console.Write("{0}\t", x)); Console.WriteLine("\nCurrent best fitness: {0}", best.Fitness); // FitnessList.Add(best.Fitness); } } BestFitness = best.Fitness; BestGenes = ReflectionCloner.DeepFieldClone(best.Genes); }
/// <summary> /// Execute a step in the network /// </summary> /// <param name="networkRef">Network which will be executed</param> public void Spike(Network networkRef) { /* * Run through removing all of the spikes and recording an output * then run through adding all of the spikes that are recorded to have a spike go out to their network * Check if each spike sends spike across all axons or if it determines which to go through randomly. * Add needs to be done on a copy of the network BEFORE the removal happens (original network) */ List <Neuron> NeuronCopy = new List <Neuron>(this.Neurons); List <Neuron> NeuronAdditionCopy = ReflectionCloner.DeepFieldClone(this.Neurons); Parallel.ForEach(NeuronCopy, neuron => { if (neuron.RemoveSpikes(networkRef) == true) { if (neuron.IsOutput == true && this.IsEngaged == true) { this.OutputSet.Add(++this.CurrentOutput); this.IsClear = true; } else if (neuron.IsOutput == true && this.IsEngaged == false) { this.IsEngaged = true; } } else { if (neuron.IsOutput == true) { this.CurrentOutput++; } } }); Parallel.ForEach(NeuronAdditionCopy, neuron => { if (neuron.ActiveDelay == 0) { neuron.FireSpike(networkRef, neuron.Connections); } }); this.GlobalTimer++; }
public object Reflection() { return(ReflectionCloner.Copy(Original)); }