コード例 #1
0
            public Dictionary <string, bool> evaluateNetwork(List <double> inputs)
            {
                //GET OUTPUT AS BOOLEAN
                Inputs = inputs.ToArray();      //SET INPUTS
                inputs.Add(1);
                if (inputs.Count != InputsCount)
                {
                    Console.WriteLine("Incorrect number of neural network inputs."); return(null);
                }

                for (int i = 0; i < InputsCount; i++)
                {
                    neurons[i].value = inputs[i];
                }

                foreach (int neuron in neurons.Keys.ToList()) //LOOP NEVER INPUTS
                {
                    double sum = 0;
                    for (int i = 0; i < neurons[neuron].incoming.Count; i++)
                    {
                        newGene   incoming = neurons[neuron].incoming[i];
                        newNeuron other    = neurons[incoming.into];
                        sum = sum + incoming.weight * other.value;                              //WEIGHT CALCULATION
                    }
                    if (neurons[neuron].incoming.Count > 0)
                    {
                        neurons[neuron].value = Sigmoid(sum);                                   //SIGMOID FUNCTION
                    }
                }

                Dictionary <string, bool> outputs = new Dictionary <string, bool>();

                for (int i = 0; i < OutputsCount; i++)
                {
                    string button = OutputKeys[i];                                              //GET BUTTON NAMES
                    if (neurons[MaxNodes + i].value > 0)
                    {
                        outputs.Add(button, true);                                              //OUTPUT IS TRUE
                    }
                    else
                    {
                        outputs.Add(button, false);                                             //OUTPUT IS FALSE
                    }
                    Outputs[i] = neurons[MaxNodes + i].value;                                   //SET OUTPUTS
                }

                //REFRESH IO PANEL
                NetMain.IO.setIO(Inputs, Outputs);
                NetMain.IO.SecureRefesh();

                return(outputs);
            }
コード例 #2
0
            public generateNetwork(newGenome genome)
            {
                //INPUTS
                for (int i = 0; i < InputsCount; i++)
                {
                    neurons[i] = new newNeuron();
                }

                //OUTPUTS
                for (int i = 0; i < OutputsCount; i++)
                {
                    neurons[MaxNodes + i] = new newNeuron();
                }

                genome.genes.Sort(); //table.sort(genome.genes, function(a, b) return (a.output < b.output) end)

                for (int i = 0; i < genome.genes.Count; i++)
                {
                    newGene gene = genome.genes[i];
                    if (gene.enabled)
                    {
                        if (!neurons.Keys.Contains(gene.output))
                        {
                            neurons[gene.output] = new newNeuron();
                        }

                        newNeuron neuron = neurons[gene.output];
                        neuron.incoming.Add(gene);
                        if (!neurons.Keys.Contains(gene.into))
                        {
                            neurons[gene.into] = new newNeuron();
                        }
                    }
                    genome.network = this;
                }
            }