db_mlp 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -0
- data/VERSION +1 -1
- data/db_mlp.gemspec +5 -4
- data/lib/db_mlp.rb +1 -0
- data/lib/modules/training.rb +2 -1
- data/test/test_db_mlp.rb +36 -18
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -30,6 +30,13 @@ This is first release and because of that it's a bit slow, I'll probably try out
|
|
30
30
|
puts "[1,0] = > #{a.feed_forward([1,0]).inspect}"
|
31
31
|
puts "[1,1] = > #{a.feed_forward([1,1]).inspect}"
|
32
32
|
|
33
|
+
You can also tell the network what iterations you would like it to perform validation on:
|
34
|
+
|
35
|
+
DBMLP.new(path_to_db, :hidden_layers => [2],
|
36
|
+
:output_nodes => 1,
|
37
|
+
:inputs => 2,
|
38
|
+
:validate_every => 100)
|
39
|
+
|
33
40
|
== Test Reports
|
34
41
|
|
35
42
|
If you want it to, the MLP can produce a test report. The basic idea is that at the end of training the MLP will feedforward again all the entries that you have passed into the validation attribute. The file contains data about the index, the data that was inputted, the target, the result and the error. Here's an example:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/db_mlp.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{db_mlp}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["reddavis"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-11-11}
|
13
13
|
s.description = %q{Database backed Multi-Layer Perceptron Neural Network in Ruby}
|
14
14
|
s.email = %q{reddavis@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -69,3 +69,4 @@ Gem::Specification.new do |s|
|
|
69
69
|
else
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
data/lib/db_mlp.rb
CHANGED
data/lib/modules/training.rb
CHANGED
@@ -5,7 +5,8 @@ module Training
|
|
5
5
|
def train_and_cross_validate(training, validations, n)
|
6
6
|
errors = []
|
7
7
|
1.upto(n) do |i|
|
8
|
-
if i %
|
8
|
+
if i % @validate_every == 0
|
9
|
+
print_message("Validating at #{i}")
|
9
10
|
if validate(validations)
|
10
11
|
print_message("Stopping at #{i}")
|
11
12
|
break
|
data/test/test_db_mlp.rb
CHANGED
@@ -139,7 +139,43 @@ class TestDBMLP < Test::Unit::TestCase
|
|
139
139
|
assert_equal 3, a.inspect.first.last.weights.size
|
140
140
|
end
|
141
141
|
end
|
142
|
+
|
143
|
+
context "Validations" do
|
144
|
+
setup do
|
145
|
+
$stdout = StringIO.new
|
146
|
+
@db_path = "sqlite3://#{File.dirname(File.expand_path(__FILE__))}/db/data.rdb"
|
147
|
+
set_data_variables
|
148
|
+
end
|
142
149
|
|
150
|
+
should "validate every 1 iterations" do
|
151
|
+
a = DBMLP.new(@db_path, :hidden_layers => [2],
|
152
|
+
:output_nodes => 1,
|
153
|
+
:inputs => 2,
|
154
|
+
:verbose => true,
|
155
|
+
:validate_every => 2)
|
156
|
+
|
157
|
+
a.train(@training, @testing, @validation, 4)
|
158
|
+
output = $stdout.string.scan(/Validating/)
|
159
|
+
assert_equal 2, output.size
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context "Testing Results Parser" do
|
164
|
+
setup do
|
165
|
+
@test_results = File.dirname(__FILE__) + '/db/test_results_test/results.txt'
|
166
|
+
end
|
167
|
+
|
168
|
+
should "return 100%" do
|
169
|
+
result = DBMLP.parse_test_results(@test_results, 1)
|
170
|
+
assert_equal 100, result
|
171
|
+
end
|
172
|
+
|
173
|
+
should "return 50%" do
|
174
|
+
result = DBMLP.parse_test_results(@test_results, 0.00002)
|
175
|
+
assert_equal 50, result
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
143
179
|
private
|
144
180
|
|
145
181
|
def set_data_variables
|
@@ -147,23 +183,5 @@ class TestDBMLP < Test::Unit::TestCase
|
|
147
183
|
@testing = [[[0,0], [0]], [[0,1], [1]], [[1,0], [1]], [[1,1], [0]]]
|
148
184
|
@validation = [[[0,0], [0]], [[0,1], [1]], [[1,0], [1]], [[1,1], [0]]]
|
149
185
|
end
|
150
|
-
|
151
|
-
public
|
152
|
-
|
153
|
-
context "Testing Results Parser" do
|
154
|
-
setup do
|
155
|
-
@test_results = File.dirname(__FILE__) + '/db/test_results_test/results.txt'
|
156
|
-
end
|
157
|
-
|
158
|
-
should "return 100%" do
|
159
|
-
result = DBMLP.parse_test_results(@test_results, 1)
|
160
|
-
assert_equal 100, result
|
161
|
-
end
|
162
|
-
|
163
|
-
should "return 50%" do
|
164
|
-
result = DBMLP.parse_test_results(@test_results, 0.00002)
|
165
|
-
assert_equal 50, result
|
166
|
-
end
|
167
|
-
end
|
168
186
|
|
169
187
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db_mlp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- reddavis
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-11 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|