Not sure if you did this in your initialization, but in the weight matrix :
Mat i,i=0
Mat i,j= Mat j,i
... is generally used : it permits to be sure the network will reach a stable state.
The capacity of a hopfield network is approximately nbPatterns=0.138*nbNodes, so 4 nodes is too small, maybe try with 10x10 nodes ( about 13 patterns in term of capacity )
I noticed you have implemented a synchronous method to compute the network state. It's totally possible even if initially, it was supposed to be asynchronous and stochastic.
Hope it can help !![]()
If you still have problems with your implementation, I can post some pseudo-code if necessary


Find content
Not Telling
