Class: NN::Affine
Instance Attribute Summary collapse
-
#d_bias ⇒ Object
readonly
Returns the value of attribute d_bias.
-
#d_weight ⇒ Object
readonly
Returns the value of attribute d_weight.
Instance Method Summary collapse
- #backward(dout) ⇒ Object
- #forward(x) ⇒ Object
-
#initialize(nn, index) ⇒ Affine
constructor
A new instance of Affine.
Constructor Details
#initialize(nn, index) ⇒ Affine
Returns a new instance of Affine.
287 288 289 290 291 292 |
# File 'lib/nn.rb', line 287 def initialize(nn, index) @nn = nn @index = index @d_weight = nil @d_bias = nil end |
Instance Attribute Details
#d_bias ⇒ Object (readonly)
Returns the value of attribute d_bias.
285 286 287 |
# File 'lib/nn.rb', line 285 def d_bias @d_bias end |
#d_weight ⇒ Object (readonly)
Returns the value of attribute d_weight.
284 285 286 |
# File 'lib/nn.rb', line 284 def d_weight @d_weight end |
Instance Method Details
#backward(dout) ⇒ Object
299 300 301 302 303 304 305 306 307 |
# File 'lib/nn.rb', line 299 def backward(dout) @d_weight = @x.transpose.dot(dout) if @nn.weight_decay > 0 dridge = @nn.weight_decay * @nn.weights[@index] @d_weight += dridge end @d_bias = dout.sum(0) dout.dot(@nn.weights[@index].transpose) end |
#forward(x) ⇒ Object
294 295 296 297 |
# File 'lib/nn.rb', line 294 def forward(x) @x = x @x.dot(@nn.weights[@index]) + @nn.biases[@index] end |