ruby-fann 1.2.5 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/README.md +24 -10
- data/ext/ruby_fann/config.h +4 -61
- data/ext/ruby_fann/doublefann.c +1 -1
- data/ext/ruby_fann/doublefann.h +1 -1
- data/ext/ruby_fann/fann.c +279 -28
- data/ext/ruby_fann/fann.h +11 -1
- data/ext/ruby_fann/fann_activation.h +1 -1
- data/ext/ruby_fann/fann_cascade.c +27 -10
- data/ext/ruby_fann/fann_cascade.h +55 -1
- data/ext/ruby_fann/fann_data.h +28 -3
- data/ext/ruby_fann/fann_error.c +7 -1
- data/ext/ruby_fann/fann_error.h +6 -2
- data/ext/ruby_fann/fann_internal.h +7 -3
- data/ext/ruby_fann/fann_io.c +67 -27
- data/ext/ruby_fann/fann_io.h +1 -1
- data/ext/ruby_fann/fann_train.c +86 -1
- data/ext/ruby_fann/fann_train.h +108 -1
- data/ext/ruby_fann/fann_train_data.c +144 -132
- data/lib/ruby-fann.rb +1 -1
- data/lib/ruby_fann/neurotica.rb +47 -47
- data/lib/ruby_fann/version.rb +2 -2
- data/lib/ruby_fann.rb +4 -4
- metadata +22 -24
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
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
|
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.2
|
4
|
+
version: 1.3.2
|
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: 2021-12-08 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,53 @@ 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
|
-
|
69
|
-
|
70
|
-
signing_key:
|
68
|
+
rubygems_version: 3.1.4
|
69
|
+
signing_key:
|
71
70
|
specification_version: 4
|
72
71
|
summary: Bindings to use FANN from within ruby/rails environment. Fann is a is a
|
73
72
|
free open source neural network library, which implements multilayer artificial
|
@@ -76,4 +75,3 @@ summary: Bindings to use FANN from within ruby/rails environment. Fann is a is
|
|
76
75
|
neural networks a breeze using ruby, with the added benefit that most of the heavy
|
77
76
|
lifting is done natively.
|
78
77
|
test_files: []
|
79
|
-
has_rdoc: true
|