Class: NN::Dropout
Instance Method Summary collapse
- #backward(dout) ⇒ Object
- #forward(x) ⇒ Object
-
#initialize(nn) ⇒ Dropout
constructor
A new instance of Dropout.
Constructor Details
#initialize(nn) ⇒ Dropout
Returns a new instance of Dropout.
384 385 386 387 |
# File 'lib/nn.rb', line 384 def initialize(nn) @nn = nn @mask = nil end |
Instance Method Details
#backward(dout) ⇒ Object
399 400 401 402 |
# File 'lib/nn.rb', line 399 def backward(dout) dout[@mask] = 0 if @nn.training dout end |
#forward(x) ⇒ Object
389 390 391 392 393 394 395 396 397 |
# File 'lib/nn.rb', line 389 def forward(x) if @nn.training @mask = SFloat.ones(*x.shape).rand < @nn.dropout_ratio x[@mask] = 0 else x *= (1 - @nn.dropout_ratio) end x end |