diff --git a/activation.go b/activation.go index 5edbba8..c102bde 100644 --- a/activation.go +++ b/activation.go @@ -1,3 +1,5 @@ +// +build ignore + package neat const ( diff --git a/activation_func.go b/activation_func.go index c9a65b2..805d7fd 100644 --- a/activation_func.go +++ b/activation_func.go @@ -46,6 +46,16 @@ type ActivationFunc struct { Fn func(x float64) float64 `json:"-"` // activation function } +// Note from github/@jesuiscamille: adapted from activation.go +func Linear() *ActivationFunc { + return &ActivationFunc{ + Name: "linear", + Fn: func(x float64) float64 { + return x + }, + } +} + // Identity returns the identity function as an activation // function. This function is only used for sensor nodes. func Identity() *ActivationFunc { diff --git a/genome.go b/genome.go index 7582d25..35b33b3 100644 --- a/genome.go +++ b/genome.go @@ -47,7 +47,13 @@ func (n *NodeGene) Copy() *NodeGene { // String returns a string representation of the node. func (n *NodeGene) String() string { - return fmt.Sprintf("[%s(%d, %s)]", n.Type, n.ID, n.Activation.Name) + // github/@jesuicamille: if Activation is , print N/A + switch n.Activation { + case nil: + return fmt.Sprintf("[%s(%d, %s)]", n.Type, n.ID, "N/A") + default: + return fmt.Sprintf("[%s(%d, %s)]", n.Type, n.ID, n.Activation.Name) + } } // ConnGene is an implementation of a connection between two nodes in the graph @@ -293,10 +299,19 @@ func (g *Genome) pathExists(src, dst int) bool { } for _, edge := range g.ConnGenes { - if edge.From == src { - if g.pathExists(edge.To, dst) { - return true + // github/@jesuiscamille: didn't understood this part. + // github/@jesuiscamille: I just modified to check if edge.To == dst + + /* + if edge.From == src { + if g.pathExists(edge.To, dst) { + return true + } } + */ + + if edge.From == src && edge.To == dst { + return true } } diff --git a/genome_new.go b/genome_new.go index 9f8ad65..9249ed3 100644 --- a/genome_new.go +++ b/genome_new.go @@ -1,3 +1,5 @@ +// +build ignore + package neat import ( diff --git a/network.go b/network.go index 65e9398..4fa0b91 100644 --- a/network.go +++ b/network.go @@ -4,8 +4,12 @@ type Network struct { signals []float64 } -func NewNetwork(g *Genome) { +// Note from github/@jesuiscamille: initially, there was no return value required, +// but there was one returned in the code. I added the required return value +// second note: *new([]float64) was originally make([]float64) +func NewNetwork(g *Genome) *Network { + var signals []float64 return &Network{ - signals: make([]float64), + signals: signals, } } diff --git a/neural_network.go b/neural_network.go index 380b3f9..058e449 100644 --- a/neural_network.go +++ b/neural_network.go @@ -48,12 +48,35 @@ func NewNeuron(nodeGene *NodeGene) *Neuron { // String returns the string representation of Neuron. func (n *Neuron) String() string { if len(n.Synapses) == 0 { - return fmt.Sprintf("[%s(%d, %s)]", n.Type, n.ID, n.Activation.Name) + // github/@jesuicamille: if Activation is , print N/A + switch n.Activation { + case nil: + return fmt.Sprintf("[%s(%d, %s)]", n.Type, n.ID, "N/A") + default: + return fmt.Sprintf("[%s(%d, %s)]", n.Type, n.ID, n.Activation.Name) + } + } + + var str string + + // github/@jesuicamille: if Activation is , print N/A + switch n.Activation { + case nil: + str = fmt.Sprintf("[%s(%d, %s)] (\n", n.Type, n.ID, "N/A") + default: + str = fmt.Sprintf("[%s(%d, %s)] (\n", n.Type, n.ID, n.Activation.Name) } - str := fmt.Sprintf("[%s(%d, %s)] (\n", n.Type, n.ID, n.Activation.Name) + for neuron, weight := range n.Synapses { - str += fmt.Sprintf(" <--{%.3f}--[%s(%d, %s)]\n", - weight, neuron.Type, neuron.ID, neuron.Activation.Name) + // github/@jesuicamille: if Activation is , print N/A + switch neuron.Activation { + case nil: + str += fmt.Sprintf(" <--{%.3f}--[%s(%d, %s)]\n", + weight, neuron.Type, neuron.ID, "N/A") + default: + str += fmt.Sprintf(" <--{%.3f}--[%s(%d, %s)]\n", + weight, neuron.Type, neuron.ID, neuron.Activation.Name) + } } return str + ")" }