├── .gitignore ├── .yardopts ├── Dockerfile ├── Gemfile ├── Gemfile.lock ├── History.txt ├── LICENSE.txt ├── README.md ├── README.txt ├── Rakefile ├── build-docker-image.sh ├── docker-image-sh.sh ├── docs ├── README_md.html ├── RubyFann.html ├── RubyFann │ ├── Shortcut.html │ ├── Standard.html │ ├── TrainData.html │ └── VERSION.html ├── created.rid ├── css │ ├── fonts.css │ └── rdoc.css ├── fonts │ ├── Lato-Light.ttf │ ├── Lato-LightItalic.ttf │ ├── Lato-Regular.ttf │ ├── Lato-RegularItalic.ttf │ ├── SourceCodePro-Bold.ttf │ └── SourceCodePro-Regular.ttf ├── images │ ├── add.png │ ├── arrow_up.png │ ├── brick.png │ ├── brick_link.png │ ├── bug.png │ ├── bullet_black.png │ ├── bullet_toggle_minus.png │ ├── bullet_toggle_plus.png │ ├── date.png │ ├── delete.png │ ├── find.png │ ├── loadingAnimation.gif │ ├── macFFBgHack.png │ ├── package.png │ ├── page_green.png │ ├── page_white_text.png │ ├── page_white_width.png │ ├── plugin.png │ ├── ruby.png │ ├── tag_blue.png │ ├── tag_green.png │ ├── transparent.png │ ├── wrench.png │ ├── wrench_orange.png │ └── zoom.png ├── index.html ├── js │ ├── darkfish.js │ ├── navigation.js │ ├── navigation.js.gz │ ├── search.js │ ├── search_index.js │ ├── search_index.js.gz │ ├── searcher.js │ └── searcher.js.gz └── table_of_contents.html ├── ext └── ruby_fann │ ├── .gitignore │ ├── MANIFEST │ ├── config.h │ ├── doublefann.c │ ├── doublefann.h │ ├── doublefann.o │ ├── extconf.rb │ ├── fann.c │ ├── fann.h │ ├── fann_activation.h │ ├── fann_augment.h │ ├── fann_cascade.c │ ├── fann_cascade.h │ ├── fann_data.h │ ├── fann_error.c │ ├── fann_error.h │ ├── fann_internal.h │ ├── fann_io.c │ ├── fann_io.h │ ├── fann_train.c │ ├── fann_train.h │ ├── fann_train_data.c │ ├── ruby_compat.h │ ├── ruby_fann.c │ └── ruby_fann.o ├── lib ├── ruby-fann.rb ├── ruby_fann.rb └── ruby_fann │ ├── neurotica.rb │ └── version.rb ├── nn1.png ├── package-lock.json ├── ruby-fann.gemspec ├── ruby-fann.png ├── test ├── Gemfile ├── test.train ├── test_helper.rb ├── test_neurotica.rb.nop ├── test_ruby_fann.rb └── test_ruby_fann_functional.rb ├── verify.train └── xor.train /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | *.bundle 4 | *.net 5 | *.log 6 | **/*/.DS_Store 7 | .vscode 8 | .config 9 | coverage 10 | InstalledFiles 11 | lib/bundler/man 12 | pkg 13 | html 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | vendor 19 | 20 | # YARD artifacts 21 | .yardoc 22 | _yardoc 23 | 24 | ext/ruby-fann/Makefile 25 | -------------------------------------------------------------------------------- /.yardopts: -------------------------------------------------------------------------------- 1 | ext/**/*.c 2 | lib/**/*.rb 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:3.2 2 | 3 | # Copy function code 4 | RUN mkdir /ruby-fann 5 | COPY . /ruby-fann 6 | # RUN gem install ruby-fann 7 | # RUN bundle install 8 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | ruby "~> 3.2" 3 | 4 | # Specify your gem's dependencies in ruby-fann.gemspec 5 | gem 'json', '~> 2' 6 | gem 'rdoc', '~> 6' 7 | gemspec 8 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | ruby-fann (1.4.3) 5 | 6 | GEM 7 | remote: https://rubygems.org/ 8 | specs: 9 | json (2.6.1) 10 | rdoc (6.3.3) 11 | 12 | PLATFORMS 13 | arm64-darwin-22 14 | ruby 15 | x86_64-darwin-19 16 | 17 | DEPENDENCIES 18 | json (~> 2) 19 | rdoc (~> 6) 20 | ruby-fann! 21 | 22 | RUBY VERSION 23 | ruby 3.2.2p53 24 | 25 | BUNDLED WITH 26 | 2.4.18 27 | -------------------------------------------------------------------------------- /History.txt: -------------------------------------------------------------------------------- 1 | == 2.0.x 2 | Get working again after a bad pull request. 3 | == 1.3.x 4 | Dependabot updates, etc. 5 | == 1.2.7 6 | * Update to more recent json and rdoc files 7 | == 1.2.6 8 | * Update to FANN 2.2(MichalPokorny) 9 | == 1.2.5 10 | * Misc cleanup and docs 11 | == 1.2.4 2013-08-01 12 | * bug fix - adopted new graphviz parameters (ScottLi) 13 | * Add Ruby equivalent of fann_train(MichalPokorny) 14 | * Ignores(Ole Kruger) 15 | 16 | == 1.2.3 2013-04-01 17 | * Remove nodoc directive 18 | 19 | == 1.2.2 2013-04-01 20 | * Update rdoc/native code 21 | 22 | == 1.2.1 2013-04-01 23 | * Update rdoc 24 | 25 | == 1.2 2013-03-26 26 | * Move to github. Dig out hoe. 27 | 28 | == 1.1.3 2010-03-08 29 | * 1 major enhancement - 30 | * ruby 1.9 compatibility: 31 | 32 | == 1.0.3 2009-12-24 33 | * 1 minor bug fix: 34 | * Fix segfaulting training in irb 35 | 36 | == 1.0.2 2009-12-02 37 | 38 | * 1 minor enhancement: 39 | * Added missing file to manifest 40 | 41 | == 1.0.1 2009-12-02 42 | 43 | * 1 minor enhancement: 44 | * Remove some extra source files 45 | 46 | == 1.0.0 2009-12-01 47 | 48 | * 1 major enhancement: 49 | * Can build/install & execute without first installing & building FANN. 50 | 51 | == 0.7.10 2008-11-24 52 | 53 | * 1 minor enhancement: 54 | * Remove several printf statements that were showing up in certain production environment's error logs. 55 | 56 | == 0.7.9 2008-08-15 57 | 58 | * 1 major bug fix: 59 | * Fix set_activation_function for correct # of args (2 instead of 1) 60 | * 1 minor enhancement 61 | * Provide support for fann_get_activation_function 62 | 63 | == 0.7.8 2007-03-25 64 | 65 | * 1 major enhancement: 66 | * training_callback(args) will be automatically called during training if implemented on subclass. See README for details. 67 | 68 | == 0.7.7 2007-01-23 69 | 70 | * 1 minor enhancement: 71 | * Cull bias neuron(s) from get_neurons function 72 | 73 | == 0.7.6 2007-01-14 74 | 75 | * 1 minor bug fix: 76 | * Exception (instead of pukage) if zero-length array given on training data 77 | 78 | == 0.7.5 2007-12-21 79 | 80 | * 3 minor enhancements: 81 | * Fixed rdoc to use actual parameter names 82 | * Minor code cleanup & symbol fixage 83 | * Nicer error messages for windows users 84 | 85 | == 0.7.4 2007-12-19 86 | 87 | * 1 minor enhancement: 88 | * Nicer message if FANN not installed 89 | 90 | == 0.7.3 2007-12-19 91 | 92 | * 1 minor enhancement: 93 | * Directives to build native extensions 94 | 95 | == 0.7.2 2007-12-18 96 | 97 | * 1 major enhancement: 98 | * Include docs 99 | 100 | == 0.0.1 2007-12-18 101 | 102 | * 1 major enhancement: 103 | * Initial release 104 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2022 Steven Miers 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RubyFann 2 | _Fast_ **AI** 3 | 4 | 5 | --- 6 | Neural Networks in `ruby` 7 | 8 | [![Gem Version](https://badge.fury.io/rb/ruby-fann.png)](http://badge.fury.io/rb/ruby-fann) 9 | 10 | ![NN eye candy](ruby-fann.png) 11 | 12 | 13 | RubyFann, or "ruby-fann" is a Ruby Gem (no Rails required) that binds to FANN (Fast Artificial Neural Network) from within a ruby/rails environment. FANN is a is a free native open source neural network library, which implements multilayer artificial neural networks, supporting both fully-connected and sparsely-connected networks. It is easy to use, versatile, well documented, and fast. `RubyFann` makes working with neural networks a breeze using `ruby`, with the added benefit that most of the heavy lifting is done natively. 14 | 15 | A talk given by our friend Ethan from Big-Oh Studios at Lone Star Ruby 2013: http://confreaks.com/videos/2609-lonestarruby2013-neural-networks-with-rubyfann 16 | 17 | ## Installation 18 | 19 | Add this line to your application's Gemfile: 20 | 21 | gem 'ruby-fann' 22 | 23 | And then execute: 24 | 25 | $ bundle 26 | 27 | Or install it yourself as: 28 | 29 | $ gem install ruby-fann 30 | 31 | ## Usage 32 | 33 | 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 ruby-fann gem: 34 | http://leenissen.dk/fann/ 35 | 36 | ## Documentation: 37 | *ruby-fann documentation:* 38 | http://tangledpath.github.io/ruby-fann/index.html 39 | 40 | 41 | 42 | ### Example training & subsequent execution: 43 | 44 | ```ruby 45 | require 'ruby-fann' 46 | train = RubyFann::TrainData.new(:inputs=>[[0.3, 0.4, 0.5], [0.1, 0.2, 0.3]], :desired_outputs=>[[0.7], [0.8]]) 47 | fann = RubyFann::Standard.new(:num_inputs=>3, :hidden_neurons=>[2, 8, 4, 3, 4], :num_outputs=>1) 48 | fann.train_on_data(train, 1000, 10, 0.1) # 1000 max_epochs, 10 errors between reports and 0.1 desired MSE (mean-squared-error) 49 | outputs = fann.run([0.3, 0.2, 0.4]) 50 | ``` 51 | 52 | ### Save training data to file and use it later (continued from above) 53 | 54 | ```ruby 55 | train.save('verify.train') 56 | train = RubyFann::TrainData.new(:filename=>'verify.train') 57 | # Train again with 10000 max_epochs, 20 errors between reports and 0.01 desired MSE (mean-squared-error) 58 | # This will take longer: 59 | fann.train_on_data(train, 10000, 20, 0.01) 60 | ``` 61 | 62 | ### Save trained network to file and use it later (continued from above) 63 | 64 | ```ruby 65 | fann.save('foo.net') 66 | saved_nn = RubyFann::Standard.new(:filename=>"foo.net") 67 | saved_nn.run([0.3, 0.2, 0.4]) 68 | ``` 69 | 70 | ### Custom training using a callback method 71 | 72 | This callback function can be called during training when using train_on_data, train_on_file or cascadetrain_on_data. 73 | 74 | 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. 75 | 76 | The callback method should return an integer, if the callback function returns -1, the training will terminate. 77 | 78 | The callback (training_callback) will be automatically called if it is implemented on your subclass as follows: 79 | 80 | ```ruby 81 | class MyFann < RubyFann::Standard 82 | def training_callback(args) 83 | puts "ARGS: #{args.inspect}" 84 | 0 85 | end 86 | end 87 | ``` 88 | ### A sample project using RubyFann to play tic-tac-toe 89 | https://github.com/bigohstudios/tictactoe 90 | 91 | ## Contributors 92 | 1. Steven Miers 93 | 2. Ole Krüger 94 | 3. dignati 95 | 4. Michal Pokorny 96 | 5. Scott Li (locksley) 97 | 6. alex.slotty 98 | 99 | ## Contributing 100 | 101 | 1. Fork it 102 | 2. Create your feature branch (`git checkout -b my-new-feature`) 103 | 3. Commit your changes (`git commit -am 'Add some feature'`) 104 | 4. Push to the branch (`git push origin my-new-feature`) 105 | 5. Create new Pull Request 106 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | == Ruby Fann - the gem: 2 | Please see https://github.com/tangledpath/ruby-fann for installation and sample usage, or check out RubyFann::Standard, RubyFann::Shortcut, and/or RubyFann::TrainData -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | require 'rake/testtask' 4 | require 'rdoc/task' 5 | require 'rake/clean' 6 | 7 | NAME = 'ruby_fann' 8 | 9 | # rule to build the extension: this says 10 | # that the extension should be rebuilt 11 | # after any change to the files in ext 12 | file "lib/#{NAME}/#{NAME}.so" => 13 | Dir.glob("ext/#{NAME}/*{.rb,.c}") do 14 | Dir.chdir("ext/#{NAME}") do 15 | # this does essentially the same thing 16 | # as what RubyGems does 17 | ruby "extconf.rb" 18 | sh "make" 19 | end 20 | end 21 | #cp "ext/#{NAME}/#{NAME}.so", "lib/#{NAME}" 22 | #end 23 | 24 | # make the :test task depend on the shared 25 | # object, so it will be built automatically 26 | # before running the tests 27 | task :test => "lib/#{NAME}/#{NAME}.so" 28 | 29 | # use 'rake clean' and 'rake clobber' to 30 | # easily delete generated files 31 | CLEAN.include('ext/**/*{.o,.log,.so}') 32 | CLEAN.include('ext/**/Makefile') 33 | CLOBBER.include('lib/**/*.so') 34 | 35 | # the same as before 36 | Rake::TestTask.new do |t| 37 | t.libs << 'test' 38 | end 39 | 40 | desc "Run tests" 41 | task :default => :test 42 | 43 | Rake::RDocTask.new do |rd| 44 | rd.main = "README.md" 45 | rd.rdoc_dir = "docs" 46 | rd.rdoc_files.include("README.md", "lib/**/*.rb", "ext/**/*.c") 47 | rd.title = "Ruby FANN Gem documentation" 48 | #rd.generator = "fivefish" 49 | end 50 | 51 | -------------------------------------------------------------------------------- /build-docker-image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | clear 3 | echo "Removing docker image..." 4 | docker image rm -f tps:ruby-fann 5 | echo "Building docker image..." 6 | docker build --platform linux/arm64 -t tps:ruby-fann . 7 | docker image ls 8 | -------------------------------------------------------------------------------- /docker-image-sh.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | docker run --platform linux/arm64 -it --entrypoint sh tps:ruby-fann 3 | # docker run --platform linux/arm64 -it earbug:artist_harvester sh 4 | -------------------------------------------------------------------------------- /docs/README_md.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | README - Ruby FANN Gem documentation 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 107 | 108 |
109 | 110 |

