Project

hopfield

0.0
No commit activity in last 3 years
No release in over 3 years
Hopfield networks can be used for smart pattern recollections. It's recalling patterns by modelling associative memory of a neural network
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 0
 Project Readme

Hopfield Network in Ruby

A short and simple Ruby implementation of a Hopfield Network. Includes a small C extension to speed up the CPU intensive loops.

What is it?

Hopfield Networks model the way humans recall memories, or more specific, how neurons recall the pattern. This means you first train the network with a set of known patterns and then pass an unknown or perturbed version of the pattern. The neurons will restore the missing information to create an exact match.

The patterns can be passed using multi dimensional array of either 0 and 1 or -1 and 1. An artifical neural network will learn the patterns. Now let's move on to an example.

gem 'hopfield'

How do I use it?

training = Hopfield::Training.new([pattern1, pattern2])
network = Hopfield::Network.new(training, perturbed_pattern)

# Propagate until match
network.propagate until network.associated?

network.pattern # the matched pattern
network.runs # how many propagations it took

TODO

  • Improve C extension to boost performance
  • Turn the random picking of neurons into pseudo randomness to prevent the same neuron to be propagated over and over again
  • Implement the Storkey learning rule to provide an alternative for the already implemented Hebbian learning rule.
  • Release the examples

Thanks to

I was introduced to Hopfield networks through the book Clever Algorithms, and I've borrowed bits of the implementation shown in the book. Also used the .associated? syntax found here: Brain.