ruby-fann 1.2.4 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +32 -13
- 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/ext/ruby_fann/ruby_fann.c +33 -0
- data/lib/ruby-fann.rb +1 -1
- data/lib/ruby_fann/neurotica.rb +49 -44
- data/lib/ruby_fann/version.rb +2 -2
- data/lib/ruby_fann.rb +4 -4
- metadata +24 -28
data/ext/ruby_fann/ruby_fann.c
CHANGED
@@ -1111,7 +1111,38 @@ static VALUE init_weights(VALUE self, VALUE train_data)
|
|
1111
1111
|
return self;
|
1112
1112
|
}
|
1113
1113
|
|
1114
|
+
/** call-seq: train(input, expected_output)
|
1114
1115
|
|
1116
|
+
Train with a single input-output pair.
|
1117
|
+
input - The inputs given to the network
|
1118
|
+
expected_output - The outputs expected. */
|
1119
|
+
static VALUE train(VALUE self, VALUE input, VALUE expected_output)
|
1120
|
+
{
|
1121
|
+
Check_Type(input, T_ARRAY);
|
1122
|
+
Check_Type(expected_output, T_ARRAY);
|
1123
|
+
|
1124
|
+
struct fann* f;
|
1125
|
+
Data_Get_Struct(self, struct fann, f);
|
1126
|
+
|
1127
|
+
unsigned int num_input = RARRAY_LEN(input);
|
1128
|
+
unsigned int num_output = RARRAY_LEN(expected_output);
|
1129
|
+
|
1130
|
+
fann_type data_input[num_input], data_output[num_output];
|
1131
|
+
|
1132
|
+
int i;
|
1133
|
+
|
1134
|
+
for (i = 0; i < num_input; i++) {
|
1135
|
+
data_input[i] = NUM2DBL(RARRAY_PTR(input)[i]);
|
1136
|
+
}
|
1137
|
+
|
1138
|
+
for (i = 0; i < num_output; i++) {
|
1139
|
+
data_output[i] = NUM2DBL(RARRAY_PTR(expected_output)[i]);
|
1140
|
+
}
|
1141
|
+
|
1142
|
+
fann_train(f, data_input, data_output);
|
1143
|
+
|
1144
|
+
return rb_int_new(0);
|
1145
|
+
}
|
1115
1146
|
|
1116
1147
|
/** call-seq: train_on_data(train_data, max_epochs, epochs_between_reports, desired_error)
|
1117
1148
|
|
@@ -1559,6 +1590,7 @@ void Init_ruby_fann ()
|
|
1559
1590
|
rb_define_method(m_rb_fann_standard_class, "print_parameters", print_parameters, 0);
|
1560
1591
|
rb_define_method(m_rb_fann_standard_class, "randomize_weights", randomize_weights, 2);
|
1561
1592
|
rb_define_method(m_rb_fann_standard_class, "run", run, 1);
|
1593
|
+
rb_define_method(m_rb_fann_standard_class, "train", train, 2);
|
1562
1594
|
rb_define_method(m_rb_fann_standard_class, "train_on_data", train_on_data, 4);
|
1563
1595
|
rb_define_method(m_rb_fann_standard_class, "train_epoch", train_epoch, 1);
|
1564
1596
|
rb_define_method(m_rb_fann_standard_class, "test_data", test_data, 1);
|
@@ -1658,6 +1690,7 @@ void Init_ruby_fann ()
|
|
1658
1690
|
rb_define_method(m_rb_fann_shortcut_class, "print_parameters", print_parameters, 0);
|
1659
1691
|
rb_define_method(m_rb_fann_shortcut_class, "randomize_weights", randomize_weights, 2);
|
1660
1692
|
rb_define_method(m_rb_fann_shortcut_class, "run", run, 1);
|
1693
|
+
rb_define_method(m_rb_fann_shortcut_class, "train", train, 2);
|
1661
1694
|
rb_define_method(m_rb_fann_shortcut_class, "train_on_data", train_on_data, 4);
|
1662
1695
|
rb_define_method(m_rb_fann_shortcut_class, "train_epoch", train_epoch, 1);
|
1663
1696
|
rb_define_method(m_rb_fann_shortcut_class, "test_data", test_data, 1);
|
data/lib/ruby-fann.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'ruby_fann'
|
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,52 +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
|
-
|
103
|
-
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
if args[:three_dimensional]
|
103
|
+
graph_viz.output(vrml: output_path)
|
104
|
+
else
|
105
|
+
graph_viz.output(png: output_path)
|
106
|
+
end
|
107
|
+
|
108
|
+
|
104
109
|
end
|
105
110
|
end
|
106
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,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-fann
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.3.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- tangledpath
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2021-12-08 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Bindings to use FANN from within ruby/rails environment
|
15
14
|
email:
|
@@ -21,56 +20,54 @@ extra_rdoc_files:
|
|
21
20
|
- README.md
|
22
21
|
- ext/ruby_fann/ruby_fann.c
|
23
22
|
files:
|
24
|
-
-
|
25
|
-
- lib/ruby_fann/neurotica.rb
|
26
|
-
- lib/ruby_fann/version.rb
|
27
|
-
- lib/ruby_fann.rb
|
28
|
-
- ext/ruby_fann/doublefann.c
|
29
|
-
- ext/ruby_fann/fann.c
|
30
|
-
- ext/ruby_fann/fann_cascade.c
|
31
|
-
- ext/ruby_fann/fann_error.c
|
32
|
-
- ext/ruby_fann/fann_io.c
|
33
|
-
- ext/ruby_fann/fann_train.c
|
34
|
-
- ext/ruby_fann/fann_train_data.c
|
35
|
-
- ext/ruby_fann/ruby_fann.c
|
23
|
+
- README.md
|
36
24
|
- ext/ruby_fann/config.h
|
25
|
+
- ext/ruby_fann/doublefann.c
|
37
26
|
- ext/ruby_fann/doublefann.h
|
27
|
+
- ext/ruby_fann/extconf.rb
|
28
|
+
- ext/ruby_fann/fann.c
|
38
29
|
- ext/ruby_fann/fann.h
|
39
30
|
- ext/ruby_fann/fann_activation.h
|
40
31
|
- ext/ruby_fann/fann_augment.h
|
32
|
+
- ext/ruby_fann/fann_cascade.c
|
41
33
|
- ext/ruby_fann/fann_cascade.h
|
42
34
|
- ext/ruby_fann/fann_data.h
|
35
|
+
- ext/ruby_fann/fann_error.c
|
43
36
|
- ext/ruby_fann/fann_error.h
|
44
37
|
- ext/ruby_fann/fann_internal.h
|
38
|
+
- ext/ruby_fann/fann_io.c
|
45
39
|
- ext/ruby_fann/fann_io.h
|
40
|
+
- ext/ruby_fann/fann_train.c
|
46
41
|
- ext/ruby_fann/fann_train.h
|
42
|
+
- ext/ruby_fann/fann_train_data.c
|
47
43
|
- ext/ruby_fann/ruby_compat.h
|
48
|
-
- ext/ruby_fann/
|
49
|
-
-
|
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
|
50
49
|
homepage: http://github.com/tangledpath/ruby-fann
|
51
50
|
licenses: []
|
52
|
-
|
51
|
+
metadata: {}
|
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
|
-
none: false
|
59
58
|
requirements:
|
60
|
-
- -
|
59
|
+
- - ">="
|
61
60
|
- !ruby/object:Gem::Version
|
62
61
|
version: '0'
|
63
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
63
|
requirements:
|
66
|
-
- -
|
64
|
+
- - ">="
|
67
65
|
- !ruby/object:Gem::Version
|
68
66
|
version: '0'
|
69
67
|
requirements: []
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
specification_version: 3
|
68
|
+
rubygems_version: 3.1.4
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
74
71
|
summary: Bindings to use FANN from within ruby/rails environment. Fann is a is a
|
75
72
|
free open source neural network library, which implements multilayer artificial
|
76
73
|
neural networks with support for both fully connected and sparsely connected networks. It
|
@@ -78,4 +75,3 @@ summary: Bindings to use FANN from within ruby/rails environment. Fann is a is
|
|
78
75
|
neural networks a breeze using ruby, with the added benefit that most of the heavy
|
79
76
|
lifting is done natively.
|
80
77
|
test_files: []
|
81
|
-
has_rdoc: true
|