rann 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80b0dff761e66e192ee76aefe2cd6f91354dc061
4
- data.tar.gz: a4957efc538906c8f5b4e265d9bd5bb5ae0308fc
3
+ metadata.gz: b604698cf3630cf7056f4b10d5b1b301292074b4
4
+ data.tar.gz: a341f41f53c78db0f026948b7bad72ff04574e54
5
5
  SHA512:
6
- metadata.gz: 4e212b698e71a4e9804f6a3ac2b5169861cb2f35baa782cacaac798657cf741266c1b085f876f6355d0fd6bfbe3993fd8fe30d360fd6e23c156eb034e32cfa85
7
- data.tar.gz: fe707c128b2d21651278fff44a63c6272f16e16262d54b17610bf8d27c020983e5a894e0a4a7ac7197956768f06712eb3bae861a1be7c36cea12ad56d8c16e50
6
+ metadata.gz: 3e7167b3fb0fb79d0fcd3fc7a72b59d0ab4c9d29b69e6fbc230599b11752b3b9e001c06e9bef284325974649e7f64d4f34dd05864fe1fedb9fa7786ef9d40586
7
+ data.tar.gz: 6816e982c0536c21a474e377c87ca6de213b62268dfda48317d2c360972e2fa2d0f32eb491c8a088cccae8ca3bb5ef367587d601db2a7eda3d45d695a6c5ea8a
data/CHANGES.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.2.7 (December 2, 2017)
2
+
3
+ - Allow different weights to the different gates in the LSTM. Previously it was
4
+ using one weighted connection into the LSTM and unweighted connections to the
5
+ gates, this has been reversed.
6
+
7
+ *Michael Campbell*
8
+
1
9
  - Add save and restore methods to backprop.
2
10
 
3
11
  *Michael Campbell*
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rann (0.2.6)
4
+ rann (0.2.7)
5
5
  parallel (~> 1.12, >= 1.12.0)
6
6
  ruby-graphviz (~> 1.2, >= 1.2.3)
7
7
 
data/lib/rann/backprop.rb CHANGED
@@ -128,35 +128,34 @@ module RANN
128
128
 
129
129
  # neuron delta is summation of neuron deltas deltas for the connections
130
130
  # from this neuron
131
- node_delta =
131
+ step_one =
132
132
  if neuron.output?
133
133
  output_index = network.output_neurons.index neuron
134
- activation_derivative = ACTIVATION_DERIVATIVES[neuron.activation_function]
135
- mse_delta targets[output_index], outputs[output_index], activation_derivative
134
+ mse_delta targets[output_index], outputs[output_index]
136
135
  else
137
- sum_of_deltas =
138
- network.connections_from(neuron).reduce 0.to_d do |m, c|
139
- out_timestep = c.output_neuron.context? ? timestep + 1 : timestep
140
- output_node_delta = node_deltas[out_timestep][c.output_neuron.id]
141
-
142
- # connection delta is the output neuron delta multiplied by the
143
- # connection's weight
144
- connection_delta =
145
- if c.output_neuron.is_a? ProductNeuron
146
- intermediate = states[out_timestep][:intermediates][c.output_neuron.id]
147
- output_node_delta.mult intermediate.div(states[timestep][:values][c.input_neuron.id], 10), 10
148
- else
149
- output_node_delta.mult c.weight, 10
150
- end
151
-
152
- m + connection_delta
153
- end
154
-
155
- ACTIVATION_DERIVATIVES[neuron.activation_function]
156
- .call(states[timestep][:values][neuron.id])
157
- .mult(sum_of_deltas, 10)
136
+ network.connections_from(neuron).reduce 0.to_d do |m, c|
137
+ out_timestep = c.output_neuron.context? ? timestep + 1 : timestep
138
+ output_node_delta = node_deltas[out_timestep][c.output_neuron.id]
139
+
140
+ # connection delta is the output neuron delta multiplied by the
141
+ # connection's weight
142
+ connection_delta =
143
+ if c.output_neuron.is_a? ProductNeuron
144
+ intermediate = states[out_timestep][:intermediates][c.output_neuron.id]
145
+ output_node_delta.mult intermediate.div(states[timestep][:values][c.input_neuron.id], 10), 10
146
+ else
147
+ output_node_delta.mult c.weight, 10
148
+ end
149
+
150
+ m + connection_delta
151
+ end
158
152
  end