RubyFann

111 | 112 |

Fast AI

113 | 114 |

— Neural Networks in ruby

115 | 116 |

117 | 118 |

119 | 120 |

RubyFann, or “ruby-fann” is a Ruby Gem (no Rails required) that binds to FANN (Fast Artificial Neural Network) from within a ruby/rails environment. FANN is a is a free native open source neural network library, which implements multilayer artificial neural networks, supporting both fully-connected and sparsely-connected networks. It is easy to use, versatile, well documented, and fast. RubyFann makes working with neural networks a breeze using ruby, with the added benefit that most of the heavy lifting is done natively.

121 | 122 |

A talk given by our friend Ethan from Big-Oh Studios at Lone Star Ruby 2013: confreaks.com/videos/2609-lonestarruby2013-neural-networks-with-rubyfann

123 | 124 |

Installation

125 | 126 |

Add this line to your application’s Gemfile:

127 | 128 |
gem 'ruby-fann'
129 | 
130 | 131 |

And then execute:

132 | 133 |
$ bundle
134 | 135 |

Or install it yourself as:

136 | 137 |
$ gem install ruby-fann
138 | 139 |

Usage

140 | 141 |

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 ruby-fann gem: leenissen.dk/fann/

142 | 143 |

Documentation:

144 | 145 |

