Class: DNN::Layers::SimpleRNNDense
- Includes:
- LayerNode
- Defined in:
- lib/dnn/core/layers/rnn_layers.rb
Instance Attribute Summary collapse
-
#trainable ⇒ Object
Returns the value of attribute trainable.
Attributes inherited from Layer
Instance Method Summary collapse
- #backward_node(dh2) ⇒ Object
- #forward_node(x, h) ⇒ Object
-
#initialize(weight, recurrent_weight, bias, activation) ⇒ SimpleRNNDense
constructor
A new instance of SimpleRNNDense.
Methods included from LayerNode
Methods inherited from Layer
#build, #built?, #call, call, #clean, #forward, from_hash, #load_hash, #output_shape, #to_hash
Constructor Details
#initialize(weight, recurrent_weight, bias, activation) ⇒ SimpleRNNDense
Returns a new instance of SimpleRNNDense.
144 145 146 147 148 149 150 |
# File 'lib/dnn/core/layers/rnn_layers.rb', line 144 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.
142 143 144 |
# File 'lib/dnn/core/layers/rnn_layers.rb', line 142 def trainable @trainable end |
Instance Method Details
#backward_node(dh2) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/dnn/core/layers/rnn_layers.rb', line 160 def backward_node(dh2) dh2 = @activation.backward_node(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_node(x, h) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/dnn/core/layers/rnn_layers.rb', line 152 def forward_node(x, h) @x = x @h = h h2 = x.dot(@weight.data) + h.dot(@recurrent_weight.data) h2 += @bias.data if @bias @activation.forward_node(h2) end |