Class: DNN::Layers::SimpleRNNDense
- Inherits:
-
Object
- Object
- DNN::Layers::SimpleRNNDense
- Defined in:
- lib/dnn/core/rnn_layers.rb
Instance Attribute Summary collapse
-
#trainable ⇒ Object
Returns the value of attribute trainable.
Instance Method Summary collapse
- #backward(dh2) ⇒ Object
- #forward(x, h) ⇒ Object
-
#initialize(weight, recurrent_weight, bias, activation) ⇒ SimpleRNNDense
constructor
A new instance of SimpleRNNDense.
Constructor Details
#initialize(weight, recurrent_weight, bias, activation) ⇒ SimpleRNNDense
135 136 137 138 139 140 141 |
# File 'lib/dnn/core/rnn_layers.rb', line 135 def initialize(weight, recurrent_weight, bias, activation) @weight = weight @recurrent_weight = recurrent_weight @bias = bias @activation = activation.clone @trainable = true end |
Instance Attribute Details
#trainable ⇒ Object
Returns the value of attribute trainable.
133 134 135 |
# File 'lib/dnn/core/rnn_layers.rb', line 133 def trainable @trainable end |
Instance Method Details
#backward(dh2) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/dnn/core/rnn_layers.rb', line 151 def backward(dh2) dh2 = @activation.backward(dh2) if @trainable @weight.grad += @x.transpose.dot(dh2) @recurrent_weight.grad += @h.transpose.dot(dh2) @bias.grad += dh2.sum(0) if @bias end dx = dh2.dot(@weight.data.transpose) dh = dh2.dot(@recurrent_weight.data.transpose) [dx, dh] end |
#forward(x, h) ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/dnn/core/rnn_layers.rb', line 143 def forward(x, h) @x = x @h = h h2 = x.dot(@weight.data) + h.dot(@recurrent_weight.data) h2 += @bias.data if @bias @activation.forward(h2) end |