Skip to content
This repository was archived by the owner on Dec 11, 2018. It is now read-only.

Fix multiple bugs and make it compilable - tests passed #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions activation.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build ignore

package neat

const (
Expand Down
10 changes: 10 additions & 0 deletions activation_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 19 additions & 4 deletions genome.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nil>, 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
Expand Down Expand Up @@ -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
}
}

Expand Down
2 changes: 2 additions & 0 deletions genome_new.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build ignore

package neat

import (
Expand Down
8 changes: 6 additions & 2 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
31 changes: 27 additions & 4 deletions neural_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nil>, 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 <nil>, 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 <nil>, 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 + ")"
}
Expand Down