https://github.com/viliusluneckas/brainz
Artificial Neural Network library written in Ruby
https://github.com/viliusluneckas/brainz
artificial-neural-networks neural-network ruby
Last synced: 12 months ago
JSON representation
Artificial Neural Network library written in Ruby
- Host: GitHub
- URL: https://github.com/viliusluneckas/brainz
- Owner: ViliusLuneckas
- License: mit
- Created: 2012-03-05T19:44:28.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2019-07-12T18:30:53.000Z (almost 7 years ago)
- Last Synced: 2024-09-18T16:19:46.187Z (almost 2 years ago)
- Topics: artificial-neural-networks, neural-network, ruby
- Language: Ruby
- Homepage:
- Size: 33.2 KB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this 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
6.