/// <summary> /// Propogate the value of the Neuron to each of the Neurons in the next layer /// through the output Dendrites. /// </summary> internal void Propogate() { foreach (var Dendrite in OutputConnections) { Dendrite.Propogate(); } }
/// <summary> /// Add the given Dendrite to the list of output connections. /// </summary> /// <param name="Connection"></param> internal void AddOutputConnection(Dendrite Connection) { OutputConnections.Add(Connection); }
/// <summary> /// Add the given Dendrite to the list of input connections. /// </summary> /// <param name="Connection"></param> internal void AddInputConnection(Dendrite Connection) { InputConnections.Add(Connection); }
internal static NeuralNet Breed(NeuralNet Father, NeuralNet Mother) { NeuralNet Child = new NeuralNet(NeuralLayerInfo); for (UInt16 LayerIter = 0; LayerIter < NeuralLayerInfo.Count(); LayerIter += 1) { NeuralLayer CurrentLayer = Child.NeuralLayers[LayerIter]; for (int NeuronIter = 0; NeuronIter < CurrentLayer.NeuronsInLayer.Count(); NeuronIter += 1) { Neuron CurrentNeuron = CurrentLayer.NeuronsInLayer[NeuronIter]; for (int DendriteIter = 0; DendriteIter < CurrentNeuron.OutputConnections.Count(); DendriteIter += 1) { Dendrite CurrentDendrite = CurrentNeuron.OutputConnections[DendriteIter]; if (GlobalRandom.NextDouble() < Math.Min(MaxMutationRate, (BaseMutationRate + (MutationRateIncreasePerFailedGeneration * GensSinceLastImprv)))) { CurrentDendrite.SetNewRandomConnectionStrength(); } else { // Children are always random switch (BreedingType) { case EnumBreedingType.AlwaysRandom: CurrentDendrite.SetNewRandomConnectionStrength(); break; // Child dendrite connection strength is the average of the mother and father case EnumBreedingType.AverageValue: CurrentDendrite.ConnectionStrength = (Father.NeuralLayers[LayerIter].NeuronsInLayer[NeuronIter].OutputConnections[DendriteIter].ConnectionStrength + Mother.NeuralLayers[LayerIter].NeuronsInLayer[NeuronIter].OutputConnections[DendriteIter].ConnectionStrength) / 2; break; // Child takes fathers or mothers dendrite connection strength default: case EnumBreedingType.Human: CurrentDendrite.ConnectionStrength = (GlobalRandom.NextDouble() < 0.5) ? Father.NeuralLayers[LayerIter].NeuronsInLayer[NeuronIter].OutputConnections[DendriteIter].ConnectionStrength : Mother.NeuralLayers[LayerIter].NeuronsInLayer[NeuronIter].OutputConnections[DendriteIter].ConnectionStrength; break; // Child dendrite connection strength pulled up and down by agreement between father and mother case EnumBreedingType.WeightedPull: if (Father.NeuralLayers[LayerIter].NeuronsInLayer[NeuronIter].OutputConnections[DendriteIter].ConnectionStrength >= 0.5 && Mother.NeuralLayers[LayerIter].NeuronsInLayer[NeuronIter].OutputConnections[DendriteIter].ConnectionStrength >= 0.5) { CurrentDendrite.ConnectionStrength = (float)Math.Min(1.0, Math.Max( Father.NeuralLayers[LayerIter].NeuronsInLayer[NeuronIter].OutputConnections[DendriteIter].ConnectionStrength, Mother.NeuralLayers[LayerIter].NeuronsInLayer[NeuronIter].OutputConnections[DendriteIter].ConnectionStrength ) + 0.01); } else if (Father.NeuralLayers[LayerIter].NeuronsInLayer[NeuronIter].OutputConnections[DendriteIter].ConnectionStrength < 0.5 && Mother.NeuralLayers[LayerIter].NeuronsInLayer[NeuronIter].OutputConnections[DendriteIter].ConnectionStrength < 0.5) { CurrentDendrite.ConnectionStrength = (float)Math.Max(0, Math.Min( Father.NeuralLayers[LayerIter].NeuronsInLayer[NeuronIter].OutputConnections[DendriteIter].ConnectionStrength, Mother.NeuralLayers[LayerIter].NeuronsInLayer[NeuronIter].OutputConnections[DendriteIter].ConnectionStrength ) - 0.01); } else { CurrentDendrite.ConnectionStrength = (GlobalRandom.NextDouble() < 0.5) ? Father.NeuralLayers[LayerIter].NeuronsInLayer[NeuronIter].OutputConnections[DendriteIter].ConnectionStrength : Mother.NeuralLayers[LayerIter].NeuronsInLayer[NeuronIter].OutputConnections[DendriteIter].ConnectionStrength; } break; } } } } } return(Child); }