ruby-dnn 0.5.11 → 0.5.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/API-Reference.ja.md +32 -3
- data/lib/dnn/core/rnn_layers.rb +71 -78
- data/lib/dnn/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96c9ff5d01c5d85fc4aff092d5985db64e8848d8e0ce2da952afb28c49794d7c
|
4
|
+
data.tar.gz: 7860cf4b52fa8742fe01b42039a91b183efe6b0d50a41c14533e844d3c687c95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5df63c654235145dcecc470b1510c2ad920c3fae83559888e79a30932cc0aea53cda0d11f6c4b732cece9a58dded024e5a9c8baf1f6df4433bb580dbd8f3139
|
7
|
+
data.tar.gz: a73018f21c4432062ff7cac5fc4317667d28ee78607e9cf80573c8dc8d884cf98314cfd8f7eb284e5d26d623129541c2e3b9b2b89bf477f543748b4c245767c0
|
data/API-Reference.ja.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
ruby-dnnのAPIリファレンスです。このリファレンスでは、APIを利用するうえで必要となるクラスとメソッドしか記載していません。
|
3
3
|
そのため、プログラムの詳細が必要な場合は、ソースコードを参照してください。
|
4
4
|
|
5
|
-
最終更新バージョン:0.5.
|
5
|
+
最終更新バージョン:0.5.12
|
6
6
|
|
7
7
|
# module DNN
|
8
8
|
ruby-dnnの名前空間をなすモジュールです。
|
@@ -395,8 +395,8 @@ Array
|
|
395
395
|
Arrayで指定する場合、[Integer height, Integer width]の形式で指定します。
|
396
396
|
|
397
397
|
|
398
|
-
# class
|
399
|
-
|
398
|
+
# class RNN < HasParamLayer
|
399
|
+
全てのリカレントニューラルネットワークのレイヤーのスーパークラスです。
|
400
400
|
|
401
401
|
## 【Properties】
|
402
402
|
|
@@ -419,6 +419,31 @@ Float
|
|
419
419
|
### arguments
|
420
420
|
* Integer num_nodes
|
421
421
|
レイヤーのノード数を設定します。
|
422
|
+
* bool stateful
|
423
|
+
trueを設定すると、一つ前に計算した中間層の値を使用して学習を行うことができます。
|
424
|
+
* bool return_sequences
|
425
|
+
trueを設定すると、時系列ネットワークの中間層全てを出力します。
|
426
|
+
falseを設定すると、時系列ネットワークの中間層の最後のみを出力します。
|
427
|
+
* Initializer weight_initializer: nil
|
428
|
+
重みの初期化に使用するイニシャライザーを設定します。
|
429
|
+
nilを指定すると、RandomNormalイニシャライザーが使用されます。
|
430
|
+
* Initializer bias_initializer: nil
|
431
|
+
バイアスの初期化に使用するイニシャライザーを設定します。
|
432
|
+
nilを指定すると、Zerosイニシャライザーが使用されます。
|
433
|
+
* Float weight_decay: 0
|
434
|
+
重み減衰の係数を設定します。
|
435
|
+
|
436
|
+
|
437
|
+
# class SimpleRNN < RNN
|
438
|
+
シンプルなRNNレイヤーを扱うクラスです。
|
439
|
+
|
440
|
+
## 【Instance methods】
|
441
|
+
|
442
|
+
## def initialize(num_nodes, stateful: false, return_sequences: true, activation: nil, weight_initializer: nil, bias_initializer: nil, weight_decay: 0)
|
443
|
+
コンストラクタ。
|
444
|
+
### arguments
|
445
|
+
* Integer num_nodes
|
446
|
+
レイヤーのノード数を設定します。
|
422
447
|
* bool stateful
|
423
448
|
trueを設定すると、一つ前に計算した中間層の値を使用して学習を行うことができます。
|
424
449
|
* bool return_sequences
|
@@ -437,6 +462,10 @@ nilを指定すると、Zerosイニシャライザーが使用されます。
|
|
437
462
|
重み減衰の係数を設定します。
|
438
463
|
|
439
464
|
|
465
|
+
# class LSTM < RNN
|
466
|
+
LSTMレイヤーを扱うクラスです。
|
467
|
+
|
468
|
+
|
440
469
|
# class Flatten
|
441
470
|
N次元のデータを平坦化します。
|
442
471
|
|
data/lib/dnn/core/rnn_layers.rb
CHANGED
@@ -1,6 +1,65 @@
|
|
1
1
|
module DNN
|
2
2
|
module Layers
|
3
3
|
|
4
|
+
# Super class of all RNN classes.
|
5
|
+
class RNN < HasParamLayer
|
6
|
+
include Initializers
|
7
|
+
include Activations
|
8
|
+
|
9
|
+
attr_reader :num_nodes
|
10
|
+
attr_reader :stateful
|
11
|
+
attr_reader :weight_decay
|
12
|
+
|
13
|
+
def initialize(num_nodes,
|
14
|
+
stateful: false,
|
15
|
+
return_sequences: true,
|
16
|
+
weight_initializer: nil,
|
17
|
+
bias_initializer: nil,
|
18
|
+
weight_decay: 0)
|
19
|
+
super()
|
20
|
+
@num_nodes = num_nodes
|
21
|
+
@stateful = stateful
|
22
|
+
@return_sequences = return_sequences
|
23
|
+
@weight_initializer = (weight_initializer || RandomNormal.new)
|
24
|
+
@bias_initializer = (bias_initializer || Zeros.new)
|
25
|
+
@weight_decay = weight_decay
|
26
|
+
@layers = []
|
27
|
+
@h = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_hash(merge_hash = nil)
|
31
|
+
hash = {
|
32
|
+
name: self.class.name,
|
33
|
+
num_nodes: @num_nodes,
|
34
|
+
stateful: @stateful,
|
35
|
+
return_sequences: @return_sequences,
|
36
|
+
activation: @activation.to_hash,
|
37
|
+
weight_initializer: @weight_initializer.to_hash,
|
38
|
+
bias_initializer: @bias_initializer.to_hash,
|
39
|
+
weight_decay: @weight_decay,
|
40
|
+
}
|
41
|
+
hash.merge!(merge_hash) if merge_hash
|
42
|
+
hash
|
43
|
+
end
|
44
|
+
|
45
|
+
def shape
|
46
|
+
@return_sequences ? [@time_length, @num_nodes] : [@num_nodes]
|
47
|
+
end
|
48
|
+
|
49
|
+
def ridge
|
50
|
+
if @weight_decay > 0
|
51
|
+
0.5 * (@weight_decay * (@params[:weight]**2).sum + @weight_decay * (@params[:weight]**2).sum)
|
52
|
+
else
|
53
|
+
0
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def init_params
|
58
|
+
@time_length = prev_layer.shape[0]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
4
63
|
class SimpleRNN_Dense
|
5
64
|
def initialize(params, grads, activation)
|
6
65
|
@params = params
|
@@ -27,14 +86,7 @@ module DNN
|
|
27
86
|
end
|
28
87
|
|
29
88
|
|
30
|
-
class SimpleRNN <
|
31
|
-
include Initializers
|
32
|
-
include Activations
|
33
|
-
|
34
|
-
attr_reader :num_nodes
|
35
|
-
attr_reader :stateful
|
36
|
-
attr_reader :weight_decay
|
37
|
-
|
89
|
+
class SimpleRNN < RNN
|
38
90
|
def self.load_hash(hash)
|
39
91
|
self.new(hash[:num_nodes],
|
40
92
|
stateful: hash[:stateful],
|
@@ -52,16 +104,13 @@ module DNN
|
|
52
104
|
weight_initializer: nil,
|
53
105
|
bias_initializer: nil,
|
54
106
|
weight_decay: 0)
|
55
|
-
super(
|
56
|
-
|
57
|
-
|
58
|
-
|
107
|
+
super(num_nodes,
|
108
|
+
stateful: stateful,
|
109
|
+
return_sequences: return_sequences,
|
110
|
+
weight_initializer: weight_initializer,
|
111
|
+
bias_initializer: bias_initializer,
|
112
|
+
weight_decay: weight_decay)
|
59
113
|
@activation = (activation || Tanh.new)
|
60
|
-
@weight_initializer = (weight_initializer || RandomNormal.new)
|
61
|
-
@bias_initializer = (bias_initializer || Zeros.new)
|
62
|
-
@weight_decay = weight_decay
|
63
|
-
@layers = []
|
64
|
-
@h = nil
|
65
114
|
end
|
66
115
|
|
67
116
|
def forward(xs)
|
@@ -96,32 +145,14 @@ module DNN
|
|
96
145
|
dxs
|
97
146
|
end
|
98
147
|
|
99
|
-
def shape
|
100
|
-
@return_sequences ? [@time_length, @num_nodes] : [@num_nodes]
|
101
|
-
end
|
102
|
-
|
103
|
-
def ridge
|
104
|
-
if @weight_decay > 0
|
105
|
-
0.5 * (@weight_decay * (@params[:weight]**2).sum + @weight_decay * (@params[:weight]**2).sum)
|
106
|
-
else
|
107
|
-
0
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
148
|
def to_hash
|
112
|
-
super({
|
113
|
-
stateful: @stateful,
|
114
|
-
return_sequences: @return_sequences,
|
115
|
-
activation: @activation.to_hash,
|
116
|
-
weight_initializer: @weight_initializer.to_hash,
|
117
|
-
bias_initializer: @bias_initializer.to_hash,
|
118
|
-
weight_decay: @weight_decay})
|
149
|
+
super({activation: @activation.to_hash})
|
119
150
|
end
|
120
151
|
|
121
152
|
private
|
122
153
|
|
123
154
|
def init_params
|
124
|
-
|
155
|
+
super()
|
125
156
|
num_prev_nodes = prev_layer.shape[1]
|
126
157
|
@params[:weight] = Xumo::SFloat.new(num_prev_nodes, @num_nodes)
|
127
158
|
@params[:weight2] = Xumo::SFloat.new(@num_nodes, @num_nodes)
|
@@ -187,15 +218,7 @@ module DNN
|
|
187
218
|
end
|
188
219
|
|
189
220
|
|
190
|
-
|
191
|
-
class LSTM < HasParamLayer
|
192
|
-
include Initializers
|
193
|
-
include Activations
|
194
|
-
|
195
|
-
attr_reader :num_nodes
|
196
|
-
attr_reader :stateful
|
197
|
-
attr_reader :weight_decay
|
198
|
-
|
221
|
+
class LSTM < RNN
|
199
222
|
def self.load_hash(hash)
|
200
223
|
self.new(hash[:num_nodes],
|
201
224
|
stateful: hash[:stateful],
|
@@ -211,16 +234,7 @@ module DNN
|
|
211
234
|
weight_initializer: nil,
|
212
235
|
bias_initializer: nil,
|
213
236
|
weight_decay: 0)
|
214
|
-
super
|
215
|
-
@num_nodes = num_nodes
|
216
|
-
@stateful = stateful
|
217
|
-
@return_sequences = return_sequences
|
218
|
-
@weight_initializer = (weight_initializer || RandomNormal.new)
|
219
|
-
@bias_initializer = (bias_initializer || Zeros.new)
|
220
|
-
@weight_decay = weight_decay
|
221
|
-
@layers = []
|
222
|
-
@h = nil
|
223
|
-
@cell = nil
|
237
|
+
super
|
224
238
|
end
|
225
239
|
|
226
240
|
def forward(xs)
|
@@ -264,31 +278,10 @@ module DNN
|
|
264
278
|
dxs
|
265
279
|
end
|
266
280
|
|
267
|
-
def shape
|
268
|
-
@return_sequences ? [@time_length, @num_nodes] : [@num_nodes]
|
269
|
-
end
|
270
|
-
|
271
|
-
def ridge
|
272
|
-
if @weight_decay > 0
|
273
|
-
0.5 * (@weight_decay * (@params[:weight]**2).sum + @weight_decay * (@params[:weight]**2).sum)
|
274
|
-
else
|
275
|
-
0
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
def to_hash
|
280
|
-
super({num_nodes: @num_nodes,
|
281
|
-
stateful: @stateful,
|
282
|
-
return_sequences: @return_sequences,
|
283
|
-
weight_initializer: @weight_initializer.to_hash,
|
284
|
-
bias_initializer: @bias_initializer.to_hash,
|
285
|
-
weight_decay: @weight_decay})
|
286
|
-
end
|
287
|
-
|
288
281
|
private
|
289
282
|
|
290
283
|
def init_params
|
291
|
-
|
284
|
+
super()
|
292
285
|
num_prev_nodes = prev_layer.shape[1]
|
293
286
|
@params[:weight] = Xumo::SFloat.new(num_prev_nodes, @num_nodes * 4)
|
294
287
|
@params[:weight2] = Xumo::SFloat.new(@num_nodes, @num_nodes * 4)
|
data/lib/dnn/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-dnn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- unagiootoro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|