ruby-dnn 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61defa3dd2c7b95ac7d3c3484789abfc7ec792be0fd4dea728fee628479fcf76
4
- data.tar.gz: 12e3a398119eb5a64eec7578b6fb3263dca4a5a1028300ab97b47194766bf65b
3
+ metadata.gz: 3b897e7f51a4bf649e3bc9b0207dd3dbea30fc35d50ca4cf5ff08c7f8daacb4c
4
+ data.tar.gz: '078b1fa114f3abe04cc40e2e01211f3a563c2796bc9da78b904478ad0a5e83ac'
5
5
  SHA512:
6
- metadata.gz: cf23b2ea6cb6d00fa2a6b822c309e0db6677f890be18c43f910aae41ea3fee0342734434f349c98e597620b2729d3a165aa8c135f4ecb94d53343bbe49709f9a
7
- data.tar.gz: 44c73b4b066a2026a2fa5d6ca81c52fdefb4c411ac9a241290c254a5071a9aa35d3ad63c71bbe09583980523f24ed8d78988fb37656b098d6896eab267585f16
6
+ metadata.gz: fe348f3964752cdc520d2f571da843a26073795de1033a823757e388f506e800fd310ffe6063d3cb415d55502c5c9576162cb1404a925088dced844b143aa129
7
+ data.tar.gz: d3347bb4ed8c6b2ad9945252947aa44c44eda188ec64cb5aa4ac371d7f3a426241f9c76c67eb12de42854ceebf4aa796a2762b43b7395a09a75e234e403b6619
data/API-Reference.ja.md CHANGED
@@ -2,7 +2,7 @@
2
2
  ruby-dnnのAPIリファレンスです。このリファレンスでは、APIを利用するうえで必要となるクラスとメソッドしか記載していません。
3
3
  そのため、プログラムの詳細が必要な場合は、ソースコードを参照してください。
4
4
 
5
- 最終更新バージョン:0.8.2
5
+ 最終更新バージョン:0.8.5
6
6
 
7
7
  # module DNN
8
8
  ruby-dnnの名前空間をなすモジュールです。
@@ -152,7 +152,7 @@ epoch_proc
152
152
  Integer
153
153
  損失関数の値を返します。
154
154
 
155
- ## def accurate(x, y, batch_size = 1, &batch_proc)
155
+ ## def accurate(x, y, batch_size = 100, &batch_proc)
156
156
  学習結果をもとに認識率を返します。
157
157
  ### arguments
158
158
  * Numo::SFloat x
@@ -216,6 +216,13 @@ layer_classで指定されたクラスのレイヤーをindexで取得します
216
216
  Layer
217
217
  対象のレイヤーのインスタンス。
218
218
 
219
+ ## def get_all_layers
220
+ モデルが持つ全てのレイヤー(モデルが持つ下位のモデルのレイヤーも含む)を取得します。
221
+ ### arguments
222
+ なし。
223
+ ### return
224
+ Array
225
+ モデルの持つすべてのレイヤーの配列
219
226
 
220
227
  # module Layers
221
228
  レイヤーの名前空間をなすモジュールです。
@@ -275,7 +275,7 @@ module DNN
275
275
  end
276
276
 
277
277
  def dloss
278
- @model.layers.select { |layer| layer.is_a?(Connection) }.each do |layer|
278
+ @model.get_all_layers.select { |layer| layer.is_a?(Connection) }.each do |layer|
279
279
  layer.dlasso
280
280
  layer.dridge
281
281
  end
@@ -284,13 +284,13 @@ module DNN
284
284
  private
285
285
 
286
286
  def lasso
287
- @model.layers.select { |layer| layer.is_a?(Connection) }
288
- .reduce(0) { |sum, layer| sum + layer.lasso }
287
+ @model.get_all_layers.select { |layer| layer.is_a?(Connection) }
288
+ .reduce(0) { |sum, layer| sum + layer.lasso }
289
289
  end
290
290
 
291
291
  def ridge
292
- @model.layers.select { |layer| layer.is_a?(Connection) }
293
- .reduce(0) { |sum, layer| sum + layer.ridge }
292
+ @model.get_all_layers.select { |layer| layer.is_a?(Connection) }
293
+ .reduce(0) { |sum, layer| sum + layer.ridge }
294
294
  end
295
295
  end
296
296
 
@@ -216,6 +216,12 @@ module DNN
216
216
  @layers.select { |layer| layer.is_a?(layer_class) }[index]
217
217
  end
218
218
  end
219
+
220
+ def get_all_layers
221
+ @layers.map { |layer|
222
+ layer.is_a?(Model) ? layer.get_all_layers : layer
223
+ }.flatten
224
+ end
219
225
 
220
226
  def forward(x, training)
221
227
  @training = training
@@ -291,7 +297,7 @@ module DNN
291
297
 
292
298
  def layers_shape_check
293
299
  @layers.each.with_index do |layer, i|
294
- prev_shape = layer.prev_layer.shape
300
+ prev_shape = layer.is_a?(Layers::Layer) ? layer.prev_layer.shape : layer.layers[-1]
295
301
  if layer.is_a?(Layers::Dense)
296
302
  if prev_shape.length != 1
297
303
  raise DNN_ShapeError.new("layer index(#{i}) Dense: The shape of the previous layer is #{prev_shape}. The shape of the previous layer must be 1 dimensional.")
@@ -94,16 +94,20 @@ module DNN
94
94
  end
95
95
  end
96
96
 
97
- def dlasso2
97
+ def dlasso
98
98
  if @l1_lambda > 0
99
- dlasso = Xumo::SFloat.ones(*@weight2.data.shape)
100
- dlasso[@weight2.data < 0] = -1
101
- @weight2.grad += @l1_lambda * dlasso
99
+ dlasso = Xumo::SFloat.ones(*@weight.data.shape)
100
+ dlasso[@weight.data < 0] = -1
101
+ @weight.grad += @l1_lambda * dlasso
102
+ dlasso2 = Xumo::SFloat.ones(*@weight2.data.shape)
103
+ dlasso2[@weight2.data < 0] = -1
104
+ @weight2.grad += @l1_lambda * dlasso2
102
105
  end
103
106
  end
104
107
 
105
- def dridge2
108
+ def dridge
106
109
  if @l2_lambda > 0
110
+ @weight.grad += l2_lambda * @weight.data
107
111
  @weight2.grad += l2_lambda * @weight2.data
108
112
  end
109
113
  end
data/lib/dnn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DNN
2
- VERSION = "0.8.4"
2
+ VERSION = "0.8.5"
3
3
  end
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.8.4
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - unagiootoro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-21 00:00:00.000000000 Z
11
+ date: 2019-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray