Class: DNN::Layers::SimpleRNN_Dense
- Inherits:
-
Object
- Object
- DNN::Layers::SimpleRNN_Dense
- Defined in:
- lib/dnn/core/rnn_layers.rb
Instance Method Summary collapse
- #backward(dh2) ⇒ Object
- #forward(x, h) ⇒ Object
-
#initialize(params, grads, activation) ⇒ SimpleRNN_Dense
constructor
A new instance of SimpleRNN_Dense.
Constructor Details
#initialize(params, grads, activation) ⇒ SimpleRNN_Dense
Returns a new instance of SimpleRNN_Dense.
64 65 66 67 68 |
# File 'lib/dnn/core/rnn_layers.rb', line 64 def initialize(params, grads, activation) @params = params @grads = grads @activation = activation end |
Instance Method Details
#backward(dh2) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/dnn/core/rnn_layers.rb', line 77 def backward(dh2) dh2 = @activation.backward(dh2) @grads[:weight] += @x.transpose.dot(dh2) @grads[:weight2] += @h.transpose.dot(dh2) @grads[:bias] += dh2.sum(0) dx = dh2.dot(@params[:weight].transpose) dh = dh2.dot(@params[:weight2].transpose) [dx, dh] end |
#forward(x, h) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/dnn/core/rnn_layers.rb', line 70 def forward(x, h) @x = x @h = h h2 = x.dot(@params[:weight]) + h.dot(@params[:weight2]) + @params[:bias] @activation.forward(h2) end |