Class: DNN::Losses::Loss

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

Instance Method Summary collapse

Instance Method Details

#backward(y, layers) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/dnn/core/losses.rb', line 16

def backward(y, layers)
  layers.select { |layer| layer.is_a?(Connection) }.each do |layer|
    layer.regularizers.each do |regularizer|
      regularizer.backward
    end
  end
  backward_loss(y)
end

#forward(x, y, layers) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/dnn/core/losses.rb', line 5

def forward(x, y, layers)
  loss_value = forward_loss(x, y)
  regularizers = layers.select { |layer| layer.is_a?(Connection) }
                       .map { |layer| layer.regularizers }.flatten
  
  regularizers.each do |regularizer|
    loss_value = regularizer.forward(loss_value)
  end
  loss_value
end

#to_hash(merge_hash = nil) ⇒ Object



25
26
27
28
29
# File 'lib/dnn/core/losses.rb', line 25

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