ruby_brain 0.1.0 → 0.1.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 +4 -4
- data/README.org +2 -2
- data/lib/ruby_brain/network.rb +33 -5
- data/lib/ruby_brain/version.rb +1 -1
- data/ruby_brain.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1b359c7dfcb72a2c865c0eb3132d795a14e865b
|
4
|
+
data.tar.gz: cf67ab8cb83e45351d9436b739851813e42dcf27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2f45afd551e3695dd6661bf68d769d40705ca7b0195156fbc6aaec61ccb796511a8b143439c2e109c867ef3dfaf485ac403bb48e350c4b0b28d96c98568a11d
|
7
|
+
data.tar.gz: 1490f842fd47da4290fff7158bdb72c987ff946b02a3f3ccf9feace7ef21fdfb2cb55a11b3dc4c798af52aa1836f27303d067f95918dd35d9b2395dac0b017c7
|
data/README.org
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
|
39
39
|
*** example "AND"
|
40
40
|
Now we assume that we train a network to operate as "AND operator"
|
41
|
-
The
|
41
|
+
The trueth table of "AND operator" is as below.
|
42
42
|
In short, when both "in 1" and "in 2" are 1, the "out" should be 1
|
43
43
|
and 0 should be output for other input combinations.
|
44
44
|
|
@@ -49,7 +49,7 @@
|
|
49
49
|
| 1 | 0 | 0 |
|
50
50
|
| 1 | 1 | 1 |
|
51
51
|
|
52
|
-
In this situation, you can prepare the dataset
|
52
|
+
In this situation, you can prepare the dataset like following Ruby array.
|
53
53
|
#+BEGIN_SRC ruby
|
54
54
|
training_input_set = [
|
55
55
|
[0, 0],
|
data/lib/ruby_brain/network.rb
CHANGED
@@ -4,7 +4,14 @@ module RubyBrain
|
|
4
4
|
def_delegators :@weights_set, :overwrite_weights, :get_weights_as_array
|
5
5
|
|
6
6
|
attr_accessor :learning_rate
|
7
|
-
|
7
|
+
|
8
|
+
# Constructor of Network class
|
9
|
+
#
|
10
|
+
# @example network structure Array(num_units_list)
|
11
|
+
# [10, 30, 3] # => 3 inputs, hidden layer 1 with 30 units, 3 outputs
|
12
|
+
# [15, 50, 60, 10] # => 15 inputs, hidden layer 1 with 50 units, hidden layer 2 with 60 units, 10 outputs
|
13
|
+
#
|
14
|
+
# @param num_units_list [Array] Array which describes the network structure
|
8
15
|
def initialize(num_units_list)
|
9
16
|
@layers = []
|
10
17
|
@num_units_list = num_units_list
|
@@ -20,6 +27,7 @@ module RubyBrain
|
|
20
27
|
# @weights_set.overwrite_weights(weights_set_source)
|
21
28
|
# end
|
22
29
|
|
30
|
+
# Initialize the network. This method creates network actually based on the network structure Array which specified with Constructor.
|
23
31
|
def init_network
|
24
32
|
@layers = []
|
25
33
|
layer = Layer.new
|
@@ -52,7 +60,9 @@ module RubyBrain
|
|
52
60
|
# @weights_set.get_weights_as_array
|
53
61
|
# end
|
54
62
|
|
55
|
-
|
63
|
+
# Calculate the network output of forward propagation.
|
64
|
+
#
|
65
|
+
# @param inputs [Array] Input dataset.
|
56
66
|
def get_forward_outputs(inputs)
|
57
67
|
inputs.each_with_index do |input, i|
|
58
68
|
@layers.first.nodes[i].value = input
|
@@ -66,7 +76,10 @@ module RubyBrain
|
|
66
76
|
end
|
67
77
|
a_layer_outputs
|
68
78
|
end
|
69
|
-
|
79
|
+
|
80
|
+
# Calculate the networkoutput of backward propagation.
|
81
|
+
#
|
82
|
+
# @param backward_inputs [Array] Input for backpropagation. Usually it is loss values.
|
70
83
|
def run_backpropagate(backward_inputs)
|
71
84
|
a_layer_outputs = nil
|
72
85
|
a_layer_inputs = backward_inputs
|
@@ -77,6 +90,8 @@ module RubyBrain
|
|
77
90
|
a_layer_outputs
|
78
91
|
end
|
79
92
|
|
93
|
+
# Updates weights actually based on the result of backward propagation
|
94
|
+
#
|
80
95
|
def update_weights
|
81
96
|
@weights_set.each_weights_with_index do |weights, i|
|
82
97
|
weights.each_with_index do |wl, j|
|
@@ -111,7 +126,14 @@ module RubyBrain
|
|
111
126
|
# end
|
112
127
|
# Math.sqrt(2.0 * accumulated_errors / training_inputs_set.size)
|
113
128
|
# end
|
114
|
-
|
129
|
+
|
130
|
+
# Starts training with training dataset
|
131
|
+
#
|
132
|
+
# @param inputs_set [Array<Array>] Input dataset for training. The structure is 2 dimentional Array. Eatch dimentions correspond to samples and features.
|
133
|
+
# @param outputs_set [Array<Array>] Output dataset for training. The structure is 2 dimentional Array. Eatch dimentions correspond to samples and features.
|
134
|
+
# @param max_training_count [Integer] Max training count.
|
135
|
+
# @param tolerance [Float] The Threshold to stop training. Training is stopped when RMS error reach to this value even if training count is not max_training_count.
|
136
|
+
# @param monitoring_channels [Array<Symbol>] Specify which log should be reported. Now you can select only `:best_params_training`
|
115
137
|
def learn(inputs_set, outputs_set, max_training_count=50, tolerance=0.0, monitoring_channels=[])
|
116
138
|
raise RubyBrain::Exception::TrainingDataError if inputs_set.size != outputs_set.size
|
117
139
|
# raise "inputs_set and outputs_set has different size!!!!" if inputs_set.size != outputs_set.size
|
@@ -240,10 +262,16 @@ module RubyBrain
|
|
240
262
|
end
|
241
263
|
end
|
242
264
|
|
265
|
+
# Dumps weights of the network into a file whose format is YAML.
|
266
|
+
#
|
267
|
+
# @param file_name [String] The path to the YAML file in which weights are saved.
|
243
268
|
def dump_weights_to_yaml(file_name=nil)
|
244
269
|
@weights_set.dump_to_yaml(file_name)
|
245
270
|
end
|
246
|
-
|
271
|
+
|
272
|
+
# Loads weights of the network from existing weights file whose format is YAML.
|
273
|
+
#
|
274
|
+
# @param yaml_file [String] The path to the YAML file which includes weights.
|
247
275
|
def load_weights_from_yaml_file(yaml_file)
|
248
276
|
@weights_set.load_from_yaml_file(yaml_file)
|
249
277
|
end
|
data/lib/ruby_brain/version.rb
CHANGED
data/ruby_brain.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["elgoog"]
|
10
10
|
spec.email = ["elgoog.development@gmail.com"]
|
11
11
|
spec.summary = %q{NeuralNet/DeepLearning implement for Ruby}
|
12
|
-
spec.description = %q{
|
12
|
+
spec.description = %q{Neural Net, Deep Learning implement for Ruby}
|
13
13
|
spec.homepage = "https://github.com/elgoog/ruby_brain/"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_brain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- elgoog
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description: Neural Net, Deep Learning implement for Ruby
|
70
70
|
email:
|
71
71
|
- elgoog.development@gmail.com
|
72
72
|
executables: []
|