moo_fann

Bindings to use FANN from within ruby/rails environment


License
GPL-3.0
Install
gem install moo_fann -v 0.1.0

Documentation

MooFann

Artifical Intelligence in Ruby

Build Status Gem Version GitHub Release Date

MooFann, or moo_fann is a ruby gem that binds to FANN (Fast Artificial Neural Network) from within a ruby/rails environment. FANN is a is a free open source neural network library, which implements multilayer artificial neural networks with support for both fully connected and sparsely connected networks. It is easy to use, versatile, well documented, and fast. MooFann makes working with neural networks a breeze using ruby, with the added benefit that most of the heavy lifting is done natively.

This is a fork of ruby-fann, that will use a more updated version of the FANN library and also have some unique features added. The original project wasn't updated in years and there are no signs that there would be an active maintainer at all. That is why I decided to create my own fork and rename it, so I'm able to push my own gem file.

Installation

Add this line to your application's Gemfile:

gem 'moo_fann'

And then execute:

$ bundle

Or install it yourself as:

$ gem install moo_fann

Usage

First, Go here & read about FANN. You don't need to install it before using the gem, but understanding FANN will help you understand what you can do with the moo_fann gem: http://leenissen.dk/fann/

Example training & subsequent execution:

  require 'moo_fann'
  train = MooFann::TrainData.new(:inputs=>[[0.3, 0.4, 0.5], [0.1, 0.2, 0.3]], :desired_outputs=>[[0.7], [0.8]])
  fann = MooFann::Standard.new(:num_inputs=>3, :hidden_neurons=>[2, 8, 4, 3, 4], :num_outputs=>1)
  fann.train_on_data(train, 1000, 10, 0.1) # 1000 max_epochs, 10 errors between reports and 0.1 desired MSE (mean-squared-error)
  outputs = fann.run([0.3, 0.2, 0.4])    

Save training data to file and use it later (continued from above)

  train.save('verify.train')
  train = MooFann::TrainData.new(:filename=>'verify.train')
  # Train again with 10000 max_epochs, 20 errors between reports and 0.01 desired MSE (mean-squared-error)
  # This will take longer:
  fann.train_on_data(train, 10000, 20, 0.01) 

Save trained network to file and use it later (continued from above)

  fann.save('foo.net')
  saved_nn = MooFann::Standard.new(:filename=>"foo.net")
  saved_nn.run([0.3, 0.2, 0.4])  

Custom training using a callback method

This callback function can be called during training when using train_on_data, train_on_file or cascadetrain_on_data.

It is very useful for doing custom things during training. It is recommended to use this function when implementing custom training procedures, or when visualizing the training in a GUI etc. The args which the callback function takes is the parameters given to the train_on_data, plus an epochs parameter which tells how many epochs the training have taken so far.

The callback method should return an integer, if the callback function returns -1, the training will terminate.

The callback (training_callback) will be automatically called if it is implemented on your subclass as follows:

class MyFann < MooFann::Standard
  def training_callback(args)
    puts "ARGS: #{args.inspect}"
    0  
  end
end

Semantic Versioning

This project uses Semantic Versioning v2.0. This means the best to integrate it into your project, is via pessimistic version control '~> 1.0'.

Contributors

  1. Steven Miers
  2. Ole Krüger
  3. dignati
  4. Michal Pokorny
  5. Scott Li (locksley)
  6. Maxine Michalski

Contributing

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