Project

brainz

0.01
No commit activity in last 3 years
No release in over 3 years
Artificial Neural Network library written in Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 0
>= 0
 Project Readme

Brainz

Artificial Neural Network Library written in Ruby.

Supported training algorithms

  • Backpropagation

Installation

Add this line to your application's Gemfile:

gem 'brainz'

And then execute:

$ bundle

Or install it yourself as:

$ gem install brainz

Usage

Simple example, logical AND operation

require 'brainz'

brainz = Brainz::Brainz.new

brainz.teach do |iteration, error|
  that(1, 1).is(1)
  that(1, 0).is(0)
  that(0, 1).is(0)
  that(0, 0).is(0)
  p "error_rate = #{'%.3f' % error || 0 } after #{iteration} iterations" if iteration % 10 == 0
end

puts "0 and 0 = #{brainz.guess(a: 0, b: 0)}"
puts "0 and 1 = #{brainz.guess(a: 0, b: 1)}"
puts "1 and 1 = #{brainz.guess(a: 1, b: 1)}"
puts "1 and 0 = #{brainz.guess(a: 1, b: 0)}"

Advanced usage, ligical XOR operation

require 'brainz'

brainz = Brainz::Brainz.new

# specify number of hidden layers
# 3 hidden layers with 4, 7 and 3 neurons
brainz.num_hidden = [4, 7, 3]

# tune learning parameters: learning_rate, momentum, wanted_error (mse)
brainz.teach(learning_rate: 0.2, momentum: 0.05, wanted_error: 0.01) do |iteration, error|
  that(1, 1).is(0)
  that(1, 0).is(1)
  that(0, 1).is(1)
  that(0, 0).is(0)
end

puts "Learning took #{brainz.last_iterations}, error: #{brainz.error}, time: #{brainz.learning_time} s."

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request