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.
96 97 98 99 100 |
# File 'lib/dnn/core/rnn_layers.rb', line 96 def initialize(params, grads, activation) @params = params @grads = grads @activation = activation end |
Instance Method Details
#backward(dh2) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/dnn/core/rnn_layers.rb', line 109 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
102 103 104 105 106 107 |
# File 'lib/dnn/core/rnn_layers.rb', line 102 def forward(x, h) @x = x @h = h h2 = x.dot(@params[:weight]) + h.dot(@params[:weight2]) + @params[:bias] @activation.forward(h2) end |