ruby-fann documentation: tangledpath.github.io/ruby-fann/index.html

146 | 147 |

Example training & subsequent execution:

148 | 149 |
require 'ruby-fann'
150 |   train = RubyFann::TrainData.new(:inputs=>[[0.3, 0.4, 0.5], [0.1, 0.2, 0.3]], :desired_outputs=>[[0.7], [0.8]])
151 |   fann = RubyFann::Standard.new(:num_inputs=>3, :hidden_neurons=>[2, 8, 4, 3, 4], :num_outputs=>1)
152 |   fann.train_on_data(train, 1000, 10, 0.1) # 1000 max_epochs, 10 errors between reports and 0.1 desired MSE (mean-squared-error)
153 |   outputs = fann.run([0.3, 0.2, 0.4])
154 | 
155 | 156 |

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

157 | 158 |
train.save('verify.train')
159 |   train = RubyFann::TrainData.new(:filename=>'verify.train')
160 |   # Train again with 10000 max_epochs, 20 errors between reports and 0.01 desired MSE (mean-squared-error)
161 |   # This will take longer:
162 |   fann.train_on_data(train, 10000, 20, 0.01)
163 | 
164 | 165 |

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

166 | 167 |
fann.save('foo.net')
168 |   saved_nn = RubyFann::Standard.new(:filename=>"foo.net")
169 |   saved_nn.run([0.3, 0.2, 0.4])
170 | 
171 | 172 |

Custom training using a callback method

173 | 174 |

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

175 | 176 |

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.

177 | 178 |

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

179 | 180 |

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

181 | 182 |
class MyFann < RubyFann::Standard
183 |   def training_callback(args)
184 |     puts "ARGS: #{args.inspect}"
185 |     0
186 |   end
187 | end
188 | 
189 | 190 |

A sample project using RubyFann to play tic-tac-toe

191 | 192 |

github.com/bigohstudios/tictactoe

193 | 194 |

Contributors

195 |
  1. 196 |

    Steven Miers

    197 |
  2. 198 |

    Ole Krüger

    199 |
  3. 200 |

    dignati

    201 |
  4. 202 |

    Michal Pokorny

    203 |
  5. 204 |

    Scott Li (locksley)

    205 |
  6. 206 |

    alex.slotty

    207 |
208 | 209 |

Contributing

210 |
  1. 211 |

    Fork it

    212 |
  2. 213 |

    Create your feature branch (git checkout -b my-new-feature)

    214 |
  3. 215 |

    Commit your changes (git commit -am 'Add some feature')

    216 |
  4. 217 |

    Push to the branch (git push origin my-new-feature)

    218 |
  5. 219 |

    Create new Pull Request

    220 |
221 | 222 |
223 | 224 | 225 | 226 | 231 | 232 | -------------------------------------------------------------------------------- /docs/RubyFann.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | module RubyFann - Ruby FANN Gem documentation 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 66 | 67 |
68 |

69 | module RubyFann 70 |

71 | 72 |
73 | 74 |

Namespace for ruby-fann functionality.

75 | 76 |

See RubyFann::Shortcut, RubyFann::Standard, and RubyFann::TrainData for details.

77 | 78 |
79 | 80 |
81 | 82 | 83 | 84 | 85 | 86 |
87 |
88 | 89 | 90 | 95 | 96 | -------------------------------------------------------------------------------- /docs/RubyFann/TrainData.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | class RubyFann::TrainData - Ruby FANN Gem documentation 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 84 | 85 |
86 |

87 | class RubyFann::TrainData 88 |

89 | 90 |
91 | 92 |
93 | 94 |
95 | 96 | 97 | 98 | 99 | 100 |
101 |
102 |

Public Class Methods

103 |
104 | 105 |
106 |
107 |
108 | 109 | new(hash) → new ruby-fann training data object (RubyFann::TrainData) 110 | 111 | click to toggle source 112 |
113 |
114 | 115 |
116 |
Initialize in one of the following forms:
117 | 
118 | # This is a flat file with training data as described in FANN docs.
119 | RubyFann::TrainData.new(:filename => 'path/to/training_file.train')
120 | 121 |

OR

122 | 123 |
# Train with inputs (array of arrays) & desired_outputs (array of arrays)
124 | # inputs & desired outputs should be of same length
125 | # All sub-arrays on inputs should be of same length
126 | # All sub-arrays on desired_outputs should be of same length
127 | # Sub-arrays on inputs & desired_outputs can be different sizes from one another
128 | RubyFann::TrainData.new(:inputs=>[[0.2, 0.3, 0.4], [0.8, 0.9, 0.7]], :desired_outputs=>[[3.14], [6.33]])
129 | 
130 | 131 |
132 |
static VALUE fann_train_data_initialize(VALUE self, VALUE hash)
133 | {
134 |     struct fann_train_data *train_data;
135 |     Check_Type(hash, T_HASH);
136 | 
137 |     VALUE filename = rb_hash_aref(hash, ID2SYM(rb_intern("filename")));
138 |     VALUE inputs = rb_hash_aref(hash, ID2SYM(rb_intern("inputs")));
139 |     VALUE desired_outputs = rb_hash_aref(hash, ID2SYM(rb_intern("desired_outputs")));
140 | 
141 |     if (TYPE(filename) == T_STRING)
142 |     {
143 |         train_data = fann_read_train_from_file(StringValuePtr(filename));
144 |         DATA_PTR(self) = train_data;
145 |     }
146 |     else if (TYPE(inputs) == T_ARRAY)
147 |     {
148 |         if (TYPE(desired_outputs) != T_ARRAY)
149 |         {
150 |             rb_raise(rb_eRuntimeError, "[desired_outputs] must be present when [inputs] used.");
151 |         }
152 | 
153 |         if (RARRAY_LEN(inputs) < 1)
154 |         {
155 |             rb_raise(rb_eRuntimeError, "[inputs] must contain at least one value.");
156 |         }
157 | 
158 |         if (RARRAY_LEN(desired_outputs) < 1)
159 |         {
160 |             rb_raise(rb_eRuntimeError, "[desired_outputs] must contain at least one value.");
161 |         }
162 | 
163 |         // The data is here, start constructing:
164 |         if (RARRAY_LEN(inputs) != RARRAY_LEN(desired_outputs))
165 |         {
166 |             rb_raise(
167 |                 rb_eRuntimeError,
168 |                 "Number of inputs must match number of outputs: (%d != %d)",
169 |                 (int)RARRAY_LEN(inputs),
170 |                 (int)RARRAY_LEN(desired_outputs));
171 |         }
172 | 
173 |         train_data = fann_create_train_from_rb_ary(inputs, desired_outputs);
174 |         DATA_PTR(self) = train_data;
175 |     }
176 |     else
177 |     {
178 |         rb_raise(rb_eRuntimeError, "Must construct with a filename(string) or inputs/desired_outputs(arrays).  All args passed via hash with symbols as keys.");
179 |     }
180 | 
181 |     return (VALUE)train_data;
182 | }
183 |
184 |
185 | 186 | 187 |
188 | 189 |
190 | 191 |
192 |
193 |

