Class: DNN::Layers::HasParamLayer
Overview
This class is a superclass of all classes with learning parameters.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#grads ⇒ Object
readonly
Differential value of parameter of layer.
-
#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
#built?, #prev_layer, #shape, #to_hash
Constructor Details
#initialize ⇒ HasParamLayer
Returns a new instance of HasParamLayer.
54 55 56 57 58 59 |
# File 'lib/dnn/core/layers.rb', line 54 def initialize super @params = {} @grads = {} @trainable = true end |
Instance Attribute Details
#grads ⇒ Object (readonly)
Differential value of parameter of layer.
52 53 54 |
# File 'lib/dnn/core/layers.rb', line 52 def grads @grads end |
#params ⇒ Object (readonly)
The parameters of the layer.
51 52 53 |
# File 'lib/dnn/core/layers.rb', line 51 def params @params end |
#trainable ⇒ Object
Setting false prevents learning of parameters.
50 51 52 |
# File 'lib/dnn/core/layers.rb', line 50 def trainable @trainable end |
Instance Method Details
#build(model) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/dnn/core/layers.rb', line 61 def build(model) @model = model unless @built @built = true init_params end end |
#update ⇒ Object
Update the parameters.
70 71 72 |
# File 'lib/dnn/core/layers.rb', line 70 def update @model.optimizer.update(self) if @trainable end |