Class: DNN::Link

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prev = nil, layer_node = nil) ⇒ Link

Returns a new instance of Link.



7
8
9
10
11
# File 'lib/dnn/core/link.rb', line 7

def initialize(prev = nil, layer_node = nil)
  @prev = prev
  @layer_node = layer_node
  @next = nil
end

Instance Attribute Details

#layer_nodeObject

Returns the value of attribute layer_node.



5
6
7
# File 'lib/dnn/core/link.rb', line 5

def layer_node
  @layer_node
end

#nextObject

Returns the value of attribute next.



4
5
6
# File 'lib/dnn/core/link.rb', line 4

def next
  @next
end

#prevObject

Returns the value of attribute prev.



3
4
5
# File 'lib/dnn/core/link.rb', line 3

def prev
  @prev
end

Instance Method Details

#backward(dy = Xumo::SFloat[1]) ⇒ Object



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

def backward(dy = Xumo::SFloat[1])
  dy = @layer_node.backward_node(dy)
  @prev&.backward(dy)
end

#forward(x) ⇒ Object



13
14
15
16
# File 'lib/dnn/core/link.rb', line 13

def forward(x)
  x = @layer_node.(x)
  @next ? @next.forward(x) : x
end