Public Instance Methods

194 |
195 | 196 |
197 |
198 |
199 | length() 201 | click to toggle source 202 |
203 |
204 | 205 |
206 |

Length of training data

207 | 208 |
209 |
static VALUE length_train_data(VALUE self)
210 | {
211 |     struct fann_train_data *t;
212 |     Data_Get_Struct(self, struct fann_train_data, t);
213 |     return (UINT2NUM(fann_length_train_data(t)));
214 |     return self;
215 | }
216 |
217 |
218 | 219 | 220 |
221 | 222 |
223 |
224 |
225 | 226 | save(filename) 227 | 228 | click to toggle source 229 |
230 |
231 | 232 |
233 |

Save to given filename

234 | 235 |
236 |
static VALUE training_save(VALUE self, VALUE filename)
237 | {
238 |     Check_Type(filename, T_STRING);
239 |     struct fann_train_data *t;
240 |     Data_Get_Struct(self, struct fann_train_data, t);
241 |     fann_save_train(t, StringValuePtr(filename));
242 |     return self;
243 | }
244 |
245 |
246 | 247 | 248 |
249 | 250 |
251 |
252 |
253 | shuffle() 255 | click to toggle source 256 |
257 |
258 | 259 |
260 |

Shuffles training data, randomizing the order. This is recommended for incremental training, while it will have no influence during batch training.

261 | 262 |
263 |
static VALUE shuffle(VALUE self)
264 | {
265 |     struct fann_train_data *t;
266 |     Data_Get_Struct(self, struct fann_train_data, t);
267 |     fann_shuffle_train_data(t);
268 |     return self;
269 | }
270 |
271 |
272 | 273 | 274 |
275 | 276 |
277 | 278 |
279 |
280 | 281 | 282 | 287 | 288 | -------------------------------------------------------------------------------- /docs/RubyFann/VERSION.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | module RubyFann::VERSION - Ruby FANN Gem documentation 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 66 | 67 |
68 |

69 | module RubyFann::VERSION 70 |

71 | 72 |
73 | 74 |
75 | 76 |
77 | 78 | 79 |
80 |
81 |

Constants

82 |
83 |
84 |
MAJOR 85 |
86 |
MINOR 87 |
88 |
STRING 89 |
90 |
TINY 91 |
92 |
93 |
94 | 95 | 96 | 97 |
98 |
99 | 100 | 101 | 106 | 107 | -------------------------------------------------------------------------------- /docs/created.rid: -------------------------------------------------------------------------------- 1 | Mon, 25 Mar 2024 03:18:51 -0500 2 | README.md Mon, 25 Mar 2024 03:18:00 -0500 3 | lib/ruby-fann.rb Mon, 14 Aug 2023 16:08:17 -0500 4 | lib/ruby_fann.rb Mon, 14 Aug 2023 16:08:17 -0500 5 | lib/ruby_fann/neurotica.rb Mon, 14 Aug 2023 16:08:17 -0500 6 | lib/ruby_fann/version.rb Thu, 21 Mar 2024 16:40:09 -0500 7 | ext/ruby_fann/doublefann.c Mon, 14 Aug 2023 16:08:17 -0500 8 | ext/ruby_fann/fann.c Mon, 14 Aug 2023 16:08:17 -0500 9 | ext/ruby_fann/fann_cascade.c Mon, 14 Aug 2023 16:08:17 -0500 10 | ext/ruby_fann/fann_error.c Mon, 14 Aug 2023 19:41:03 -0500 11 | ext/ruby_fann/fann_io.c Mon, 14 Aug 2023 16:08:17 -0500 12 | ext/ruby_fann/fann_train.c Mon, 14 Aug 2023 16:08:17 -0500 13 | ext/ruby_fann/fann_train_data.c Mon, 14 Aug 2023 19:27:15 -0500 14 | ext/ruby_fann/ruby_fann.c Thu, 21 Mar 2024 16:39:31 -0500 15 | -------------------------------------------------------------------------------- /docs/css/fonts.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), 3 | * with Reserved Font Name "Source". All Rights Reserved. Source is a 4 | * trademark of Adobe Systems Incorporated in the United States and/or other 5 | * countries. 6 | * 7 | * This Font Software is licensed under the SIL Open Font License, Version 8 | * 1.1. 9 | * 10 | * This license is copied below, and is also available with a FAQ at: 11 | * http://scripts.sil.org/OFL 12 | */ 13 | 14 | @font-face { 15 | font-family: "Source Code Pro"; 16 | font-style: normal; 17 | font-weight: 400; 18 | src: local("Source Code Pro"), 19 | local("SourceCodePro-Regular"), 20 | url("../fonts/SourceCodePro-Regular.ttf") format("truetype"); 21 | } 22 | 23 | @font-face { 24 | font-family: "Source Code Pro"; 25 | font-style: normal; 26 | font-weight: 700; 27 | src: local("Source Code Pro Bold"), 28 | local("SourceCodePro-Bold"), 29 | url("../fonts/SourceCodePro-Bold.ttf") format("truetype"); 30 | } 31 | 32 | /* 33 | * Copyright (c) 2010, Łukasz Dziedzic (dziedzic@typoland.com), 34 | * with Reserved Font Name Lato. 35 | * 36 | * This Font Software is licensed under the SIL Open Font License, Version 37 | * 1.1. 38 | * 39 | * This license is copied below, and is also available with a FAQ at: 40 | * http://scripts.sil.org/OFL 41 | */ 42 | 43 | @font-face { 44 | font-family: "Lato"; 45 | font-style: normal; 46 | font-weight: 300; 47 | src: local("Lato Light"), 48 | local("Lato-Light"), 49 | url("../fonts/Lato-Light.ttf") format("truetype"); 50 | } 51 | 52 | @font-face { 53 | font-family: "Lato"; 54 | font-style: italic; 55 | font-weight: 300; 56 | src: local("Lato Light Italic"), 57 | local("Lato-LightItalic"), 58 | url("../fonts/Lato-LightItalic.ttf") format("truetype"); 59 | } 60 | 61 | @font-face { 62 | font-family: "Lato"; 63 | font-style: normal; 64 | font-weight: 700; 65 | src: local("Lato Regular"), 66 | local("Lato-Regular"), 67 | url("../fonts/Lato-Regular.ttf") format("truetype"); 68 | } 69 | 70 | @font-face { 71 | font-family: "Lato"; 72 | font-style: italic; 73 | font-weight: 700; 74 | src: local("Lato Italic"), 75 | local("Lato-Italic"), 76 | url("../fonts/Lato-RegularItalic.ttf") format("truetype"); 77 | } 78 | 79 | /* 80 | * ----------------------------------------------------------- 81 | * SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 82 | * ----------------------------------------------------------- 83 | * 84 | * PREAMBLE 85 | * The goals of the Open Font License (OFL) are to stimulate worldwide 86 | * development of collaborative font projects, to support the font creation 87 | * efforts of academic and linguistic communities, and to provide a free and 88 | * open framework in which fonts may be shared and improved in partnership 89 | * with others. 90 | * 91 | * The OFL allows the licensed fonts to be used, studied, modified and 92 | * redistributed freely as long as they are not sold by themselves. The 93 | * fonts, including any derivative works, can be bundled, embedded, 94 | * redistributed and/or sold with any software provided that any reserved 95 | * names are not used by derivative works. The fonts and derivatives, 96 | * however, cannot be released under any other type of license. The 97 | * requirement for fonts to remain under this license does not apply 98 | * to any document created using the fonts or their derivatives. 99 | * 100 | * DEFINITIONS 101 | * "Font Software" refers to the set of files released by the Copyright 102 | * Holder(s) under this license and clearly marked as such. This may 103 | * include source files, build scripts and documentation. 104 | * 105 | * "Reserved Font Name" refers to any names specified as such after the 106 | * copyright statement(s). 107 | * 108 | * "Original Version" refers to the collection of Font Software components as 109 | * distributed by the Copyright Holder(s). 110 | * 111 | * "Modified Version" refers to any derivative made by adding to, deleting, 112 | * or substituting -- in part or in whole -- any of the components of the 113 | * Original Version, by changing formats or by porting the Font Software to a 114 | * new environment. 115 | * 116 | * "Author" refers to any designer, engineer, programmer, technical 117 | * writer or other person who contributed to the Font Software. 118 | * 119 | * PERMISSION & CONDITIONS 120 | * Permission is hereby granted, free of charge, to any person obtaining 121 | * a copy of the Font Software, to use, study, copy, merge, embed, modify, 122 | * redistribute, and sell modified and unmodified copies of the Font 123 | * Software, subject to the following conditions: 124 | * 125 | * 1) Neither the Font Software nor any of its individual components, 126 | * in Original or Modified Versions, may be sold by itself. 127 | * 128 | * 2) Original or Modified Versions of the Font Software may be bundled, 129 | * redistributed and/or sold with any software, provided that each copy 130 | * contains the above copyright notice and this license. These can be 131 | * included either as stand-alone text files, human-readable headers or 132 | * in the appropriate machine-readable metadata fields within text or 133 | * binary files as long as those fields can be easily viewed by the user. 134 | * 135 | * 3) No Modified Version of the Font Software may use the Reserved Font 136 | * Name(s) unless explicit written permission is granted by the corresponding 137 | * Copyright Holder. This restriction only applies to the primary font name as 138 | * presented to the users. 139 | * 140 | * 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 141 | * Software shall not be used to promote, endorse or advertise any 142 | * Modified Version, except to acknowledge the contribution(s) of the 143 | * Copyright Holder(s) and the Author(s) or with their explicit written 144 | * permission. 145 | * 146 | * 5) The Font Software, modified or unmodified, in part or in whole, 147 | * must be distributed entirely under this license, and must not be 148 | * distributed under any other license. The requirement for fonts to 149 | * remain under this license does not apply to any document created 150 | * using the Font Software. 151 | * 152 | * TERMINATION 153 | * This license becomes null and void if any of the above conditions are 154 | * not met. 155 | * 156 | * DISCLAIMER 157 | * THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 158 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 159 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 160 | * OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 161 | * COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 162 | * INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 163 | * DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 164 | * FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 165 | * OTHER DEALINGS IN THE FONT SOFTWARE. 166 | */ 167 | 168 | -------------------------------------------------------------------------------- /docs/css/rdoc.css: -------------------------------------------------------------------------------- 1 | /* 2 | * "Darkfish" Rdoc CSS 3 | * $Id: rdoc.css 54 2009-01-27 01:09:48Z deveiant $ 4 | * 5 | * Author: Michael Granger 6 | * 7 | */ 8 | 9 | /* vim: ft=css et sw=2 ts=2 sts=2 */ 10 | /* Base Green is: #6C8C22 */ 11 | 12 | .hide { display: none !important; } 13 | 14 | * { padding: 0; margin: 0; } 15 | 16 | body { 17 | background: #fafafa; 18 | font-family: Lato, sans-serif; 19 | font-weight: 300; 20 | } 21 | 22 | h1 span, 23 | h2 span, 24 | h3 span, 25 | h4 span, 26 | h5 span, 27 | h6 span { 28 | position: relative; 29 | 30 | display: none; 31 | padding-left: 1em; 32 | line-height: 0; 33 | vertical-align: baseline; 34 | font-size: 10px; 35 | } 36 | 37 | h1 span { top: -1.3em; } 38 | h2 span { top: -1.2em; } 39 | h3 span { top: -1.0em; } 40 | h4 span { top: -0.8em; } 41 | h5 span { top: -0.5em; } 42 | h6 span { top: -0.5em; } 43 | 44 | h1:hover span, 45 | h2:hover span, 46 | h3:hover span, 47 | h4:hover span, 48 | h5:hover span, 49 | h6:hover span { 50 | display: inline; 51 | } 52 | 53 | h1:target, 54 | h2:target, 55 | h3:target, 56 | h4:target, 57 | h5:target, 58 | h6:target { 59 | margin-left: -10px; 60 | border-left: 10px solid #f1edba; 61 | } 62 | 63 | :link, 64 | :visited { 65 | color: #6C8C22; 66 | text-decoration: none; 67 | } 68 | 69 | :link:hover, 70 | :visited:hover { 71 | border-bottom: 1px dotted #6C8C22; 72 | } 73 | 74 | code, 75 | pre { 76 | font-family: "Source Code Pro", Monaco, monospace; 77 | background-color: rgba(27,31,35,0.05); 78 | padding: 0em 0.2em; 79 | border-radius: 0.2em; 80 | } 81 | 82 | table { 83 | margin: 0; 84 | border-spacing: 0; 85 | border-collapse: collapse; 86 | } 87 | 88 | table tr th, table tr td { 89 | padding: 0.2em 0.4em; 90 | border: 1px solid #ccc; 91 | } 92 | 93 | table tr th { 94 | background-color: #eceaed; 95 | } 96 | 97 | table tr:nth-child(even) td { 98 | background-color: #f5f4f6; 99 | } 100 | 101 | /* @group Generic Classes */ 102 | 103 | .initially-hidden { 104 | display: none; 105 | } 106 | 107 | #search-field { 108 | width: 98%; 109 | background: white; 110 | border: none; 111 | height: 1.5em; 112 | -webkit-border-radius: 4px; 113 | -moz-border-radius: 4px; 114 | border-radius: 4px; 115 | text-align: left; 116 | } 117 | #search-field:focus { 118 | background: #f1edba; 119 | } 120 | #search-field:-moz-placeholder, 121 | #search-field::-webkit-input-placeholder { 122 | font-weight: bold; 123 | color: #666; 124 | } 125 | 126 | .missing-docs { 127 | font-size: 120%; 128 | background: white url(../images/wrench_orange.png) no-repeat 4px center; 129 | color: #ccc; 130 | line-height: 2em; 131 | border: 1px solid #d00; 132 | opacity: 1; 133 | padding-left: 20px; 134 | text-indent: 24px; 135 | letter-spacing: 3px; 136 | font-weight: bold; 137 | -webkit-border-radius: 5px; 138 | -moz-border-radius: 5px; 139 | } 140 | 141 | .target-section { 142 | border: 2px solid #dcce90; 143 | border-left-width: 8px; 144 | padding: 0 1em; 145 | background: #fff3c2; 146 | } 147 | 148 | /* @end */ 149 | 150 | /* @group Index Page, Standalone file pages */ 151 | .table-of-contents ul { 152 | margin: 1em; 153 | list-style: none; 154 | } 155 | 156 | .table-of-contents ul ul { 157 | margin-top: 0.25em; 158 | } 159 | 160 | .table-of-contents ul :link, 161 | .table-of-contents ul :visited { 162 | font-size: 16px; 163 | } 164 | 165 | .table-of-contents li { 166 | margin-bottom: 0.25em; 167 | } 168 | 169 | .table-of-contents li .toc-toggle { 170 | width: 16px; 171 | height: 16px; 172 | background: url(../images/add.png) no-repeat; 173 | } 174 | 175 | .table-of-contents li .toc-toggle.open { 176 | background: url(../images/delete.png) no-repeat; 177 | } 178 | 179 | /* @end */ 180 | 181 | /* @group Top-Level Structure */ 182 | 183 | nav { 184 | float: left; 185 | width: 260px; 186 | font-family: Helvetica, sans-serif; 187 | font-size: 14px; 188 | border-right: 1px solid #ccc; 189 | position: sticky; 190 | top: 0; 191 | overflow: auto; 192 | height: calc(100vh - 100px); /* reduce the footer height */ 193 | } 194 | 195 | main { 196 | display: block; 197 | margin: 0 2em 5em 260px; 198 | padding-left: 20px; 199 | min-width: 340px; 200 | font-size: 16px; 201 | } 202 | 203 | main h1, 204 | main h2, 205 | main h3, 206 | main h4, 207 | main h5, 208 | main h6 { 209 | font-family: Helvetica, sans-serif; 210 | } 211 | 212 | .table-of-contents main { 213 | margin-left: 2em; 214 | } 215 | 216 | #validator-badges { 217 | clear: both; 218 | margin: 1em 1em 2em; 219 | font-size: smaller; 220 | } 221 | 222 | /* @end */ 223 | 224 | /* @group navigation */ 225 | nav { 226 | margin-bottom: 1em; 227 | } 228 | 229 | nav .nav-section { 230 | margin-top: 2em; 231 | border-top: 2px solid #aaa; 232 | font-size: 90%; 233 | overflow: hidden; 234 | } 235 | 236 | nav h2 { 237 | margin: 0; 238 | padding: 2px 8px 2px 8px; 239 | background-color: #e8e8e8; 240 | color: #555; 241 | font-size: 125%; 242 | text-align: center; 243 | } 244 | 245 | nav h3, 246 | #table-of-contents-navigation { 247 | margin: 0; 248 | padding: 2px 8px 2px 8px; 249 | text-align: right; 250 | background-color: #e8e8e8; 251 | color: #555; 252 | } 253 | 254 | nav ul, 255 | nav dl, 256 | nav p { 257 | padding: 4px 8px 0; 258 | list-style: none; 259 | } 260 | 261 | #project-navigation .nav-section { 262 | margin: 0; 263 | border-top: 0; 264 | } 265 | 266 | #home-section h2 { 267 | text-align: center; 268 | } 269 | 270 | #table-of-contents-navigation { 271 | font-size: 1.2em; 272 | font-weight: bold; 273 | text-align: center; 274 | } 275 | 276 | #search-section { 277 | margin-top: 0; 278 | border-top: 0; 279 | } 280 | 281 | #search-field-wrapper { 282 | border-top: 1px solid #aaa; 283 | border-bottom: 1px solid #aaa; 284 | padding: 3px 8px; 285 | background-color: #e8e8e8; 286 | color: #555; 287 | } 288 | 289 | ul.link-list li { 290 | white-space: nowrap; 291 | line-height: 1.4em; 292 | } 293 | 294 | ul.link-list .type { 295 | font-size: 8px; 296 | text-transform: uppercase; 297 | color: white; 298 | background: #969696; 299 | padding: 2px 4px; 300 | -webkit-border-radius: 5px; 301 | } 302 | 303 | dl.note-list dt { 304 | float: left; 305 | margin-right: 1em; 306 | } 307 | 308 | .calls-super { 309 | background: url(../images/arrow_up.png) no-repeat right center; 310 | } 311 | 312 | .nav-section details summary { 313 | display: block; 314 | } 315 | 316 | .nav-section details summary::-webkit-details-marker { 317 | display: none; 318 | } 319 | 320 | .nav-section details summary:before { 321 | content: ""; 322 | } 323 | 324 | .nav-section details summary:after { 325 | content: " \25B6"; /* BLACK RIGHT-POINTING TRIANGLE */ 326 | } 327 | .nav-section details[open] > summary:after { 328 | content: " \25BD"; /* WHITE DOWN-POINTING TRIANGLE */ 329 | } 330 | 331 | /* @end */ 332 | 333 | /* @group Documentation Section */ 334 | main { 335 | color: #333; 336 | } 337 | 338 | main > h1:first-child, 339 | main > h2:first-child, 340 | main > h3:first-child, 341 | main > h4:first-child, 342 | main > h5:first-child, 343 | main > h6:first-child { 344 | margin-top: 0px; 345 | } 346 | 347 | main sup { 348 | vertical-align: super; 349 | font-size: 0.8em; 350 | } 351 | 352 | /* The heading with the class name */ 353 | main h1[class] { 354 | margin-top: 0; 355 | margin-bottom: 1em; 356 | font-size: 2em; 357 | color: #6C8C22; 358 | } 359 | 360 | main h1 { 361 | margin: 2em 0 0.5em; 362 | font-size: 1.7em; 363 | } 364 | 365 | main h2 { 366 | margin: 2em 0 0.5em; 367 | font-size: 1.5em; 368 | } 369 | 370 | main h3 { 371 | margin: 2em 0 0.5em; 372 | font-size: 1.2em; 373 | } 374 | 375 | main h4 { 376 | margin: 2em 0 0.5em; 377 | font-size: 1.1em; 378 | } 379 | 380 | main h5 { 381 | margin: 2em 0 0.5em; 382 | font-size: 1em; 383 | } 384 | 385 | main h6 { 386 | margin: 2em 0 0.5em; 387 | font-size: 1em; 388 | } 389 | 390 | main p { 391 | margin: 0 0 0.5em; 392 | line-height: 1.4em; 393 | } 394 | 395 | main pre { 396 | margin: 1.2em 0.5em; 397 | padding: 1em; 398 | font-size: 0.8em; 399 | } 400 | 401 | main hr { 402 | margin: 1.5em 1em; 403 | border: 2px solid #ddd; 404 | } 405 | 406 | main blockquote { 407 | margin: 0 2em 1.2em 1.2em; 408 | padding-left: 0.5em; 409 | border-left: 2px solid #ddd; 410 | } 411 | 412 | main ol, 413 | main ul { 414 | margin: 1em 2em; 415 | } 416 | 417 | main li > p { 418 | margin-bottom: 0.5em; 419 | } 420 | 421 | main dl { 422 | margin: 1em 0.5em; 423 | } 424 | 425 | main dt { 426 | margin-bottom: 0.5em; 427 | font-weight: bold; 428 | } 429 | 430 | main dd { 431 | margin: 0 1em 1em 0.5em; 432 | } 433 | 434 | main header h2 { 435 | margin-top: 2em; 436 | border-width: 0; 437 | border-top: 4px solid #bbb; 438 | font-size: 130%; 439 | } 440 | 441 | main header h3 { 442 | margin: 2em 0 1.5em; 443 | border-width: 0; 444 | border-top: 3px solid #bbb; 445 | font-size: 120%; 446 | } 447 | 448 | .documentation-section-title { 449 | position: relative; 450 | } 451 | .documentation-section-title .section-click-top { 452 | position: absolute; 453 | top: 6px; 454 | left: 12px; 455 | font-size: 10px; 456 | color: #9b9877; 457 | visibility: hidden; 458 | padding-left: 0.5px; 459 | } 460 | 461 | .documentation-section-title:hover .section-click-top { 462 | visibility: visible; 463 | } 464 | 465 | .constants-list > dl { 466 | margin: 1em 0 2em; 467 | border: 0; 468 | } 469 | 470 | .constants-list > dl dt { 471 | margin-bottom: 0.75em; 472 | padding-left: 0; 473 | font-family: "Source Code Pro", Monaco, monospace; 474 | font-size: 110%; 475 | } 476 | 477 | .constants-list > dl dt a { 478 | color: inherit; 479 | } 480 | 481 | .constants-list > dl dd { 482 | margin: 0 0 2em 0; 483 | padding: 0; 484 | color: #666; 485 | } 486 | 487 | .documentation-section h2 { 488 | position: relative; 489 | } 490 | 491 | .documentation-section h2 a { 492 | position: absolute; 493 | top: 8px; 494 | right: 10px; 495 | font-size: 12px; 496 | color: #9b9877; 497 | visibility: hidden; 498 | } 499 | 500 | .documentation-section h2:hover a { 501 | visibility: visible; 502 | } 503 | 504 | /* @group Method Details */ 505 | 506 | main .method-source-code { 507 | max-height: 0; 508 | overflow: auto; 509 | transition-duration: 200ms; 510 | transition-delay: 0ms; 511 | transition-property: all; 512 | transition-timing-function: ease-in-out; 513 | } 514 | 515 | main .method-source-code.active-menu { 516 | max-height: 100vh; 517 | } 518 | 519 | main .method-description .method-calls-super { 520 | color: #333; 521 | font-weight: bold; 522 | } 523 | 524 | main .method-detail { 525 | margin-bottom: 2.5em; 526 | cursor: pointer; 527 | } 528 | 529 | main .method-detail:target { 530 | margin-left: -10px; 531 | border-left: 10px solid #f1edba; 532 | } 533 | 534 | main .method-heading { 535 | position: relative; 536 | font-family: "Source Code Pro", Monaco, monospace; 537 | font-size: 110%; 538 | font-weight: bold; 539 | color: #333; 540 | } 541 | main .method-heading :link, 542 | main .method-heading :visited { 543 | color: inherit; 544 | } 545 | main .method-click-advice { 546 | position: absolute; 547 | top: 2px; 548 | right: 5px; 549 | font-size: 12px; 550 | color: #9b9877; 551 | visibility: hidden; 552 | padding-right: 20px; 553 | line-height: 20px; 554 | background: url(../images/zoom.png) no-repeat right top; 555 | } 556 | main .method-heading:hover .method-click-advice { 557 | visibility: visible; 558 | } 559 | 560 | main .method-alias .method-heading { 561 | color: #666; 562 | } 563 | 564 | main .method-description, 565 | main .aliases { 566 | margin-top: 0.75em; 567 | color: #333; 568 | } 569 | 570 | main .aliases { 571 | padding-top: 4px; 572 | font-style: italic; 573 | cursor: default; 574 | } 575 | main .method-description ul { 576 | margin-left: 1.5em; 577 | } 578 | 579 | main #attribute-method-details .method-detail:hover { 580 | background-color: transparent; 581 | cursor: default; 582 | } 583 | main .attribute-access-type { 584 | text-transform: uppercase; 585 | padding: 0 1em; 586 | } 587 | /* @end */ 588 | 589 | /* @end */ 590 | 591 | /* @group Source Code */ 592 | 593 | pre { 594 | margin: 0.5em 0; 595 | border: 1px dashed #999; 596 | padding: 0.5em; 597 | background: #262626; 598 | color: white; 599 | overflow: auto; 600 | } 601 | 602 | .ruby-constant { color: #7fffd4; background: transparent; } 603 | .ruby-keyword { color: #00ffff; background: transparent; } 604 | .ruby-ivar { color: #eedd82; background: transparent; } 605 | .ruby-operator { color: #00ffee; background: transparent; } 606 | .ruby-identifier { color: #ffdead; background: transparent; } 607 | .ruby-node { color: #ffa07a; background: transparent; } 608 | .ruby-comment { color: #dc0000; background: transparent; } 609 | .ruby-regexp { color: #ffa07a; background: transparent; } 610 | .ruby-value { color: #7fffd4; background: transparent; } 611 | 612 | /* @end */ 613 | 614 | 615 | /* @group search results */ 616 | #search-results { 617 | font-family: Lato, sans-serif; 618 | font-weight: 300; 619 | } 620 | 621 | #search-results .search-match { 622 | font-family: Helvetica, sans-serif; 623 | font-weight: normal; 624 | } 625 | 626 | #search-results .search-selected { 627 | background: #e8e8e8; 628 | border-bottom: 1px solid transparent; 629 | } 630 | 631 | #search-results li { 632 | list-style: none; 633 | border-bottom: 1px solid #aaa; 634 | margin-bottom: 0.5em; 635 | } 636 | 637 | #search-results li:last-child { 638 | border-bottom: none; 639 | margin-bottom: 0; 640 | } 641 | 642 | #search-results li p { 643 | padding: 0; 644 | margin: 0.5em; 645 | } 646 | 647 | #search-results .search-namespace { 648 | font-weight: bold; 649 | } 650 | 651 | #search-results li em { 652 | background: yellow; 653 | font-style: normal; 654 | } 655 | 656 | #search-results pre { 657 | margin: 0.5em; 658 | font-family: "Source Code Pro", Monaco, monospace; 659 | } 660 | 661 | /* @end */ 662 | 663 | -------------------------------------------------------------------------------- /docs/fonts/Lato-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/fonts/Lato-Light.ttf -------------------------------------------------------------------------------- /docs/fonts/Lato-LightItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/fonts/Lato-LightItalic.ttf -------------------------------------------------------------------------------- /docs/fonts/Lato-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/fonts/Lato-Regular.ttf -------------------------------------------------------------------------------- /docs/fonts/Lato-RegularItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/fonts/Lato-RegularItalic.ttf -------------------------------------------------------------------------------- /docs/fonts/SourceCodePro-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/fonts/SourceCodePro-Bold.ttf -------------------------------------------------------------------------------- /docs/fonts/SourceCodePro-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/fonts/SourceCodePro-Regular.ttf -------------------------------------------------------------------------------- /docs/images/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/add.png -------------------------------------------------------------------------------- /docs/images/arrow_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/arrow_up.png -------------------------------------------------------------------------------- /docs/images/brick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/brick.png -------------------------------------------------------------------------------- /docs/images/brick_link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/brick_link.png -------------------------------------------------------------------------------- /docs/images/bug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/bug.png -------------------------------------------------------------------------------- /docs/images/bullet_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/bullet_black.png -------------------------------------------------------------------------------- /docs/images/bullet_toggle_minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/bullet_toggle_minus.png -------------------------------------------------------------------------------- /docs/images/bullet_toggle_plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/bullet_toggle_plus.png -------------------------------------------------------------------------------- /docs/images/date.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/date.png -------------------------------------------------------------------------------- /docs/images/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/delete.png -------------------------------------------------------------------------------- /docs/images/find.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/find.png -------------------------------------------------------------------------------- /docs/images/loadingAnimation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/loadingAnimation.gif -------------------------------------------------------------------------------- /docs/images/macFFBgHack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/macFFBgHack.png -------------------------------------------------------------------------------- /docs/images/package.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/package.png -------------------------------------------------------------------------------- /docs/images/page_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/page_green.png -------------------------------------------------------------------------------- /docs/images/page_white_text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/page_white_text.png -------------------------------------------------------------------------------- /docs/images/page_white_width.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/page_white_width.png -------------------------------------------------------------------------------- /docs/images/plugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/plugin.png -------------------------------------------------------------------------------- /docs/images/ruby.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/ruby.png -------------------------------------------------------------------------------- /docs/images/tag_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/tag_blue.png -------------------------------------------------------------------------------- /docs/images/tag_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/tag_green.png -------------------------------------------------------------------------------- /docs/images/transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/transparent.png -------------------------------------------------------------------------------- /docs/images/wrench.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/wrench.png -------------------------------------------------------------------------------- /docs/images/wrench_orange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/wrench_orange.png -------------------------------------------------------------------------------- /docs/images/zoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangledpath/ruby-fann/96163a4c5d856765a2bc84ff29f0b4b57d2752bf/docs/images/zoom.png -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Ruby FANN Gem documentation 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 82 | 83 |
84 | 85 | 86 |

