Class: NN::Identity
Instance Method Summary collapse
- #backward(y) ⇒ Object
- #forward(x) ⇒ Object
-
#initialize(nn) ⇒ Identity
constructor
A new instance of Identity.
- #loss(y) ⇒ Object
Constructor Details
#initialize(nn) ⇒ Identity
333 334 335 |
# File 'lib/nn.rb', line 333 def initialize(nn) @nn = nn end |
Instance Method Details
#backward(y) ⇒ Object
341 342 343 |
# File 'lib/nn.rb', line 341 def backward(y) @out - y end |
#forward(x) ⇒ Object
337 338 339 |
# File 'lib/nn.rb', line 337 def forward(x) @out = x end |
#loss(y) ⇒ Object
345 346 347 348 |
# File 'lib/nn.rb', line 345 def loss(y) ridge = 0.5 * @nn.weight_decay * @nn.weights.reduce(0){|sum, weight| sum + (weight ** 2).sum} 0.5 * ((@out - y) ** 2).sum / @nn.batch_size + ridge end |