Class: DNN::Layers::Mean
- Includes:
- LayerNode
- Defined in:
- lib/dnn/core/layers/math_layers.rb
Instance Attribute Summary collapse
-
#axis ⇒ Object
readonly
Returns the value of attribute axis.
-
#keepdims ⇒ Object
readonly
Returns the value of attribute keepdims.
Attributes inherited from Layer
Instance Method Summary collapse
- #backward_node(dy) ⇒ Object
- #forward_node(x) ⇒ Object
-
#initialize(axis: 0, keepdims: true) ⇒ Mean
constructor
A new instance of Mean.
- #load_hash(hash) ⇒ Object
- #to_hash ⇒ Object
Methods included from LayerNode
Methods inherited from Layer
#<<, #build, #built?, #call, call, #clean, #compute_output_shape, #forward, from_hash
Constructor Details
#initialize(axis: 0, keepdims: true) ⇒ Mean
Returns a new instance of 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 (readonly)
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 (readonly)
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 |