private void Validate(NEATNetwork network) { Assert.AreEqual(1, network.OutputCount); Assert.AreEqual(2, network.InputCount); Assert.AreEqual(3, network.NetworkDepth); Assert.IsTrue(network.ActivationFunction is ActivationSigmoid); Assert.IsTrue(network.OutputActivationFunction is ActivationStep); Assert.AreEqual(0.0, ((ActivationStep)network.OutputActivationFunction).Center); Assert.AreEqual(1.0, ((ActivationStep)network.OutputActivationFunction).High); Assert.AreEqual(0.0, ((ActivationStep)network.OutputActivationFunction).Low); Assert.AreEqual(5, network.Neurons.Count); IDictionary <NEATNeuronType, NEATNeuron> neurons = new Dictionary <NEATNeuronType, NEATNeuron>(); foreach (NEATNeuron neuron in network.Neurons) { neurons[neuron.NeuronType] = neuron; } Assert.AreEqual(4, neurons.Count); NEATNeuron output = neurons[NEATNeuronType.Output]; NEATNeuron input = neurons[NEATNeuronType.Input]; Assert.AreEqual(1, input.OutputboundLinks.Count); Assert.AreEqual(0, input.InboundLinks.Count); Assert.AreEqual(0, output.OutputboundLinks.Count); Assert.AreEqual(1, output.InboundLinks.Count); }
private void Link( double weight, NEATNeuron from, NEATNeuron to, bool recurrent) { NEATLink l = new NEATLink(weight, from, to, recurrent); from.OutputboundLinks.Add(l); to.InboundLinks.Add(l); }
/// <summary> /// Convert the genes to an actual network. /// </summary> /// public override void Decode() { var pop = (NEATPopulation)Population; IList <NEATNeuron> neurons = new List <NEATNeuron>(); foreach (IGene gene in Neurons.Genes) { var neuronGene = (NEATNeuronGene)gene; var neuron = new NEATNeuron( neuronGene.NeuronType, neuronGene.Id, neuronGene.SplitY, neuronGene.SplitX, neuronGene.ActivationResponse); neurons.Add(neuron); } // now to create the links. foreach (IGene gene_0 in Links.Genes) { var linkGene = (NEATLinkGene)gene_0; if (linkGene.Enabled) { int element = GetElementPos(linkGene.FromNeuronID); NEATNeuron fromNeuron = neurons[element]; element = GetElementPos(linkGene.ToNeuronID); if (element == -1) { Console.Out.WriteLine("test"); } NEATNeuron toNeuron = neurons[element]; var link = new NEATLink(linkGene.Weight, fromNeuron, toNeuron, linkGene.Recurrent); fromNeuron.OutputboundLinks.Add(link); toNeuron.InboundLinks.Add(link); } } var network = new NEATNetwork(inputCount, outputCount, neurons, pop.NeatActivationFunction, pop.OutputActivationFunction, 0); network.Snapshot = pop.Snapshot; Organism = network; }
/// <summary> /// Convert the genes to an actual network. /// </summary> public override void Decode() { NEATPattern pattern = new NEATPattern(); IList <NEATNeuron> neurons = pattern.Neurons; foreach (IGene gene in Neurons.Genes) { NEATNeuronGene neuronGene = (NEATNeuronGene)gene; NEATNeuron neuron = new NEATNeuron( neuronGene.NeuronType, neuronGene.Id, neuronGene .SplitY, neuronGene.SplitX, neuronGene .ActivationResponse); neurons.Add(neuron); } // now to create the links. foreach (IGene gene in Links.Genes) { NEATLinkGene linkGene = (NEATLinkGene)gene; if (linkGene.Enabled) { int element = GetElementPos(linkGene.FromNeuronID); NEATNeuron fromNeuron = neurons[element]; element = GetElementPos(linkGene.ToNeuronID); NEATNeuron toNeuron = neurons[element]; NEATLink link = new NEATLink(linkGene.Weight, fromNeuron, toNeuron, linkGene.IsRecurrent); fromNeuron.OutputboundLinks.Add(link); toNeuron.InboundLinks.Add(link); } } pattern.NEATActivation = (((NEATTraining)GA).NeatActivationFunction); pattern.ActivationFunction = (((NEATTraining)GA).OutputActivationFunction); pattern.InputNeurons = (inputCount); pattern.OutputNeurons = (outputCount); pattern.Snapshot = ((NEATTraining)GA).Snapshot; Organism = pattern.Generate(); }
/// <summary> /// Convert the genes to an actual network. /// </summary> /// public override void Decode() { var pop = (NEATPopulation) Population; IList<NEATNeuron> neurons = new List<NEATNeuron>(); foreach (IGene gene in Neurons.Genes) { var neuronGene = (NEATNeuronGene) gene; var neuron = new NEATNeuron( neuronGene.NeuronType, neuronGene.Id, neuronGene.SplitY, neuronGene.SplitX, neuronGene.ActivationResponse); neurons.Add(neuron); } // now to create the links. foreach (IGene gene_0 in Links.Genes) { var linkGene = (NEATLinkGene) gene_0; if (linkGene.Enabled) { int element = GetElementPos(linkGene.FromNeuronID); NEATNeuron fromNeuron = neurons[element]; element = GetElementPos(linkGene.ToNeuronID); if (element == -1) { Console.Out.WriteLine("test"); } NEATNeuron toNeuron = neurons[element]; var link = new NEATLink(linkGene.Weight, fromNeuron, toNeuron, linkGene.Recurrent); fromNeuron.OutputboundLinks.Add(link); toNeuron.InboundLinks.Add(link); } } var network = new NEATNetwork(inputCount, outputCount, neurons, pop.NeatActivationFunction, pop.OutputActivationFunction, 0); network.Snapshot = pop.Snapshot; Organism = network; }
private NEATNetwork Create() { IList <NEATNeuron> neurons = new List <NEATNeuron>(); IActivationFunction afSigmoid = new ActivationSigmoid(); IActivationFunction afStep = new ActivationStep(); // create the neurons NEATNeuron input1 = new NEATNeuron( NEATNeuronType.Input, 1, 0.1, 0.2, 0.3); NEATNeuron input2 = new NEATNeuron( NEATNeuronType.Input, 2, 0.1, 0.2, 0.3); NEATNeuron bias = new NEATNeuron( NEATNeuronType.Bias, 3, 0.1, 0.2, 0.3); NEATNeuron hidden1 = new NEATNeuron( NEATNeuronType.Hidden, 4, 0.1, 0.2, 0.3); NEATNeuron output = new NEATNeuron( NEATNeuronType.Output, 5, 0.1, 0.2, 0.3); // add the neurons neurons.Add(input1); neurons.Add(input2); neurons.Add(hidden1); neurons.Add(bias); neurons.Add(output); // connect everything Link(0.01, input1, hidden1, false); Link(0.01, input2, hidden1, false); Link(0.01, bias, hidden1, false); Link(0.01, hidden1, output, false); // create the network NEATNetwork result = new NEATNetwork(2, 1, neurons, afSigmoid, afStep, 3); return(result); }