Package ec.neat

Class NEATNode

java.lang.Object
ec.neat.NEATNode
All Implemented Interfaces:
Prototype, Setup, Serializable, Cloneable

public class NEATNode extends Object implements Prototype
NEATNode is the class to represent node in network, it stores status of the node in that network. A Node is either a NEURON or a SENSOR. If it's a sensor, it can be loaded with a value for output. If it's a neuron, it has a list of its incoming input signals. Based on the position of the node in network, we have output, input, bias and hidden nodes. We use INPUT nodes to load inputs, and get output from OUTPUT nodes.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    The activation function is used in for hidden node.
    static enum 
    The place this node could be.
    static enum 
    The type of a node.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    double
    The total activation entering the node.
    int
    Keeps track of which activation the node is currently in.
    boolean
    To make sure outputs are active.
    double
    The incoming activity before being processed.
    boolean
    When it's true, the node cannot be mutated.
    The activation function, use sigmoid for default, but can use some other choice, like ReLU.
    Distinguish the input node, hidden or output node.
    A list of incoming links, it is used to get activation status of the nodes on the other ends.
    int
    The depth of current node in current network, this field is used in counting max depth in a network.
    boolean
    Indicate if this node has been traversed in max depth counting.
    double
    Holds the previous step's activation for recurrence.
    int
    Node id for this node.
    boolean
    Indicates if the value of current node has been override by method other than network's activation.
    double
    Contains the activation value that will override this node's activation.
    static final String
     
    double
    Holds the activation BEFORE the previous step's This is necessary for a special recurrent case when the inNode of a recurrent link is one time step ahead of the outNode.
    Distinguish the Sensor node or other neuron node.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Set activation to the override value and turn off override.
    void
    Clear in incomgin links of this node, this is useful in create a new network from current genotype.
    Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.
    Returns the default base for this prototype.
    int
    depth(int d, NEATNetwork network, int maxDepth)
    Return the depth of this node in the network.
    Return a clone of this node, but with a empty incomingGenes list.
    boolean
     
    void
    Put all the field into initial status, this is useful in flushing the whole network.
    void
    Old flush code, used in C++ version.
    double
    Return the activation status of this node.
    double
    Return the last step activation if this node is active at last step.
    int
     
    void
    overrideOutput(double newOutput)
    Force an output value on the node.
    This method is used to output a gene that is same as the format in start genome file.
    void
    Reads a Node printed by printNode(...).
    void
    This method is used to read a node in start genome from file.
    void
    reset(NEATNode.NodeType nodeType, int id, NEATNode.NodePlace placement)
    Reset the node to initial status.
    boolean
    sensorLoad(double val)
    If this node is a sensor node, load this node with the given input
    void
    Sets up the object by reading it from the parameters stored in state, built off of the parameter base base.
    void
    sigmoid(double slope)
    The Sigmoid function.
    This method convert the gene in to human readable format.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • P_NODE

      public static final String P_NODE
      See Also:
    • activationCount

      public int activationCount
      Keeps track of which activation the node is currently in.
    • lastActivation

      public double lastActivation
      Holds the previous step's activation for recurrence.
    • previousLastActivation

      public double previousLastActivation
      Holds the activation BEFORE the previous step's This is necessary for a special recurrent case when the inNode of a recurrent link is one time step ahead of the outNode. The innode then needs to send from TWO time steps ago.
    • override

      public boolean override
      Indicates if the value of current node has been override by method other than network's activation.
    • overrideValue

      public double overrideValue
      Contains the activation value that will override this node's activation.
    • frozen

      public boolean frozen
      When it's true, the node cannot be mutated.
    • functionType

      public NEATNode.FunctionType functionType
      The activation function, use sigmoid for default, but can use some other choice, like ReLU.
    • type

      public NEATNode.NodeType type
      Distinguish the Sensor node or other neuron node.
    • geneticNodeLabel

      public NEATNode.NodePlace geneticNodeLabel
      Distinguish the input node, hidden or output node.
    • activeSum

      public double activeSum
      The incoming activity before being processed.
    • activation

      public double activation
      The total activation entering the node.
    • activeFlag

      public boolean activeFlag
      To make sure outputs are active.
    • incomingGenes

      public ArrayList<NEATGene> incomingGenes
      A list of incoming links, it is used to get activation status of the nodes on the other ends.
    • nodeId

      public int nodeId
      Node id for this node.
    • innerLevel

      public int innerLevel
      The depth of current node in current network, this field is used in counting max depth in a network.
    • isTraversed

      public boolean isTraversed
      Indicate if this node has been traversed in max depth counting.
  • Constructor Details

    • NEATNode

      public NEATNode()
  • Method Details

    • setup

      public void setup(EvolutionState state, Parameter base)
      Description copied from interface: Prototype
      Sets up the object by reading it from the parameters stored in state, built off of the parameter base base. If an ancestor implements this method, be sure to call super.setup(state,base); before you do anything else.

      For prototypes, setup(...) is typically called once for the prototype instance; cloned instances do not receive the setup(...) call. setup(...) may be called more than once; the only guarantee is that it will get called at least once on an instance or some "parent" object from which it was ultimately cloned.

      Specified by:
      setup in interface Prototype
      Specified by:
      setup in interface Setup
    • defaultBase

      public Parameter defaultBase()
      Description copied from interface: Prototype
      Returns the default base for this prototype. This should generally be implemented by building off of the static base() method on the DefaultsForm object for the prototype's package. This should be callable during setup(...).
      Specified by:
      defaultBase in interface Prototype
    • reset

      public void reset(NEATNode.NodeType nodeType, int id, NEATNode.NodePlace placement)
      Reset the node to initial status.
    • emptyClone

      public Object emptyClone()
      Return a clone of this node, but with a empty incomingGenes list.
    • clone

      public Object clone()
      Description copied from interface: Prototype
      Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.

      Typically this should be a full "deep" clone. However, you may share certain elements with other objects rather than clone hem, depending on the situation:

      • If you hold objects which are shared with other instances, don't clone them.
      • If you hold objects which must be unique, clone them.
      • If you hold objects which were given to you as a gesture of kindness, and aren't owned by you, you probably shouldn't clone them.
      • DON'T attempt to clone: Singletons, Cliques, or Populations, or Subpopulation.
      • Arrays are not cloned automatically; you may need to clone an array if you're not sharing it with other instances. Arrays have the nice feature of being copyable by calling clone() on them.

      Implementations.

      • If no ancestor of yours implements clone(), and you have no need to do clone deeply, and you are abstract, then you should not declare clone().
      • If no ancestor of yours implements clone(), and you have no need to do clone deeply, and you are not abstract, then you should implement it as follows:

         public Object clone() 
             {
             try
                 { 
                 return super.clone();
                 }
             catch ((CloneNotSupportedException e)
                 { throw new InternalError(); } // never happens
             }
                
      • If no ancestor of yours implements clone(), but you need to deep-clone some things, then you should implement it as follows:

         public Object clone() 
             {
             try
                 { 
                 MyObject myobj = (MyObject) (super.clone());
        
                 // put your deep-cloning code here...
                 }
             catch ((CloneNotSupportedException e)
                 { throw new InternalError(); } // never happens
             return myobj;
             } 
                
      • If an ancestor has implemented clone(), and you also need to deep clone some things, then you should implement it as follows:

         public Object clone() 
             { 
             MyObject myobj = (MyObject) (super.clone());
        
             // put your deep-cloning code here...
        
             return myobj;
             } 
                
      Specified by:
      clone in interface Prototype
      Overrides:
      clone in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • flushBack

      public void flushBack()
      Old flush code, used in C++ version. Put all the field into initial status, this is useful in flushing the whole network.
    • flush

      public void flush()
      Put all the field into initial status, this is useful in flushing the whole network.
    • getActivation

      public double getActivation()
      Return the activation status of this node.
    • getTimeDelayActivation

      public double getTimeDelayActivation()
      Return the last step activation if this node is active at last step.
    • activateWithOverride

      public void activateWithOverride()
      Set activation to the override value and turn off override.
    • overrideOutput

      public void overrideOutput(double newOutput)
      Force an output value on the node.
    • clearIncoming

      public void clearIncoming()
      Clear in incomgin links of this node, this is useful in create a new network from current genotype.
    • depth

      public int depth(int d, NEATNetwork network, int maxDepth)
      Return the depth of this node in the network.
    • readNode

      public void readNode(EvolutionState state, LineNumberReader reader) throws IOException
      Reads a Node printed by printNode(...). The default form simply reads a line into a string, and then calls readNodeFromString() on that line.
      Throws:
      IOException
    • readNodeFromString

      public void readNodeFromString(String string, EvolutionState state)
      This method is used to read a node in start genome from file.
    • toString

      public String toString()
      This method convert the gene in to human readable format. It can be useful in debugging.
      Overrides:
      toString in class Object
    • printNodeToString

      public String printNodeToString()
      This method is used to output a gene that is same as the format in start genome file.
    • sigmoid

      public void sigmoid(double slope)
      The Sigmoid function.
    • sensorLoad

      public boolean sensorLoad(double val)
      If this node is a sensor node, load this node with the given input