Class: DNN::Layers::RNN
- Inherits:
-
HasParamLayer
- Object
- Layer
- HasParamLayer
- DNN::Layers::RNN
- Includes:
- Activations, Initializers
- Defined in:
- lib/dnn/core/rnn_layers.rb
Overview
Super class of all RNN classes.
Constant Summary
Constants included from Activations
Instance Attribute Summary collapse
-
#num_nodes ⇒ Object
readonly
Returns the value of attribute num_nodes.
-
#stateful ⇒ Object
readonly
Returns the value of attribute stateful.
-
#weight_decay ⇒ Object
readonly
Returns the value of attribute weight_decay.
Attributes inherited from HasParamLayer
Instance Method Summary collapse
- #init_params ⇒ Object
-
#initialize(num_nodes, stateful: false, return_sequences: true, weight_initializer: nil, bias_initializer: nil, weight_decay: 0) ⇒ RNN
constructor
A new instance of RNN.
- #ridge ⇒ Object
- #shape ⇒ Object
- #to_hash(merge_hash = nil) ⇒ Object
Methods inherited from HasParamLayer
Methods inherited from Layer
#backward, #build, #built?, #forward, #prev_layer
Constructor Details
#initialize(num_nodes, stateful: false, return_sequences: true, weight_initializer: nil, bias_initializer: nil, weight_decay: 0) ⇒ RNN
Returns a new instance of RNN.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dnn/core/rnn_layers.rb', line 13 def initialize(num_nodes, stateful: false, return_sequences: true, weight_initializer: nil, bias_initializer: nil, weight_decay: 0) super() @num_nodes = num_nodes @stateful = stateful @return_sequences = return_sequences @weight_initializer = (weight_initializer || RandomNormal.new) @bias_initializer = (bias_initializer || Zeros.new) @weight_decay = weight_decay @layers = [] @h = nil end |
Instance Attribute Details
#num_nodes ⇒ Object (readonly)
Returns the value of attribute num_nodes.
9 10 11 |
# File 'lib/dnn/core/rnn_layers.rb', line 9 def num_nodes @num_nodes end |
#stateful ⇒ Object (readonly)
Returns the value of attribute stateful.
10 11 12 |
# File 'lib/dnn/core/rnn_layers.rb', line 10 def stateful @stateful end |
#weight_decay ⇒ Object (readonly)
Returns the value of attribute weight_decay.
11 12 13 |
# File 'lib/dnn/core/rnn_layers.rb', line 11 def weight_decay @weight_decay end |
Instance Method Details
#init_params ⇒ Object
57 58 59 |
# File 'lib/dnn/core/rnn_layers.rb', line 57 def init_params @time_length = prev_layer.shape[0] end |
#ridge ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/dnn/core/rnn_layers.rb', line 49 def ridge if @weight_decay > 0 0.5 * (@weight_decay * (@params[:weight]**2).sum + @weight_decay * (@params[:weight]**2).sum) else 0 end end |
#shape ⇒ Object
45 46 47 |
# File 'lib/dnn/core/rnn_layers.rb', line 45 def shape @return_sequences ? [@time_length, @num_nodes] : [@num_nodes] end |
#to_hash(merge_hash = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dnn/core/rnn_layers.rb', line 30 def to_hash(merge_hash = nil) hash = { name: self.class.name, num_nodes: @num_nodes, stateful: @stateful, return_sequences: @return_sequences, activation: @activation.to_hash, weight_initializer: @weight_initializer.to_hash, bias_initializer: @bias_initializer.to_hash, weight_decay: @weight_decay, } hash.merge!(merge_hash) if merge_hash hash end |