github.com/yaricom/goNEAT@v0.0.0-20210507221059-e2110b885482/neat/genetics/innovation.go (about)

     1  package genetics
     2  
     3  // This Innovation class serves as a way to record innovations specifically, so that an innovation in one genome can be
     4  // compared with other innovations in the same epoch, and if they are the same innovation, they can both be assigned the
     5  // same innovation number.
     6  //
     7  // This class can encode innovations that represent a new link forming, or a new node being added.  In each case, two
     8  // nodes fully specify the innovation and where it must have occurred (between them).
     9  type Innovation struct {
    10  
    11  	// Two nodes specify where the innovation took place
    12  	InNodeId       int
    13  	OutNodeId      int
    14  	// The number assigned to the innovation
    15  	InnovationNum  int64
    16  	// If this is a new node innovation, then there are 2 innovations (links) added for the new node
    17  	InnovationNum2 int64
    18  
    19  	// If a link is added, this is its weight
    20  	NewWeight      float64
    21  	// If a link is added, this is its connected trait index
    22  	NewTraitNum    int
    23  	// If a new node was created, this is its node_id
    24  	NewNodeId      int
    25  
    26  	// If a new node was created, this is the innovation number of the gene's link it is being stuck inside
    27  	OldInnovNum    int64
    28  
    29  	// Flag to indicate whether its innovation for recurrent link
    30  	IsRecurrent    bool
    31  
    32  	// Either NEWNODE or NEWLINK
    33  	innovationType innovationType
    34  }
    35  
    36  // Constructor for the new node case
    37  func NewInnovationForNode(node_in_id, node_out_id int, innovation_num1, innovation_num2 int64,
    38  				newnode_id int, old_innov_num int64) *Innovation {
    39  	return &Innovation {
    40  		innovationType:newNodeInnType,
    41  		InNodeId:node_in_id,
    42  		OutNodeId:node_out_id,
    43  		InnovationNum:innovation_num1,
    44  		InnovationNum2:innovation_num2,
    45  		NewNodeId:newnode_id,
    46  		OldInnovNum:old_innov_num,
    47  	}
    48  }
    49  
    50  // Constructor for new link case
    51  func NewInnovationForLink(node_in_id, node_out_id int, innovation_num int64, weight float64, trait_id int) *Innovation {
    52  	return &Innovation {
    53  		innovationType:newLinkInnType,
    54  		InNodeId:node_in_id,
    55  		OutNodeId:node_out_id,
    56  		InnovationNum:innovation_num,
    57  		NewWeight:weight,
    58  		NewTraitNum:trait_id,
    59  	}
    60  }
    61  
    62  //Constructor for a recur link
    63  func NewInnovationForRecurrentLink(node_in_id, node_out_id int, innovation_num int64, weight float64,
    64  					trait_id int, recur bool) *Innovation {
    65  	return &Innovation{
    66  		innovationType:newLinkInnType,
    67  		InNodeId:node_in_id,
    68  		OutNodeId:node_out_id,
    69  		InnovationNum:innovation_num,
    70  		NewWeight:weight,
    71  		NewTraitNum:trait_id,
    72  		IsRecurrent:recur,
    73  	}
    74  }