views:

318

answers:

2

I was looking at the knights tour problem and decided to have a go at implementing it in python using a neural network to find solutions.

The general explanation of the method can be found on Wikipedia

While I think I have implemented it correctly (I can't see anything else that is wrong), it doesn't work, it updates a few links, removing the edges where the connecting vertex has a degree more than two, but it doesn't converge on the solution.

I was wondering if anyone had any ideas on what I have implemented incorrectly (Sorry about the horrible code).

EDIT
Working code can be found at Yacoby.net

+2  A: 

First impression is that you only have one buffer for the board. I'm basing this on the fact that I don't see any buffer swaps between iterations - I haven't looked that closely and may easily be wrong.

If you modify a single buffer in place, when you do the neighbour counts, you base them on a partly modified board - not the board you had at the start.

Steve314
+3  A: 

You can't update the neurons in place. Since U[t+1] depends on U[t] and V[t], if you have already updated V the calculation for U will be wrong

I think you should split the update into two phases update_state and update_output, so all the U are updated and then all the V

    for n in neurons:
        n.update_state()
    for n in neurons:
        n.update_output()
gnibbler
I can't believe how I could have missed something so obvious. Answer was accepted for the slightly better explanation.
Yacoby