Class: DNN::TwoInputLink

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prev1 = nil, prev2 = nil, layer_node = nil) ⇒ TwoInputLink

Returns a new instance of TwoInputLink.



22
23
24
25
26
# File 'lib/dnn/core/link.rb', line 22

def initialize(prev1 = nil, prev2 = nil, layer_node = nil)
  @prev1 = prev1
  @prev2 = prev2
  @layer_node = layer_node
end

Instance Attribute Details

#layer_nodeObject

Returns the value of attribute layer_node.



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

def layer_node
  @layer_node
end

#prev1Object

Returns the value of attribute prev1.



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

def prev1
  @prev1
end

#prev2Object

Returns the value of attribute prev2.



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

def prev2
  @prev2
end

Instance Method Details

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



28
29
30
31
32
33
34
35
36
37
# File 'lib/dnn/core/link.rb', line 28

def backward(dy = Numo::SFloat[1])
  dys = @layer_node.backward_node(dy)
  if dys.is_a?(Array)
    dy1, dy2 = *dys
  else
    dy1 = dys
  end
  @prev1&.backward(dy1)
  @prev2&.backward(dy2) if dy2
end