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(weight, weight2, bias, activation) ⇒ SimpleRNN_Dense
constructor
A new instance of SimpleRNN_Dense.
Constructor Details
#initialize(weight, weight2, bias, activation) ⇒ SimpleRNN_Dense
Returns a new instance of SimpleRNN_Dense.
128 129 130 131 132 133 |
# File 'lib/dnn/core/rnn_layers.rb', line 128 def initialize(weight, weight2, bias, activation) @weight = weight @weight2 = weight2 @bias = bias @activation = activation.clone end |
Instance Method Details
#backward(dh2) ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'lib/dnn/core/rnn_layers.rb', line 142 def backward(dh2) dh2 = @activation.backward(dh2) @weight.grad += @x.transpose.dot(dh2) @weight2.grad += @h.transpose.dot(dh2) @bias.grad += dh2.sum(0) dx = dh2.dot(@weight.data.transpose) dh = dh2.dot(@weight2.data.transpose) [dx, dh] end |
#forward(x, h) ⇒ Object
135 136 137 138 139 140 |
# File 'lib/dnn/core/rnn_layers.rb', line 135 def forward(x, h) @x = x @h = h h2 = x.dot(@weight.data) + h.dot(@weight2.data) + @bias.data @activation.forward(h2) end |