db_mlp 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/db_mlp.gemspec +1 -1
- data/examples/data.rdb +0 -0
- data/examples/xor.rb +6 -3
- data/lib/db_mlp.rb +1 -1
- data/lib/modules/training.rb +3 -3
- data/test/test_db_mlp.rb +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/db_mlp.gemspec
CHANGED
data/examples/data.rdb
CHANGED
Binary file
|
data/examples/xor.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../lib/db_mlp'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/db_mlp')
|
2
2
|
require 'benchmark'
|
3
3
|
|
4
4
|
db = "sqlite3://#{File.dirname(File.expand_path(__FILE__))}/data.rdb"
|
5
|
-
a = DBMLP.new(db, :hidden_layers => [2
|
5
|
+
a = DBMLP.new(db, :hidden_layers => [2],
|
6
|
+
:output_nodes => 1,
|
7
|
+
:inputs => 2,
|
8
|
+
:verbose => true)
|
6
9
|
|
7
10
|
times = Benchmark.measure do
|
8
11
|
|
@@ -12,7 +15,7 @@ times = Benchmark.measure do
|
|
12
15
|
testing = [[[0,0], [0]], [[0,1], [1]], [[1,0], [1]], [[1,1], [0]]]
|
13
16
|
validation = [[[0,0], [0]], [[0,1], [1]], [[1,0], [1]], [[1,1], [0]]]
|
14
17
|
|
15
|
-
a.train(training, testing, validation,
|
18
|
+
a.train(training, testing, validation, 3000)
|
16
19
|
|
17
20
|
puts "Test data"
|
18
21
|
puts "[0,0] = > #{a.feed_forward([0,0]).inspect}"
|
data/lib/db_mlp.rb
CHANGED
data/lib/modules/training.rb
CHANGED
@@ -82,7 +82,7 @@ module Training
|
|
82
82
|
if layer_index == 0
|
83
83
|
compute_output_deltas(layer, targets)
|
84
84
|
else
|
85
|
-
compute_hidden_deltas(layer, targets)
|
85
|
+
compute_hidden_deltas(layer, targets, reversed_network[layer_index-1])
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
@@ -94,10 +94,10 @@ module Training
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
def compute_hidden_deltas(layer, targets)
|
97
|
+
def compute_hidden_deltas(layer, targets, previous_layer)
|
98
98
|
layer.each_with_index do |neuron, neuron_index|
|
99
99
|
error = 0
|
100
|
-
|
100
|
+
previous_layer.each do |output_neuron|
|
101
101
|
error += output_neuron.delta * output_neuron.weights[neuron_index]
|
102
102
|
end
|
103
103
|
output = neuron.last_output
|
data/test/test_db_mlp.rb
CHANGED
@@ -26,7 +26,7 @@ class TestDBMLP < Test::Unit::TestCase
|
|
26
26
|
set_data_variables
|
27
27
|
@db_path = "sqlite3://#{File.dirname(File.expand_path(__FILE__))}/db/data.rdb"
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
should "contain 4 layers" do
|
31
31
|
a = DBMLP.new(@db_path, :hidden_layers => [2, 2, 2], :output_nodes => 2, :inputs => 2)
|
32
32
|
assert_equal 4, a.inspect.size
|