Class: DNN::Layers::Layer

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

Overview

Super class of all optimizer classes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Layer

Returns a new instance of Layer.



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

def initialize
  @built = false
end

Instance Attribute Details

#input_shape ⇒ Array (readonly)

Return the shape of the input data.

Returns:

  • (Array) —

    Return the shape of the input data.



9
10
11
# File 'lib/dnn/core/layers.rb', line 9

def input_shape
  @input_shape
end

#learning_phase ⇒ Bool

Returns learning_phase Return the true if learning.

Returns:

  • (Bool) —

    learning_phase Return the true if learning.



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

def learning_phase
  @learning_phase
end

Instance Method Details

#backward(dy) ⇒ Object

Backward propagation.

Raises:

  • (NotImplementedError)


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

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

#build(input_shape) ⇒ Object

Build the layer.

Parameters:

  • input_shape (Array) —

    Setting the shape of the input data.



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

def build(input_shape)
  @input_shape = input_shape
  @learning_phase = true
  @built = true
end

#built? ⇒ Bool

Does the layer have already been built?

Returns:

  • (Bool) —

    If layer have already been built then return true.



25
26
27
# File 'lib/dnn/core/layers.rb', line 25

def built?
  @built
end

#forward(x) ⇒ Object

Forward propagation.

Raises:

  • (NotImplementedError)


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

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

#output_shape ⇒ Array

Please reimplement this method as needed. The default implementation return input_shape.

Returns:

  • (Array) —

    Return the shape of the output data.



42
43
44
# File 'lib/dnn/core/layers.rb', line 42

def output_shape
  @input_shape
end

#to_hash(merge_hash = nil) ⇒ Object

Layer to a hash.



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

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