Exemplo n.º 1
0
        public GenesisPhenotype(Counter counter, Genome genome, int inputs, int outputs)
        {
            for (int i = 0; i < inputs; i++)
            {
                Neuron n = new Neuron(new Linear(), counter.GetNeuronInnovation());
                genome.AddNeuron(n);
                inputNeurons.Add(n);
            }

            for (int i = 0; i < outputs; i++)
            {
                Neuron n = new Neuron(new Linear(), counter.GetNeuronInnovation());
                genome.AddNeuron(n);
                outputNeurons.Add(n);
            }

            foreach (Neuron inputN in inputNeurons)
            {
                foreach (Neuron outputN in outputNeurons)
                {
                    Synapse s = new Synapse(counter.GetSynapseInnovation(), inputN.GetId, outputN.GetId, true);
                    genome.AddSynapse(s);
                    synapses.Add(s);
                }
            }
        }
Exemplo n.º 2
0
    /// <summary>
    /// Mates/combines 2 genomes into 2 different OffSpring Aka Crossover
    /// </summary>
    public void Mate(Genome Partner, Genome OffSpring1, Genome OffSpring2)
    {
        List <int> InovationNumbersList = GetInovationList().Union(Partner.GetInovationList()).ToList();

        List <Node> ToAddNodes = new List <Node>();

        foreach (int inovation in InovationNumbersList)
        {
            Neuron myNeuron      = GetNeuron(inovation);
            Neuron partnerNeuron = Partner.GetNeuron(inovation);

            if (myNeuron != null && partnerNeuron != null) //Both Genomes have the selected neuron, a random one will be selected, the oposing one is added to the other OffSpring
            {
                if (Random.value > 0.5f)                   //50% chance
                {
                    OffSpring1.AddNeuron(myNeuron, true);
                    OffSpring2.AddNeuron(partnerNeuron, true);
                }
                else
                {
                    OffSpring1.AddNeuron(partnerNeuron, true);
                    OffSpring2.AddNeuron(myNeuron, true);
                }
            }
            else if (myNeuron != null)//the neuron is not present in the Partner, it's labeled as either disjoint or excess, it will be added to both
            {
                OffSpring1.AddNeuron(myNeuron, true);
                OffSpring2.AddNeuron(myNeuron, true);
            }
            else if (partnerNeuron != null)
            {
                OffSpring1.AddNeuron(partnerNeuron, true);
                OffSpring2.AddNeuron(partnerNeuron, true);
            }
        }
    }
Exemplo n.º 3
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         genome.AddNeuron(1, ref innovations, 3);
         network.DestroyNetwork();
         network = genome.CreateNetwork();
         network.VisualizeNetwork(panel.GetComponent <RectTransform>(), perceptron, link, loopLink, false);
         print(genome.GetPerceptronGenes().Count);
     }
     if (Input.GetMouseButtonDown(1))
     {
         genome.AddLink(1, .5f, ref innovations, 3, 3);
         network.DestroyNetwork();
         network = genome.CreateNetwork();
         network.VisualizeNetwork(panel.GetComponent <RectTransform>(), perceptron, link, loopLink, false);
     }
 }