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, #forward, from_hash, #load_hash, #output_shape, #to_hash
Constructor Details
#initialize(axis: 0) ⇒ Mean
Returns a new instance of Mean.
147 148 149 150 |
# File 'lib/dnn/core/layers/math_layers.rb', line 147 def initialize(axis: 0) super() @axis = axis end |
Instance Method Details
#backward_node(dy) ⇒ Object
157 158 159 160 161 162 163 164 165 |
# File 'lib/dnn/core/layers/math_layers.rb', line 157 def backward_node(dy) dx = dy if @axis (@dim - 1).times do dx = dx.concatenate(dy, axis: @axis) end end dx / @dim end |
#forward_node(x) ⇒ Object
152 153 154 155 |
# File 'lib/dnn/core/layers/math_layers.rb', line 152 def forward_node(x) @dim = @axis ? x.shape[@axis] : x.size x.mean(axis: @axis, keepdims: true) end |