Class: DNN::Layers::Dense
Instance Attribute Summary collapse
Attributes inherited from Connection
#l1_lambda, #l2_lambda
#grads, #params, #trainable
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Connection
#dlasso, #dridge, #lasso, #ridge
#build, #update
Methods inherited from Layer
#build, #built?, #prev_layer
Constructor Details
#initialize(num_nodes, weight_initializer: nil, bias_initializer: nil, l1_lambda: 0, l2_lambda: 0) ⇒ Dense
Returns a new instance of Dense.
175
176
177
178
179
180
181
182
183
|
# File 'lib/dnn/core/layers.rb', line 175
def initialize(num_nodes,
weight_initializer: nil,
bias_initializer: nil,
l1_lambda: 0,
l2_lambda: 0)
super(weight_initializer: weight_initializer, bias_initializer: bias_initializer,
l1_lambda: l1_lambda, l2_lambda: l2_lambda)
@num_nodes = num_nodes
end
|
Instance Attribute Details
#num_nodes ⇒ Object
Returns the value of attribute num_nodes.
165
166
167
|
# File 'lib/dnn/core/layers.rb', line 165
def num_nodes
@num_nodes
end
|
Class Method Details
.load_hash(hash) ⇒ Object
167
168
169
170
171
172
173
|
# File 'lib/dnn/core/layers.rb', line 167
def self.load_hash(hash)
self.new(hash[:num_nodes],
weight_initializer: Util.load_hash(hash[:weight_initializer]),
bias_initializer: Util.load_hash(hash[:bias_initializer]),
l1_lambda: hash[:l1_lambda],
l2_lambda: hash[:l2_lambda])
end
|
Instance Method Details
#backward(dout) ⇒ Object
190
191
192
193
194
195
196
197
198
199
|
# File 'lib/dnn/core/layers.rb', line 190
def backward(dout)
@grads[:weight] = @x.transpose.dot(dout)
if @l1_lambda > 0
@grads[:weight] += dlasso
elsif @l2_lambda > 0
@grads[:weight] += dridge
end
@grads[:bias] = dout.sum(0)
dout.dot(@params[:weight].transpose)
end
|
#forward(x) ⇒ Object
185
186
187
188
|
# File 'lib/dnn/core/layers.rb', line 185
def forward(x)
@x = x
@x.dot(@params[:weight]) + @params[:bias]
end
|
#shape ⇒ Object
201
202
203
|
# File 'lib/dnn/core/layers.rb', line 201
def shape
[@num_nodes]
end
|
#to_hash ⇒ Object
205
206
207
|
# File 'lib/dnn/core/layers.rb', line 205
def to_hash
super({num_nodes: @num_nodes})
end
|