ruby-fann 1.2.6 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/README.md +15 -10
- data/lib/ruby-fann.rb +1 -1
- data/lib/ruby_fann.rb +4 -4
- data/lib/ruby_fann/neurotica.rb +47 -47
- data/lib/ruby_fann/version.rb +2 -2
- metadata +22 -23
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
NGMzNjgwNDc3NjI0NTNlYjliNGI2MTc4NjE4OWViMjRkYzhjNGI3ZGRmNzM5
|
10
|
-
NjBmMWZkMzcwZWQ4NjcwYTM4ZjI1NjQ2MmM1OGY5Y2IyNWQxYjNjMTRmN2E1
|
11
|
-
YWE5MzJjYTVjNzRmMGEzNWM3NTQ3OTUwMDQ0OGFmM2I0Y2FiNWU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZTIyYWY3MDUyNDdiZDIwZDc3ZjI5YzEyZmRhNDIwNmExYTBhMzhlNzdjZDdi
|
14
|
-
N2RlZDE1YjhjMWQ4YjBkZTU3ZDkxZjRhNTYyNDFhMzUzOWVkMmRmZWRkMjkz
|
15
|
-
NjY1YmVkOWIwMzczYjU0Mzc1MzlkOWZiNzIzZDVhZGY4YjI4MTA=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4e776852e634e048d7deb249dade56d043f894e5
|
4
|
+
data.tar.gz: cee2fc3c67d0d259a31b1977ab3a823f69149805
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fcb8ca865dd8212609862b2ca026b81a862d7ae3eb2992a227bf609ddc234f74397f0c4b811bd2517f536cbd4b49b578d0344ef24817223aafc4bf41c78bc2ea
|
7
|
+
data.tar.gz: c17efd4ad1539126d9dcafc6a10a13cb499107dee2f976a0719ee780243fffc6b0ff4e3cc069f2627102cb5a1a4bb8243cc196964726425b7fd7a2d696d7e359
|
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# RubyFann
|
2
|
-
|
2
|
+
_Fast_ **AI**
|
3
|
+
---
|
4
|
+
Neural Networks in `ruby`
|
3
5
|
|
4
6
|
[![Gem Version](https://badge.fury.io/rb/ruby-fann.png)](http://badge.fury.io/rb/ruby-fann)
|
5
7
|
|
6
|
-
RubyFann, or "ruby-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
|
8
|
+
RubyFann, or "ruby-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 (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.
|
7
9
|
|
8
10
|
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
|
9
11
|
|
@@ -26,17 +28,20 @@ Or install it yourself as:
|
|
26
28
|
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:
|
27
29
|
http://leenissen.dk/fann/
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
+
## Documentation:
|
32
|
+
*ruby-fann documentation:*
|
33
|
+
http://tangledpath.github.io/ruby-fann/index.html
|
34
|
+
|
35
|
+
|
31
36
|
|
32
37
|
### Example training & subsequent execution:
|
33
|
-
|
38
|
+
|
34
39
|
```ruby
|
35
40
|
require 'ruby-fann'
|
36
41
|
train = RubyFann::TrainData.new(:inputs=>[[0.3, 0.4, 0.5], [0.1, 0.2, 0.3]], :desired_outputs=>[[0.7], [0.8]])
|
37
42
|
fann = RubyFann::Standard.new(:num_inputs=>3, :hidden_neurons=>[2, 8, 4, 3, 4], :num_outputs=>1)
|
38
43
|
fann.train_on_data(train, 1000, 10, 0.1) # 1000 max_epochs, 10 errors between reports and 0.1 desired MSE (mean-squared-error)
|
39
|
-
outputs = fann.run([0.3, 0.2, 0.4])
|
44
|
+
outputs = fann.run([0.3, 0.2, 0.4])
|
40
45
|
```
|
41
46
|
|
42
47
|
### Save training data to file and use it later (continued from above)
|
@@ -46,7 +51,7 @@ http://ruby-fann.rubyforge.org/
|
|
46
51
|
train = RubyFann::TrainData.new(:filename=>'verify.train')
|
47
52
|
# Train again with 10000 max_epochs, 20 errors between reports and 0.01 desired MSE (mean-squared-error)
|
48
53
|
# This will take longer:
|
49
|
-
fann.train_on_data(train, 10000, 20, 0.01)
|
54
|
+
fann.train_on_data(train, 10000, 20, 0.01)
|
50
55
|
```
|
51
56
|
|
52
57
|
### Save trained network to file and use it later (continued from above)
|
@@ -54,9 +59,9 @@ http://ruby-fann.rubyforge.org/
|
|
54
59
|
```ruby
|
55
60
|
fann.save('foo.net')
|
56
61
|
saved_nn = RubyFann::Standard.new(:filename=>"foo.net")
|
57
|
-
saved_nn.run([0.3, 0.2, 0.4])
|
62
|
+
saved_nn.run([0.3, 0.2, 0.4])
|
58
63
|
```
|
59
|
-
|
64
|
+
|
60
65
|
### Custom training using a callback method
|
61
66
|
|
62
67
|
This callback function can be called during training when using train_on_data, train_on_file or cascadetrain_on_data.
|
@@ -71,7 +76,7 @@ The callback (training_callback) will be automatically called if it is implement
|
|
71
76
|
class MyFann < RubyFann::Standard
|
72
77
|
def training_callback(args)
|
73
78
|
puts "ARGS: #{args.inspect}"
|
74
|
-
0
|
79
|
+
0
|
75
80
|
end
|
76
81
|
end
|
77
82
|
```
|
data/lib/ruby-fann.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'ruby_fann'
|
data/lib/ruby_fann.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'ruby_fann/version'
|
2
|
+
require 'ruby_fann/ruby_fann'
|
3
3
|
|
4
4
|
# Namespace for ruby-fann functionality.
|
5
5
|
#
|
6
6
|
# See RubyFann::Shortcut, RubyFann::Standard, and RubyFann::TrainData for details.
|
7
|
-
module RubyFann
|
8
|
-
|
7
|
+
module RubyFann
|
8
|
+
|
9
9
|
end
|
data/lib/ruby_fann/neurotica.rb
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'rubygems'
|
2
|
+
require 'graphviz'
|
3
3
|
|
4
4
|
module RubyFann
|
5
5
|
# Generates directed graph from a RubyFann neural network.
|
6
|
-
# Requires the GraphViz gem 0.8.0 (or higher) to be installed,
|
6
|
+
# Requires the GraphViz gem 0.8.0 (or higher) to be installed,
|
7
7
|
# as well as graphviz proper 2.14.1 (or higher).
|
8
8
|
class Neurotica # :nodoc:
|
9
9
|
attr_accessor :connector_colors
|
10
10
|
attr_accessor :input_layer_color
|
11
11
|
attr_accessor :hidden_layer_colors
|
12
12
|
attr_accessor :output_layer_color
|
13
|
-
|
13
|
+
|
14
14
|
# Initialize neurotica grapher with the following args:
|
15
15
|
# :connector_colors - array of graphviz-friendly color names/numbers
|
16
16
|
# :input_layer_color - graphviz-friendly color name/number
|
17
17
|
# :hidden_layer_colors - array of graphviz-friendly color names/numbers
|
18
18
|
# :output_layer_color - graphviz-friendly color name/number
|
19
|
-
def initialize(args={})
|
19
|
+
def initialize(args = {})
|
20
20
|
@connector_colors = args[:connector_colors]
|
21
21
|
@input_layer_color = args[:input_layer_color]
|
22
22
|
@hidden_layer_colors = args[:hidden_layer_colors]
|
23
23
|
@output_layer_color = args[:output_layer_color]
|
24
|
-
@connector_colors ||= ['red', 'blue', 'yellow', 'green', 'orange', 'black', 'pink', 'gold', 'lightblue', 'firebrick4', 'purple']
|
24
|
+
@connector_colors ||= ['red', 'blue', 'yellow', 'green', 'orange', 'black', 'pink', 'gold', 'lightblue', 'firebrick4', 'purple']
|
25
25
|
@input_layer_color ||= 'green'
|
26
|
-
@hidden_layer_colors ||= ['bisque2', 'yellow', 'blue', 'orange', 'khaki3']
|
26
|
+
@hidden_layer_colors ||= ['bisque2', 'yellow', 'blue', 'orange', 'khaki3']
|
27
27
|
@output_layer_color ||= 'purple'
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# Generate output graph with given neural network to the given output path (PNG)
|
31
31
|
# If args[:three_dimensional] is set, then a 3d VRML graph will be generated (experimental)
|
32
|
-
def graph(neural_net, output_path, args={})
|
33
|
-
if
|
34
|
-
graph_viz = GraphViz::new(
|
35
|
-
shape=
|
32
|
+
def graph(neural_net, output_path, args = {})
|
33
|
+
if args[:three_dimensional]
|
34
|
+
graph_viz = GraphViz::new( 'G', :dim=>'3') # , :size=>'17,11'
|
35
|
+
shape = 'point'
|
36
36
|
else
|
37
|
-
graph_viz = GraphViz::new(
|
38
|
-
shape=
|
37
|
+
graph_viz = GraphViz::new( 'G', :dim=>'2') # , :size=>'17,11'
|
38
|
+
shape = 'egg'
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
neurons = neural_net.get_neurons()
|
42
42
|
graph_node_hash = {}
|
43
43
|
max_layer = neurons.max {|a,b| a[:layer] <=> b[:layer] }[:layer]
|
@@ -45,7 +45,7 @@ module RubyFann
|
|
45
45
|
|
46
46
|
# Add nodes:
|
47
47
|
neurons.each do |neuron|
|
48
|
-
fillcolor =
|
48
|
+
fillcolor = 'transparent' # : "khaki3"
|
49
49
|
layer = neuron[:layer]
|
50
50
|
fillcolor = case layer
|
51
51
|
when 0
|
@@ -55,57 +55,57 @@ module RubyFann
|
|
55
55
|
else
|
56
56
|
@hidden_layer_colors[(layer-1) % @hidden_layer_colors.length]
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
#puts "adding neuron with #{neuron[:value]}"
|
60
60
|
node_id = neuron.object_id.to_s
|
61
|
-
# label = (layer==0) ? ("%d-%0.3f-%0.3f" % [neuron[:layer], neuron[:value], neuron[:sum]]) : ("%d-%0.3f-%0.3f" % [neuron[:layer], neuron[:value], neuron[:sum]])
|
62
|
-
label = (layer==0 || layer==max_layer) ? (
|
61
|
+
# label = (layer==0) ? ("%d-%0.3f-%0.3f" % [neuron[:layer], neuron[:value], neuron[:sum]]) : ("%d-%0.3f-%0.3f" % [neuron[:layer], neuron[:value], neuron[:sum]])
|
62
|
+
label = (layer == 0 || layer == max_layer) ? ('%0.3f' % neuron[:value]) : ('%0.3f' % rand) #neuron[:sum])
|
63
63
|
graph_node_hash[node_id] = graph_viz.add_node(
|
64
64
|
node_id,
|
65
|
-
:label
|
66
|
-
:
|
67
|
-
:fillcolor
|
68
|
-
|
69
|
-
:shape
|
70
|
-
:
|
71
|
-
# :
|
72
|
-
# :
|
73
|
-
# :
|
74
|
-
:
|
75
|
-
)
|
65
|
+
label: label,
|
66
|
+
style: 'filled',
|
67
|
+
fillcolor: fillcolor,
|
68
|
+
# color: fillcolor,
|
69
|
+
shape: shape,
|
70
|
+
z: '#{rand(100)}', # TODO
|
71
|
+
# z: '0', # TODO
|
72
|
+
# width: '1',
|
73
|
+
# height: '1',
|
74
|
+
fontname: 'Verdana'
|
75
|
+
)
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
previous_neurons = nil
|
79
79
|
layer_neurons = nil
|
80
80
|
0.upto(max_layer) do |layer|
|
81
81
|
previous_neurons = layer_neurons
|
82
|
-
layer_neurons = neurons.find_all{|n| n[:layer]==layer}
|
83
|
-
|
82
|
+
layer_neurons = neurons.find_all { |n| n[:layer] == layer }
|
83
|
+
|
84
84
|
if previous_neurons
|
85
85
|
previous_neurons.each do |pn|
|
86
86
|
node_id = pn.object_id.to_s
|
87
|
-
|
87
|
+
|
88
88
|
layer_neurons.each do |n|
|
89
89
|
dest_id = n.object_id.to_s
|
90
90
|
graph_viz.add_edge(
|
91
|
-
graph_node_hash[node_id],
|
92
|
-
graph_node_hash[dest_id],
|
93
|
-
:
|
94
|
-
:
|
95
|
-
)
|
91
|
+
graph_node_hash[node_id],
|
92
|
+
graph_node_hash[dest_id],
|
93
|
+
weight: '10',
|
94
|
+
color: "#{connector_colors[layer % connector_colors.length]}"
|
95
|
+
)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
if
|
103
|
-
graph_viz.output(:
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
if args[:three_dimensional]
|
103
|
+
graph_viz.output(vrml: output_path)
|
104
104
|
else
|
105
|
-
graph_viz.output(:
|
105
|
+
graph_viz.output(png: output_path)
|
106
106
|
end
|
107
|
-
|
108
|
-
|
107
|
+
|
108
|
+
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end
|
data/lib/ruby_fann/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-fann
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tangledpath
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Bindings to use FANN from within ruby/rails environment
|
14
14
|
email:
|
@@ -20,54 +20,54 @@ extra_rdoc_files:
|
|
20
20
|
- README.md
|
21
21
|
- ext/ruby_fann/ruby_fann.c
|
22
22
|
files:
|
23
|
-
-
|
24
|
-
- lib/ruby_fann/neurotica.rb
|
25
|
-
- lib/ruby_fann/version.rb
|
26
|
-
- lib/ruby_fann.rb
|
27
|
-
- ext/ruby_fann/doublefann.c
|
28
|
-
- ext/ruby_fann/fann.c
|
29
|
-
- ext/ruby_fann/fann_cascade.c
|
30
|
-
- ext/ruby_fann/fann_error.c
|
31
|
-
- ext/ruby_fann/fann_io.c
|
32
|
-
- ext/ruby_fann/fann_train.c
|
33
|
-
- ext/ruby_fann/fann_train_data.c
|
34
|
-
- ext/ruby_fann/ruby_fann.c
|
23
|
+
- README.md
|
35
24
|
- ext/ruby_fann/config.h
|
25
|
+
- ext/ruby_fann/doublefann.c
|
36
26
|
- ext/ruby_fann/doublefann.h
|
27
|
+
- ext/ruby_fann/extconf.rb
|
28
|
+
- ext/ruby_fann/fann.c
|
37
29
|
- ext/ruby_fann/fann.h
|
38
30
|
- ext/ruby_fann/fann_activation.h
|
39
31
|
- ext/ruby_fann/fann_augment.h
|
32
|
+
- ext/ruby_fann/fann_cascade.c
|
40
33
|
- ext/ruby_fann/fann_cascade.h
|
41
34
|
- ext/ruby_fann/fann_data.h
|
35
|
+
- ext/ruby_fann/fann_error.c
|
42
36
|
- ext/ruby_fann/fann_error.h
|
43
37
|
- ext/ruby_fann/fann_internal.h
|
38
|
+
- ext/ruby_fann/fann_io.c
|
44
39
|
- ext/ruby_fann/fann_io.h
|
40
|
+
- ext/ruby_fann/fann_train.c
|
45
41
|
- ext/ruby_fann/fann_train.h
|
42
|
+
- ext/ruby_fann/fann_train_data.c
|
46
43
|
- ext/ruby_fann/ruby_compat.h
|
47
|
-
- ext/ruby_fann/
|
48
|
-
-
|
44
|
+
- ext/ruby_fann/ruby_fann.c
|
45
|
+
- lib/ruby-fann.rb
|
46
|
+
- lib/ruby_fann.rb
|
47
|
+
- lib/ruby_fann/neurotica.rb
|
48
|
+
- lib/ruby_fann/version.rb
|
49
49
|
homepage: http://github.com/tangledpath/ruby-fann
|
50
50
|
licenses: []
|
51
51
|
metadata: {}
|
52
|
-
post_install_message:
|
52
|
+
post_install_message:
|
53
53
|
rdoc_options: []
|
54
54
|
require_paths:
|
55
55
|
- lib
|
56
56
|
- ext
|
57
57
|
required_ruby_version: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
|
-
- -
|
64
|
+
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
68
|
rubyforge_project: ruby-fann
|
69
|
-
rubygems_version: 2.
|
70
|
-
signing_key:
|
69
|
+
rubygems_version: 2.6.10
|
70
|
+
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: Bindings to use FANN from within ruby/rails environment. Fann is a is a
|
73
73
|
free open source neural network library, which implements multilayer artificial
|
@@ -76,4 +76,3 @@ summary: Bindings to use FANN from within ruby/rails environment. Fann is a is
|
|
76
76
|
neural networks a breeze using ruby, with the added benefit that most of the heavy
|
77
77
|
lifting is done natively.
|
78
78
|
test_files: []
|
79
|
-
has_rdoc: true
|