RubyFann

87 | 88 |

Fast AI

89 | 90 |

— Neural Networks in ruby

91 | 92 |

93 | 94 |

95 | 96 |

RubyFann, or “ruby-fann” is a Ruby Gem (no Rails required) that binds to FANN (Fast Artificial Neural Network) from within a ruby/rails environment. FANN is a is a free native open source neural network library, which implements multilayer artificial neural networks, supporting both fully-connected and sparsely-connected networks. It is easy to use, versatile, well documented, and fast. RubyFann makes working with neural networks a breeze using ruby, with the added benefit that most of the heavy lifting is done natively.

97 | 98 |

A talk given by our friend Ethan from Big-Oh Studios at Lone Star Ruby 2013: confreaks.com/videos/2609-lonestarruby2013-neural-networks-with-rubyfann

99 | 100 |

Installation

101 | 102 |

Add this line to your application’s Gemfile:

103 | 104 |
gem 'ruby-fann'
105 | 
106 | 107 |

And then execute:

108 | 109 |
$ bundle
110 | 111 |

Or install it yourself as:

112 | 113 |
$ gem install ruby-fann
114 | 115 |

Usage

116 | 117 |

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 ruby-fann gem: leenissen.dk/fann/

118 | 119 |

Documentation:

120 | 121 |

