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