예제 #1
0
 /**
  * Old flush code, used in C++ version. Put all the field into initial
  * status, this is useful in flushing the whole network.
  */
 public void FlushBack()
 {
     if (Type != NodeType.SENSOR)
     {
         // SENSOR Node do not need to flush recursively
         if (ActivationCount > 0)
         {
             ActivationCount        = 0;
             Activation             = 0;
             LastActivation         = 0;
             PreviousLastActivation = 0;
         }
         for (int i = 0; i < IncomingGenes.Count; ++i)
         {
             NEATGene link = IncomingGenes[i];
             if (link.InNode.ActivationCount > 0)
             {
                 // NOTE : in here we have the add_weight field clear code
                 // for hebbian learning,
                 // we ignore it here since we are not using it
                 link.InNode.FlushBack();
             }
         }
     }
     else
     {
         // Flush the SENSOR
         ActivationCount        = 0;
         Activation             = 0;
         LastActivation         = 0;
         PreviousLastActivation = 0;
     }
 }
예제 #2
0
        public override bool Equals(object o)
        {
            NEATGene g = (NEATGene)o;

            if (InNodeId != g.InNodeId)
            {
                return(false);
            }
            if (OutNodeId != g.OutNodeId)
            {
                return(false);
            }
            if (!Weight.Equals(g.Weight))
            {
                return(false);
            }
            if (IsRecurrent != g.IsRecurrent)
            {
                return(false);
            }
            if (InnovationNumber != g.InnovationNumber)
            {
                return(false);
            }
            if (!MutationNumber.Equals(g.MutationNumber))
            {
                return(false);
            }
            return(Enable == g.Enable);
        }
예제 #3
0
        /**
         * Create the phenotype (network) from the genotype (genome). One main task
         * of method is to link the incomingGenes for each nodes.
         */
        public void BuildNetwork(NEATIndividual ind)
        {
            Individual = ind;

            ((List <NEATNode>)Nodes).AddRange(Individual.Nodes);

            List <NEATNode> inputList  = new List <NEATNode>();
            List <NEATNode> outputList = new List <NEATNode>();

            // NOTE: original code clone the node, thus organism and network each
            // have a node instance
            // but we do not clone it here
            foreach (NEATNode node in Individual.Nodes)
            {
                // we are rebuild the network, we clear all the node incomingGenes
                // as we will rebuild it later
                node.ClearIncoming();
                // Check for input or output designation of node
                if (node.GeneticNodeLabel == NEATNode.NodePlace.INPUT)
                {
                    inputList.Add(node);
                }
                else if (node.GeneticNodeLabel == NEATNode.NodePlace.BIAS)
                {
                    inputList.Add(node);
                }
                else if (node.GeneticNodeLabel == NEATNode.NodePlace.OUTPUT)
                {
                    outputList.Add(node);
                }
            }
            ((List <NEATNode>)Inputs).AddRange(inputList);
            ((List <NEATNode>)Outputs).AddRange(outputList);

            // prepare the incomingGenes for each node
            foreach (Gene g in Individual.genome)
            {
                // only deal with enabled nodes
                NEATGene link = (NEATGene)g;

                if (link.Enable)
                {
                    NEATNode outNode = link.OutNode;

                    outNode.IncomingGenes.Add(link);
                }
            }
        }
예제 #4
0
        public override object Clone()
        {
            // Gene::Gene(Gene *g,Trait *tp,NNode *inode,NNode *onode)
            // we do not clone the inNode and outNode instance
            NEATGene myobj = (NEATGene)base.Clone();

            myobj.Weight           = Weight;
            myobj.IsRecurrent      = IsRecurrent;
            myobj.InNodeId         = InNodeId;
            myobj.OutNodeId        = OutNodeId;
            myobj.InnovationNumber = InnovationNumber;
            myobj.MutationNumber   = MutationNumber;
            myobj.Enable           = Enable;
            myobj.Frozen           = Frozen;
            myobj.TimeDelay        = TimeDelay;

            return(myobj);
        }