Class: DNN::Layers::HasParamLayer
Overview
This class is a superclass of all classes with learning parameters.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#params ⇒ Array
readonly
The parameters of the layer.
-
#trainable ⇒ Bool
Trainable Setting false prevents learning of parameters.
Attributes inherited from Layer
Instance Method Summary collapse
- #build(input_shape) ⇒ Object
-
#initialize ⇒ HasParamLayer
constructor
A new instance of HasParamLayer.
-
#update(optimizer) ⇒ Object
Update the parameters.
Methods inherited from Layer
#backward, #built?, #forward, #output_shape, #to_hash
Constructor Details
#initialize ⇒ HasParamLayer
Returns a new instance of HasParamLayer.
53 54 55 56 57 |
# File 'lib/dnn/core/layers.rb', line 53 def initialize super() @params = {} @trainable = true end |
Instance Attribute Details
#params ⇒ Array (readonly)
Returns The parameters of the layer.
51 52 53 |
# File 'lib/dnn/core/layers.rb', line 51 def params @params end |
#trainable ⇒ Bool
Returns trainable Setting false prevents learning of parameters.
49 50 51 |
# File 'lib/dnn/core/layers.rb', line 49 def trainable @trainable end |
Instance Method Details
#build(input_shape) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/dnn/core/layers.rb', line 59 def build(input_shape) @input_shape = input_shape unless @built @built = true init_params end end |
#update(optimizer) ⇒ Object
Update the parameters.
68 69 70 |
# File 'lib/dnn/core/layers.rb', line 68 def update(optimizer) optimizer.update(@params) if @trainable end |