1
$\begingroup$

I ran the Neat Python XOR example and a neural network it found has the following properties:

Best individual in generation 22 meets fitness threshold - complexity: (2, 8) Number of evaluations: 3450

Best genome: Nodes: NodeGene(id=0, type=INPUT, bias=0.0, response=4.924273, activation=sigmoid) NodeGene(id=1, type=INPUT, bias=0.0, response=4.924273, activation=sigmoid) NodeGene(id=2, type=OUTPUT, bias=0.0, response=4.921960812206318, activation=sigmoid) NodeGene(id=3, type=HIDDEN, bias=-2.340619398413843, response=4.930091408143276, activation=sigmoid) NodeGene(id=4, type=HIDDEN, bias=0.4674809078722945, response=4.918937894580367, activation=sigmoid) Connections: ConnectionGene(in=0, out=2, weight=1.0534262789427578, enabled=True, innov=0) ConnectionGene(in=1, out=2, weight=-1.6479324848766828, enabled=True, innov=1) ConnectionGene(in=0, out=3, weight=-3.5479647367966765, enabled=True, innov=2) ConnectionGene(in=3, out=2, weight=5.970619032226201, enabled=True, innov=3) ConnectionGene(in=1, out=3, weight=4.634338591600734, enabled=True, innov=4) ConnectionGene(in=0, out=4, weight=0.19203601809123594, enabled=True, innov=5) ConnectionGene(in=4, out=2, weight=-0.6588709650159562, enabled=True, innov=6) ConnectionGene(in=4, out=3, weight=-3.0010419817357072, enabled=True, innov=8) Node order: [4, 3]

Output: expected 0.00000 got 0.11990 expected 1.00000 got 1.00000 expected 1.00000 got 0.92939 expected 0.00000 got 0.00395 {2} {2} {0, 1, 3, 4} {0, 1, 2, 3, 4}

enter image description here

However, when trying to implement the neural network in Python, I don't get the same results:

import math

def sigmoid(x):
    f = 1 / (1 + math.exp(-x))
    return f


node0 = 1
node1 = 1
node2 = 0

node3_bias = -2.340619398413843
node4_bias = 0.4674809078722945

connection_0_2 = 1.0534262789427578
connection_1_2 = -1.6479324848766828
connection_0_3 = -3.5479647367966765
connection_3_2 = 5.970619032226201
connection_1_3 = 4.634338591600734
connection_0_4 = 0.19203601809123594
connection_4_2 = -0.6588709650159562
connection_4_3 = -3.0010419817357072


def main():
    activated_node4 = sigmoid(node4_bias * 1 +
                              node0 * connection_0_4)
    activated_node3 = sigmoid(node3_bias * 1 +
                              activated_node4 * connection_4_3 +
                              node0 * connection_0_3 +
                              node1 * connection_1_3)
    activated_node2 = sigmoid(activated_node4 * connection_4_2 +
                              activated_node3 * connection_3_2 +
                              node1 * connection_1_2 +
                              node0 * connection_0_2)

    print("The value is: ", activated_node2)


if __name__ == "__main__":

    main()

For nodes 1 and 1 I get:

The value is: 0.30957048732254944

which does not match the expected output above.

Can anyone please help me with some pointers as to what I am getting wrong?

Thank you.

$\endgroup$
-1
$\begingroup$

In case anyone has the same issue, please follow the github thread at:

https://github.com/CodeReclaimers/neat-python/issues/79

|improve this answer|||||
$\endgroup$
  • $\begingroup$ The idea of Stack Exchange is Q&A pairs should be self-contained reference, not just links to external resources (the link is OK as a footnote). So, sadly, this isn't a good answer for this site. If you could summarise the relevant content from the link, it could be a good answer. $\endgroup$ – Neil Slater Mar 5 '17 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.