Class: DNN::Layers::Mean
Instance Attribute Summary collapse
Attributes inherited from Layer
#input_shape, #output_shape
Instance Method Summary
collapse
Methods included from LayerNode
#forward
Methods inherited from Layer
#<<, #build, #built?, #call, call, #clean, #compute_output_shape, #forward, from_hash
Constructor Details
#initialize(axis: 0, keepdims: true) ⇒ Mean
234
235
236
237
238
|
# File 'lib/dnn/core/layers/math_layers.rb', line 234
def initialize(axis: 0, keepdims: true)
super()
@axis = axis
@keepdims = keepdims
end
|
Instance Attribute Details
#axis ⇒ Object
Returns the value of attribute axis.
231
232
233
|
# File 'lib/dnn/core/layers/math_layers.rb', line 231
def axis
@axis
end
|
#keepdims ⇒ Object
Returns the value of attribute keepdims.
232
233
234
|
# File 'lib/dnn/core/layers/math_layers.rb', line 232
def keepdims
@keepdims
end
|
Instance Method Details
#backward_node(dy) ⇒ Object
251
252
253
|
# File 'lib/dnn/core/layers/math_layers.rb', line 251
def backward_node(dy)
MathUtils.broadcast_to(dy, @x_shape) / @dim
end
|
#forward_node(x) ⇒ Object
240
241
242
243
244
245
246
247
248
249
|
# File 'lib/dnn/core/layers/math_layers.rb', line 240
def forward_node(x)
@x_shape = x.shape
if @axis
@dim = x.shape[@axis]
x.mean(axis: @axis, keepdims: true)
else
@dim = x.size
x.mean
end
end
|
#load_hash(hash) ⇒ Object
259
260
261
|
# File 'lib/dnn/core/layers/math_layers.rb', line 259
def load_hash(hash)
initialize(axis: hash[:axis], keepdims: hash[:keepdims])
end
|
#to_hash ⇒ Object
255
256
257
|
# File 'lib/dnn/core/layers/math_layers.rb', line 255
def to_hash
super(axis: @axis, keepdims: @keepdims)
end
|