Class: DNN::Layers::HasParamLayer

Inherits:
Layer
  • Object
show all
Defined in:
lib/dnn/core/layers.rb

Overview

This class is a superclass of all classes with learning parameters.

Direct Known Subclasses

BatchNormalization, Conv2D, Dense, RNN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Layer

#backward, #built?, #forward, #prev_layer, #shape, #to_hash

Constructor Details

#initializeHasParamLayer

Returns a new instance of HasParamLayer.



52
53
54
55
56
57
# File 'lib/dnn/core/layers.rb', line 52

def initialize
  super
  @params = {}
  @grads = {}
  @trainable = true
end

Instance Attribute Details

#gradsObject (readonly)

Differential value of parameter of layer.



50
51
52
# File 'lib/dnn/core/layers.rb', line 50

def grads
  @grads
end

#paramsObject (readonly)

The parameters of the layer.



49
50
51
# File 'lib/dnn/core/layers.rb', line 49

def params
  @params
end

#trainableObject

Setting false prevents learning of parameters.



48
49
50
# File 'lib/dnn/core/layers.rb', line 48

def trainable
  @trainable
end

Instance Method Details

#build(model) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/dnn/core/layers.rb', line 59

def build(model)
  @model = model
  unless @built
    @built = true
    init_params
  end
end

#updateObject

Update the parameters.



68
69
70
# File 'lib/dnn/core/layers.rb', line 68

def update
  @model.optimizer.update(self) if @trainable
end