Class: DNN::Layers::Mean
- Includes:
- LayerNode
- Defined in:
- lib/dnn/core/layers/math_layers.rb
Instance Attribute Summary
Attributes inherited from Layer
Instance Method Summary collapse
- #backward_node(dy) ⇒ Object
- #forward_node(x) ⇒ Object
-
#initialize(axis: 0) ⇒ Mean
constructor
A new instance of Mean.
Methods included from LayerNode
Methods inherited from Layer
#build, #built?, #call, call, #clean, #compute_output_shape, #forward, from_hash, #load_hash, #to_hash
Constructor Details
#initialize(axis: 0) ⇒ Mean
Returns a new instance of Mean.
164 165 166 167 |
# File 'lib/dnn/core/layers/math_layers.rb', line 164 def initialize(axis: 0) super() @axis = axis end |
Instance Method Details
#backward_node(dy) ⇒ Object
175 176 177 178 179 180 181 182 |
# File 'lib/dnn/core/layers/math_layers.rb', line 175 def backward_node(dy) return dy / @dim if @x_shape == dy.shape dx = dy (@dim - 1).times do dx = dx.concatenate(dy, axis: @axis) end dx / @dim end |
#forward_node(x) ⇒ Object
169 170 171 172 173 |
# File 'lib/dnn/core/layers/math_layers.rb', line 169 def forward_node(x) @x_shape = x.shape @dim = x.shape[@axis] x.mean(axis: @axis, keepdims: true) end |