Class: RANN::LSTM
- Inherits:
-
Object
- Object
- RANN::LSTM
- Defined in:
- lib/rann/lstm.rb
Instance Attribute Summary collapse
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#network ⇒ Object
readonly
Returns the value of attribute network.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
Instance Method Summary collapse
- #add_input(neuron) ⇒ Object
- #init ⇒ Object
-
#initialize(name, size) ⇒ LSTM
constructor
A new instance of LSTM.
Constructor Details
Instance Attribute Details
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
9 10 11 |
# File 'lib/rann/lstm.rb', line 9 def inputs @inputs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/rann/lstm.rb', line 9 def name @name end |
#network ⇒ Object (readonly)
Returns the value of attribute network.
9 10 11 |
# File 'lib/rann/lstm.rb', line 9 def network @network end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
9 10 11 |
# File 'lib/rann/lstm.rb', line 9 def outputs @outputs end |
Instance Method Details
#add_input(neuron) ⇒ Object
73 74 75 76 77 |
# File 'lib/rann/lstm.rb', line 73 def add_input neuron @inputs.each do |input| @network.add RANN::Connection.new neuron, input end end |
#init ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rann/lstm.rb', line 20 def init @size.times do |j| input = RANN::Neuron.new("LSTM #{name} Input #{j}", 0, :standard, :linear).tap{ |n| @network.add n } @inputs << input f = RANN::Neuron.new("LSTM #{name} F #{j}", 3, :standard, :sig).tap{ |n| @network.add n } i = RANN::Neuron.new("LSTM #{name} I #{j}", 4, :standard, :sig).tap{ |n| @network.add n } g = RANN::Neuron.new("LSTM #{name} G #{j}", 3, :standard, :tanh).tap{ |n| @network.add n } o = RANN::Neuron.new("LSTM #{name} O #{j}", 3, :standard, :sig).tap{ |n| @network.add n } bias_f = RANN::Neuron.new("LSTM #{name} Bias F #{j}", 0, :bias).tap{ |n| @network.add n } bias_i = RANN::Neuron.new("LSTM #{name} Bias I #{j}", 0, :bias).tap{ |n| @network.add n } bias_g = RANN::Neuron.new("LSTM #{name} Bias G #{j}", 0, :bias).tap{ |n| @network.add n } bias_o = RANN::Neuron.new("LSTM #{name} Bias O #{j}", 0, :bias).tap{ |n| @network.add n } memory_product = RANN::ProductNeuron.new("LSTM #{name} Mem Product #{j}", 2, :standard, :linear).tap{ |n| @network.add n } i_g_product = RANN::ProductNeuron.new("LSTM #{name} Hidden 2/3 Product #{j}", 2, :standard, :linear).tap{ |n| @network.add n } memory_standard = RANN::Neuron.new("LSTM #{name} Mem Standard #{j}", 2, :standard, :linear).tap{ |n| @network.add n } memory_tanh = RANN::Neuron.new("LSTM #{name} Mem Tanh #{j}", 1, :standard, :tanh).tap{ |n| @network.add n } memory_o_product = RANN::ProductNeuron.new("LSTM #{name} Mem/Hidden 4 Product #{j}", 2, :standard, :linear).tap{ |n| @network.add n } @outputs << memory_o_product memory_context = RANN::Neuron.new("LSTM #{name} Mem Context #{j}", 1, :context).tap do |n| @network.add n n.value = 1.to_d # connecting to a product neuron end output_context = RANN::Neuron.new("LSTM #{name} Output Context #{j}", 1, :context).tap{ |n| @network.add n } @network.add RANN::Connection.new input, f @network.add RANN::Connection.new input, i @network.add RANN::Connection.new input, g @network.add RANN::Connection.new input, o @network.add RANN::LockedConnection.new f, memory_product, 1.to_d @network.add RANN::LockedConnection.new i, i_g_product, 1.to_d @network.add RANN::LockedConnection.new g, i_g_product, 1.to_d @network.add RANN::LockedConnection.new i_g_product, memory_standard, 1.to_d @network.add RANN::LockedConnection.new memory_product, memory_standard, 1.to_d @network.add RANN::LockedConnection.new memory_standard, memory_tanh, 1.to_d @network.add RANN::LockedConnection.new o, memory_o_product, 1.to_d @network.add RANN::LockedConnection.new memory_tanh, memory_o_product, 1.to_d @network.add RANN::LockedConnection.new memory_standard, memory_context, 1.to_d @network.add RANN::LockedConnection.new memory_context, memory_product, 1.to_d @network.add RANN::LockedConnection.new memory_context, i, 1.to_d @network.add RANN::LockedConnection.new memory_o_product, output_context, 1.to_d @network.add RANN::Connection.new output_context, f @network.add RANN::Connection.new output_context, i @network.add RANN::Connection.new output_context, g @network.add RANN::Connection.new output_context, o @network.add RANN::Connection.new bias_f, f @network.add RANN::Connection.new bias_i, i @network.add RANN::Connection.new bias_g, g @network.add RANN::Connection.new bias_o, o end end |