Class: DNN::Layers::GRU

Inherits:
RNN show all
Defined in:
lib/dnn/core/rnn_layers.rb

Instance Attribute Summary

Attributes inherited from RNN

#num_nodes, #recurrent_weight_initializer, #recurrent_weight_regularizer, #return_sequences, #stateful

Attributes inherited from Connection

#bias_initializer, #bias_regularizer, #weight_initializer, #weight_regularizer

Attributes inherited from HasParamLayer

#params, #trainable

Attributes inherited from Layer

#input_shape, #learning_phase

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RNN

#backward, #forward, #output_shape, #regularizers, #reset_state, #to_hash

Methods inherited from Connection

#regularizers, #to_hash, #use_bias

Methods inherited from Layer

#backward, #built?, #forward, #output_shape, #to_hash

Constructor Details

#initialize(num_nodes, stateful: false, return_sequences: true, weight_initializer: RandomNormal.new, recurrent_weight_initializer: RandomNormal.new, bias_initializer: Zeros.new, weight_regularizer: nil, recurrent_weight_regularizer: nil, bias_regularizer: nil, use_bias: true) ⇒ GRU

Returns a new instance of GRU.



437
438
439
440
441
442
443
444
445
446
447
448
# File 'lib/dnn/core/rnn_layers.rb', line 437

def initialize(num_nodes,
               stateful: false,
               return_sequences: true,
               weight_initializer: RandomNormal.new,
               recurrent_weight_initializer: RandomNormal.new,
               bias_initializer: Zeros.new,
               weight_regularizer: nil,
               recurrent_weight_regularizer: nil,
               bias_regularizer: nil,
               use_bias: true)
  super
end

Class Method Details

.from_hash(hash) ⇒ Object



423
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/dnn/core/rnn_layers.rb', line 423

def self.from_hash(hash)
  gru = self.new(hash[:num_nodes],
                 stateful: hash[:stateful],
                 return_sequences: hash[:return_sequences],
                 weight_initializer: Utils.from_hash(hash[:weight_initializer]),
                 recurrent_weight_initializer: Utils.from_hash(hash[:recurrent_weight_initializer]),
                 bias_initializer: Utils.from_hash(hash[:bias_initializer]),
                 weight_regularizer: Utils.from_hash(hash[:weight_regularizer]),
                 recurrent_weight_regularizer: Utils.from_hash(hash[:recurrent_weight_regularizer]),
                 bias_regularizer: Utils.from_hash(hash[:bias_regularizer]),
                 use_bias: hash[:use_bias])
  gru
end

Instance Method Details

#build(input_shape) ⇒ Object



450
451
452
453
454
455
456
457
458
459
460
# File 'lib/dnn/core/rnn_layers.rb', line 450

def build(input_shape)
  super
  num_prev_nodes = @input_shape[1]
  @weight.data = Xumo::SFloat.new(num_prev_nodes, @num_nodes * 3)
  @recurrent_weight.data = Xumo::SFloat.new(@num_nodes, @num_nodes * 3)
  @bias.data = Xumo::SFloat.new(@num_nodes * 3) if @bias
  init_weight_and_bias
  @time_length.times do |t|
    @layers << GRU_Dense.new(@weight, @recurrent_weight, @bias)
  end
end