ruby-fann documentation: tangledpath.github.io/ruby-fann/index.html

122 | 123 |

Example training & subsequent execution:

124 | 125 |
require 'ruby-fann'
126 |   train = RubyFann::TrainData.new(:inputs=>[[0.3, 0.4, 0.5], [0.1, 0.2, 0.3]], :desired_outputs=>[[0.7], [0.8]])
127 |   fann = RubyFann::Standard.new(:num_inputs=>3, :hidden_neurons=>[2, 8, 4, 3, 4], :num_outputs=>1)
128 |   fann.train_on_data(train, 1000, 10, 0.1) # 1000 max_epochs, 10 errors between reports and 0.1 desired MSE (mean-squared-error)
129 |   outputs = fann.run([0.3, 0.2, 0.4])
130 | 
131 | 132 |

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

133 | 134 |
train.save('verify.train')
135 |   train = RubyFann::TrainData.new(:filename=>'verify.train')
136 |   # Train again with 10000 max_epochs, 20 errors between reports and 0.01 desired MSE (mean-squared-error)
137 |   # This will take longer:
138 |   fann.train_on_data(train, 10000, 20, 0.01)
139 | 
140 | 141 |

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

142 | 143 |
fann.save('foo.net')
144 |   saved_nn = RubyFann::Standard.new(:filename=>"foo.net")
145 |   saved_nn.run([0.3, 0.2, 0.4])
146 | 
147 | 148 |

Custom training using a callback method

149 | 150 |

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

151 | 152 |

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.

153 | 154 |

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

155 | 156 |

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

157 | 158 |
class MyFann < RubyFann::Standard
159 |   def training_callback(args)
160 |     puts "ARGS: #{args.inspect}"
161 |     0
162 |   end
163 | end
164 | 
165 | 166 |

A sample project using RubyFann to play tic-tac-toe

167 | 168 |

github.com/bigohstudios/tictactoe

169 | 170 |

Contributors

171 |
  1. 172 |

    Steven Miers

    173 |
  2. 174 |

    Ole Krüger

    175 |
  3. 176 |

    dignati

    177 |
  4. 178 |

    Michal Pokorny

    179 |
  5. 180 |

    Scott Li (locksley)

    181 |
  6. 182 |

    alex.slotty

    183 |
184 | 185 |

Contributing

186 |
  1. 187 |

    Fork it

    188 |
  2. 189 |

    Create your feature branch (git checkout -b my-new-feature)

    190 |
  3. 191 |

    Commit your changes (git commit -am 'Add some feature')

    192 |
  4. 193 |

    Push to the branch (git push origin my-new-feature)

    194 |
  5. 195 |

    Create new Pull Request

    196 |
197 | 198 |
199 | 200 | 201 | 206 | 207 | -------------------------------------------------------------------------------- /docs/js/darkfish.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Darkfish Page Functions 4 | * $Id: darkfish.js 53 2009-01-07 02:52:03Z deveiant $ 5 | * 6 | * Author: Michael Granger 7 | * 8 | */ 9 | 10 | /* Provide console simulation for firebug-less environments */ 11 | /* 12 | if (!("console" in window) || !("firebug" in console)) { 13 | var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", 14 | "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; 15 | 16 | window.console = {}; 17 | for (var i = 0; i < names.length; ++i) 18 | window.console[names[i]] = function() {}; 19 | }; 20 | */ 21 | 22 | 23 | function showSource( e ) { 24 | var target = e.target; 25 | while (!target.classList.contains('method-detail')) { 26 | target = target.parentNode; 27 | } 28 | if (typeof target !== "undefined" && target !== null) { 29 | target = target.querySelector('.method-source-code'); 30 | } 31 | if (typeof target !== "undefined" && target !== null) { 32 | target.classList.toggle('active-menu') 33 | } 34 | }; 35 | 36 | function hookSourceViews() { 37 | document.querySelectorAll('.method-heading').forEach(function (codeObject) { 38 | codeObject.addEventListener('click', showSource); 39 | }); 40 | }; 41 | 42 | function hookSearch() { 43 | var input = document.querySelector('#search-field'); 44 | var result = document.querySelector('#search-results'); 45 | result.classList.remove("initially-hidden"); 46 | 47 | var search_section = document.querySelector('#search-section'); 48 | search_section.classList.remove("initially-hidden"); 49 | 50 | var search = new Search(search_data, input, result); 51 | 52 | search.renderItem = function(result) { 53 | var li = document.createElement('li'); 54 | var html = ''; 55 | 56 | // TODO add relative path to