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

Attributes inherited from Layer

#input_shape

Instance Method Summary collapse

Methods inherited from Layer

#backward, #built?, #forward, #output_shape, #to_hash

Constructor Details

#initializeHasParamLayer

Returns a new instance of HasParamLayer.



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

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

Instance Attribute Details

#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(input_shape) ⇒ Object



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

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

#update(optimizer) ⇒ Object

Update the parameters.



66
67
68
# File 'lib/dnn/core/layers.rb', line 66

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