159
153
 
154
+ node_delta =
155
+ ACTIVATION_DERIVATIVES[neuron.activation_function]
156
+ .call(states[timestep][:values][neuron.id])
157
+ .mult(step_one, 10)
158
+
160
159
  node_deltas[timestep][neuron.id] = node_delta
161
160
 
162
161
  network.connections_to(neuron).each do |c|
@@ -224,11 +223,8 @@ module RANN
224
223
  total_squared_error
225
224
  end
226
225
 
227
- def self.mse_delta target, actual, activation_derivative
228
- step_one = actual - target
229
- step_two = activation_derivative.call actual
230
-
231
- step_one.mult step_two, 10
226
+ def self.mse_delta target, actual
227
+ actual - target
232
228
  end
233
229
 
234
230
  def self.bptt_connecting_to neuron, network, timestep
data/lib/rann/lstm.rb CHANGED
@@ -18,7 +18,6 @@ module RANN
18
18
  end
19
19
 
20
20
  def init
21
- input_bias = RANN::Neuron.new("LSTM #{name} Input Bias", 0, :bias).tap{ |n| @network.add n }
22
21
  @size.times do |j|
23
22
  input = RANN::Neuron.new("LSTM #{name} Input #{j}", 0, :standard).tap{ |n| @network.add n }
24
23
  @inputs << input
@@ -49,10 +48,10 @@ module RANN
49
48
  memory_context = RANN::Neuron.new("LSTM #{name} Mem Context #{j}", 1, :context).tap{ |n| @network.add n }
50
49
  output_context = RANN::Neuron.new("LSTM #{name} Output Context #{j}", 1, :context).tap{ |n| @network.add n }
51
50
 
52
- @network.add RANN::LockedConnection.new input, f, 1
53
- @network.add RANN::LockedConnection.new input, i, 1
54
- @network.add RANN::LockedConnection.new input, g, 1
55
- @network.add RANN::LockedConnection.new input, o, 1
51
+ @network.add RANN::Connection.new input, f
52
+ @network.add RANN::Connection.new input, i
53
+ @network.add RANN::Connection.new input, g
54
+ @network.add RANN::Connection.new input, o
56
55
  @network.add RANN::LockedConnection.new f, memory_product, 1
57
56
  @network.add RANN::LockedConnection.new i, i_g_product, 1
58
57
  @network.add RANN::LockedConnection.new g, i_g_product, 1
@@ -63,8 +62,8 @@ module RANN
63
62
  @network.add RANN::LockedConnection.new memory_tanh, memory_o_product, 1
64
63
  @network.add RANN::LockedConnection.new memory_o_product, output, 1
65
64
  @network.add RANN::LockedConnection.new memory_standard, memory_context, 1
66
- @network.add RANN::Connection.new memory_context, memory_product
67
- @network.add RANN::Connection.new memory_context, i
65
+ @network.add RANN::LockedConnection.new memory_context, memory_product, 1
66
+ @network.add RANN::LockedConnection.new memory_context, i, 1
68
67
  @network.add RANN::LockedConnection.new memory_o_product, output_context, 1
69
68
  @network.add RANN::Connection.new output_context, f
70
69
  @network.add RANN::Connection.new output_context, i
@@ -74,13 +73,12 @@ module RANN
74
73
  @network.add RANN::Connection.new bias_i, i
75
74
  @network.add RANN::Connection.new bias_g, g
76
75
  @network.add RANN::Connection.new bias_o, o
77
- @network.add RANN::Connection.new input_bias, input
78
76
  end
79
77
  end
80
78
 
81
79
  def add_input neuron
82
80
  @inputs.each do |input|
83
- @network.add RANN::Connection.new neuron, input
81
+ @network.add RANN::LockedConnection.new neuron, input, 1
84
82
  end
85
83
  end
86
84
  end
data/lib/rann/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RANN
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rann
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Campbell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-30 00:00:00.000000000 Z
11
+ date: 2017-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel