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

#initialize ⇒ HasParamLayer

Returns a new instance of HasParamLayer.



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

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

Instance Attribute Details

#params ⇒ Array (readonly)

Returns The parameters of the layer.

Returns:

  • (Array) —

    The parameters of the layer.



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

def params
  @params
end

#trainable ⇒ Bool

Returns trainable Setting false prevents learning of parameters.

Returns:

  • (Bool) —

    trainable Setting false prevents learning of parameters.



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

def trainable
  @trainable
end

Instance Method Details

#build(input_shape) ⇒ Object



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

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

#update(optimizer) ⇒ Object

Update the parameters.



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

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