Multi-Layer Perceptron Neural Network
I built this to not only learn about the MLP but to also make a very simple, well laid out MLP so other can easily see what’s happening.
I also suggest checking out bit.ly/XEWOc for a great tutorial.
Install
gem install mlp
How To Use
require 'mlp'
a = MLP::Network.new(hidden_layers: [2], output_nodes: 1, inputs: 2)
3001.times do |i|
a.train([0,0], [0])
a.train([0,1], [1])
a.train([1,0], [1])
error = a.train([1,1], [0])
puts "Error after iteration #{i}:\t#{error}" if i%200 == 0
end
puts "Test data"
puts "[0,0] = > #{a.feed_forward([0,0]).inspect}"
puts "[0,1] = > #{a.feed_forward([0,1]).inspect}"
puts "[1,0] = > #{a.feed_forward([1,0]).inspect}"
puts "[1,1] = > #{a.feed_forward([1,1]).inspect}"
Benchmarks
The above example produces these times
user system total real
MLP 0.820000 0.000000 0.820000 ( 0.837693)
Ai4R 1.180000 0.010000 1.190000 ( 1.232388)
Thanks
-
David Richards - For his code reviews and all round helpfulness. - github.com/davidrichards
Copyright
Copyright © 2009 Red Davis, 2017 Igor Pavlov See LICENSE for details.