Class: DNN::Layers::Layer

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

Overview

Super class of all optimizer classes.

Instance Method Summary collapse

Constructor Details

#initializeLayer

Returns a new instance of Layer.



6
7
8
# File 'lib/dnn/core/layers.rb', line 6

def initialize
  @built = false
end

Instance Method Details

#backward(dout) ⇒ Object

Backward propagation. Classes that inherit from this class must implement this method.

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/dnn/core/layers.rb', line 29

def backward(dout)
  raise NotImplementedError.new("Class '#{self.class.name}' has implement method 'update'")
end

#build(model) ⇒ Object

Build the layer.



11
12
13
14
# File 'lib/dnn/core/layers.rb', line 11

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

#built?Boolean

Does the layer have already been built?

Returns:

  • (Boolean)


17
18
19
# File 'lib/dnn/core/layers.rb', line 17

def built?
  @built
end

#forward(x) ⇒ Object

Forward propagation. Classes that inherit from this class must implement this method.

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/dnn/core/layers.rb', line 23

def forward(x)
  raise NotImplementedError.new("Class '#{self.class.name}' has implement method 'forward'")
end

#prev_layerObject

Get the previous layer.



46
47
48
# File 'lib/dnn/core/layers.rb', line 46

def prev_layer
  @model.get_prev_layer(self)
end

#shapeObject

Get the shape of the layer.



34
35
36
# File 'lib/dnn/core/layers.rb', line 34

def shape
  prev_layer.shape
end

#to_hash(merge_hash = nil) ⇒ Object

Layer to a hash.



39
40
41
42
43
# File 'lib/dnn/core/layers.rb', line 39

def to_hash(merge_hash = nil)
  hash = {class: self.class.name}
  hash.merge!(merge_hash) if merge_hash
  hash
end