Class: DNN::Losses::SoftmaxCrossEntropy
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#backward, #forward
Methods inherited from Loss
call, #call, #clean, #forward, from_hash, #loss, #regularizers_backward, #regularizers_forward
Constructor Details
Returns a new instance of SoftmaxCrossEntropy.
160
161
162
|
# File 'lib/dnn/core/losses.rb', line 160
def initialize(eps: 1e-7)
@eps = eps
end
|
Instance Attribute Details
#eps ⇒ Object
Returns the value of attribute eps.
149
150
151
|
# File 'lib/dnn/core/losses.rb', line 149
def eps
@eps
end
|
Class Method Details
.softmax(y) ⇒ Object
Also known as:
activation
152
153
154
|
# File 'lib/dnn/core/losses.rb', line 152
def softmax(y)
Xumo::NMath.exp(y) / Xumo::NMath.exp(y).sum(1, keepdims: true)
end
|
Instance Method Details
#backward_node(d) ⇒ Object
170
171
172
|
# File 'lib/dnn/core/losses.rb', line 170
def backward_node(d)
@x - @t
end
|
#forward_node(y, t) ⇒ Object
164
165
166
167
168
|
# File 'lib/dnn/core/losses.rb', line 164
def forward_node(y, t)
@t = t
@x = SoftmaxCrossEntropy.softmax(y)
-(t * Xumo::NMath.log(@x + @eps)).mean(0).sum
end
|
#load_hash(hash) ⇒ Object
178
179
180
|
# File 'lib/dnn/core/losses.rb', line 178
def load_hash(hash)
initialize(eps: hash[:eps])
end
|
#to_hash ⇒ Object
174
175
176
|
# File 'lib/dnn/core/losses.rb', line 174
def to_hash
super(eps: @eps)
end
|