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, Connection

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.



57
58
59
60
61
# File 'lib/dnn/core/layers.rb', line 57

def initialize
  super()
  @params = {}
  @trainable = true
end

Instance Attribute Details

#paramsObject (readonly)

The parameters of the layer.



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

def params
  @params
end

#trainableObject

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

#updateObject

Update the parameters.



72
73
74
# File 'lib/dnn/core/layers.rb', line 72

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