sabina 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +13 -7
- data/examples/example_ae_01/main.rb +3 -3
- data/examples/example_mp_01/main.rb +4 -4
- data/examples/example_mp_02/main.rb +4 -4
- data/lib/sabina.rb +1 -1
- data/lib/sabina/auto_encoder.rb +3 -3
- data/lib/sabina/layer/base_layer.rb +1 -1
- data/lib/sabina/multilayer_perceptron.rb +5 -5
- data/lib/sabina/{util.rb → utils.rb} +1 -1
- data/lib/sabina/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 09d92303d891d1e1ea24dfe5e688e84debafb475
|
|
4
|
+
data.tar.gz: ef253703112d948b663dc3361f21663bc6a2ab1b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 139f3faf91df64f40ab2ad8619872e6701397f914aaf3a5b49aea3c16367b3cce2c97ed35a29c2bff2f0ed9bcfdf115856cba30c6896e200da81714e1b24ded6
|
|
7
|
+
data.tar.gz: b905b21b887a26eb915011345d74960d96ef41a88521c5acfca1b3bc05d1a146e7d7e6e74671fe8268902bf800c7f0640c23901366ed9e760bca0e3f3b89aecb
|
data/.gitignore
CHANGED
data/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# Sabina
|
|
2
2
|
|
|
3
|
+
[](https://badge.fury.io/rb/sabina) [](https://travis-ci.org/seinosuke/sabina)
|
|
3
4
|
Sabina is a machine learning library.
|
|
4
5
|
This gem provides tools for Multi-Layer Perceptrons and Auto-Encoders.
|
|
5
6
|
|
|
@@ -30,7 +31,7 @@ require 'sabina'
|
|
|
30
31
|
|
|
31
32
|
DIM = 2
|
|
32
33
|
K = 3
|
|
33
|
-
|
|
34
|
+
EPOCH = 100
|
|
34
35
|
|
|
35
36
|
training_data = Sabina::MultilayerPerceptron.load_csv('training_data.csv')
|
|
36
37
|
|
|
@@ -47,7 +48,7 @@ options = {
|
|
|
47
48
|
|
|
48
49
|
mp = Sabina::MultilayerPerceptron.new(options)
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
EPOCH.times do |t|
|
|
51
52
|
mp.learn
|
|
52
53
|
error = mp.error(training_data)
|
|
53
54
|
puts " error : #{error}"
|
|
@@ -62,7 +63,7 @@ Example of normal usage is shown below. Use `SparseAutoEncoder` class when the n
|
|
|
62
63
|
require 'sabina'
|
|
63
64
|
|
|
64
65
|
DIM = 2
|
|
65
|
-
|
|
66
|
+
EPOCH = 100
|
|
66
67
|
|
|
67
68
|
original_data = Sabina::AutoEncoder.load_csv('training_data.csv')
|
|
68
69
|
|
|
@@ -79,7 +80,7 @@ options = {
|
|
|
79
80
|
|
|
80
81
|
sae = Sabina::SparseAutoEncoder.new(options)
|
|
81
82
|
|
|
82
|
-
|
|
83
|
+
EPOCH.times do |t|
|
|
83
84
|
sae.learn
|
|
84
85
|
error = sae.error(original_data)
|
|
85
86
|
puts " error : #{error}"
|
|
@@ -101,7 +102,7 @@ x0,x1,label
|
|
|
101
102
|
|
|
102
103
|
This is a example for two-dimensional vector data. For example, if you want to input D-dimensional vector data, write `x0,x1,...,x(D-1),label` at the first line.
|
|
103
104
|
The column of `label` is used for a cluster id. For example, if there are three clusters in training data, a number at the `label` column will be 0, 1 or 2.
|
|
104
|
-
|
|
105
|
+
|
|
105
106
|
When you prepare a CSV file, load the file as shown below.
|
|
106
107
|
|
|
107
108
|
```ruby
|
|
@@ -187,8 +188,14 @@ Run [examples/example_mp_02/main.rb](https://github.com/seinosuke/sabina/blob/ma
|
|
|
187
188
|
|
|
188
189
|
Run [examples/example_ae_01/main.rb](https://github.com/seinosuke/sabina/blob/master/examples/example_ae_01/main.rb).
|
|
189
190
|
|
|
190
|
-

|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
## MNIST Example
|
|
191
195
|
|
|
196
|
+
[https://github.com/seinosuke/sabina_mnist_example](https://github.com/seinosuke/sabina_mnist_example)
|
|
197
|
+
|
|
198
|
+

|
|
192
199
|
|
|
193
200
|
## Contributing
|
|
194
201
|
|
|
@@ -198,4 +205,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/seinos
|
|
|
198
205
|
## License
|
|
199
206
|
|
|
200
207
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
201
|
-
|
|
@@ -3,7 +3,7 @@ require 'open3'
|
|
|
3
3
|
require 'sabina'
|
|
4
4
|
|
|
5
5
|
DIM = 2
|
|
6
|
-
|
|
6
|
+
EPOCH = 100
|
|
7
7
|
xrange = [-2.2, 2.2]
|
|
8
8
|
yrange = [-2.2, 2.2]
|
|
9
9
|
|
|
@@ -76,7 +76,7 @@ Open3.popen3('gnuplot') do |gp_in, gp_out, gp_err|
|
|
|
76
76
|
log = []
|
|
77
77
|
x_mat = Matrix.columns( original_data.map { |data| data[:x] } )
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
EPOCH.times do |t|
|
|
80
80
|
sae.learn
|
|
81
81
|
log << sae.error(original_data)
|
|
82
82
|
gp_in.puts "set multiplot layout 1, 2"
|
|
@@ -112,7 +112,7 @@ Open3.popen3('gnuplot') do |gp_in, gp_out, gp_err|
|
|
|
112
112
|
|
|
113
113
|
# progress bar
|
|
114
114
|
puts " error : #{log.last}"
|
|
115
|
-
puts " [#{("*"*(t /
|
|
115
|
+
puts " [#{("*"*((t.to_f / EPOCH)*10).to_i).ljust(9, " ")}]"
|
|
116
116
|
print "\e[2A"; STDOUT.flush;
|
|
117
117
|
end
|
|
118
118
|
|
|
@@ -4,7 +4,7 @@ require 'sabina'
|
|
|
4
4
|
|
|
5
5
|
DIM = 2
|
|
6
6
|
K = 2
|
|
7
|
-
|
|
7
|
+
EPOCH = 100
|
|
8
8
|
xrange = [-2.2, 2.2]
|
|
9
9
|
yrange = [-2.2, 2.2]
|
|
10
10
|
|
|
@@ -84,7 +84,7 @@ Open3.popen3('gnuplot') do |gp_in, gp_out, gp_err|
|
|
|
84
84
|
end
|
|
85
85
|
x_mat = Matrix.columns( tmp_data )
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
EPOCH.times do |t|
|
|
88
88
|
mp.learn
|
|
89
89
|
log << mp.error(training_data)
|
|
90
90
|
gp_in.puts "set multiplot layout 1, 2"
|
|
@@ -132,7 +132,7 @@ Open3.popen3('gnuplot') do |gp_in, gp_out, gp_err|
|
|
|
132
132
|
# Training Error
|
|
133
133
|
##################################################
|
|
134
134
|
gp_in.puts "set label 2 center at screen 0.79,0.9 'Training Error' font 'Helvetica,22'"
|
|
135
|
-
gp_in.puts "set xrange [0:#{
|
|
135
|
+
gp_in.puts "set xrange [0:#{EPOCH}]"
|
|
136
136
|
gp_in.puts "set yrange [0:#{log.first + 10}]"
|
|
137
137
|
gp_in.puts "set xlabel 'iteration number'"
|
|
138
138
|
gp_in.puts "set ylabel 'training error'"
|
|
@@ -147,7 +147,7 @@ Open3.popen3('gnuplot') do |gp_in, gp_out, gp_err|
|
|
|
147
147
|
|
|
148
148
|
# progress bar
|
|
149
149
|
puts " error : #{log.last}"
|
|
150
|
-
puts " [#{("*"*(t /
|
|
150
|
+
puts " [#{("*"*((t.to_f / EPOCH)*10).to_i).ljust(9, " ")}]"
|
|
151
151
|
print "\e[2A"; STDOUT.flush;
|
|
152
152
|
end
|
|
153
153
|
|
|
@@ -4,7 +4,7 @@ require 'sabina'
|
|
|
4
4
|
|
|
5
5
|
DIM = 2
|
|
6
6
|
K = 3
|
|
7
|
-
|
|
7
|
+
EPOCH = 100
|
|
8
8
|
xrange = [-2.2, 2.2]
|
|
9
9
|
yrange = [-2.2, 2.2]
|
|
10
10
|
|
|
@@ -96,7 +96,7 @@ Open3.popen3('gnuplot') do |gp_in, gp_out, gp_err|
|
|
|
96
96
|
end
|
|
97
97
|
x_mat = Matrix.columns( tmp_data )
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
EPOCH.times do |t|
|
|
100
100
|
mp.learn
|
|
101
101
|
log << mp.error(training_data)
|
|
102
102
|
gp_in.puts "set multiplot layout 1, 2"
|
|
@@ -144,7 +144,7 @@ Open3.popen3('gnuplot') do |gp_in, gp_out, gp_err|
|
|
|
144
144
|
# Training Error
|
|
145
145
|
##################################################
|
|
146
146
|
gp_in.puts "set label 2 center at screen 0.79,0.9 'Training Error' font 'Helvetica,22'"
|
|
147
|
-
gp_in.puts "set xrange [0:#{
|
|
147
|
+
gp_in.puts "set xrange [0:#{EPOCH}]"
|
|
148
148
|
gp_in.puts "set yrange [0:#{log.first + 10}]"
|
|
149
149
|
gp_in.puts "set xlabel 'iteration number'"
|
|
150
150
|
gp_in.puts "set ylabel 'training error'"
|
|
@@ -159,7 +159,7 @@ Open3.popen3('gnuplot') do |gp_in, gp_out, gp_err|
|
|
|
159
159
|
|
|
160
160
|
# progress bar
|
|
161
161
|
puts " error : #{log.last}"
|
|
162
|
-
puts " [#{("*"*(t /
|
|
162
|
+
puts " [#{("*"*((t.to_f / EPOCH)*10).to_i).ljust(9, " ")}]"
|
|
163
163
|
print "\e[2A"; STDOUT.flush;
|
|
164
164
|
end
|
|
165
165
|
|
data/lib/sabina.rb
CHANGED
data/lib/sabina/auto_encoder.rb
CHANGED
|
@@ -4,7 +4,7 @@ module Sabina
|
|
|
4
4
|
def self.load_csv(file_name)
|
|
5
5
|
table = CSV.table(file_name)
|
|
6
6
|
table.map do |data|
|
|
7
|
-
x =
|
|
7
|
+
x = data[0..-2]
|
|
8
8
|
{ :x => x, :d => x }
|
|
9
9
|
end
|
|
10
10
|
end
|
|
@@ -13,11 +13,11 @@ module Sabina
|
|
|
13
13
|
def check_layers
|
|
14
14
|
super
|
|
15
15
|
|
|
16
|
-
if layers.size != 3
|
|
16
|
+
if @layers.size != 3
|
|
17
17
|
raise "The number of layers must be three."
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
if layers.first.size != layers.last.size
|
|
20
|
+
if @layers.first.size != @layers.last.size
|
|
21
21
|
raise "The number of units of the input layer must be equal to that of the output layer."
|
|
22
22
|
end
|
|
23
23
|
end
|
|
@@ -8,8 +8,8 @@ module Sabina
|
|
|
8
8
|
table = CSV.table(file_name)
|
|
9
9
|
k = table[:label].max + 1
|
|
10
10
|
table.map do |data|
|
|
11
|
-
x =
|
|
12
|
-
d = Array.new(k) { |
|
|
11
|
+
x = data[0..-2]
|
|
12
|
+
d = Array.new(k) { 0 }.tap { |ary| ary[data[:label]] = 1 }
|
|
13
13
|
{ :x => x, :d => d }
|
|
14
14
|
end
|
|
15
15
|
end
|
|
@@ -46,8 +46,8 @@ module Sabina
|
|
|
46
46
|
|
|
47
47
|
# Check if `@layers` is valid.
|
|
48
48
|
def check_layers
|
|
49
|
-
if layers.size < 3
|
|
50
|
-
raise "The number of layers
|
|
49
|
+
if @layers.size < 3
|
|
50
|
+
raise "The number of layers must be more than three."
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
@@ -62,7 +62,7 @@ module Sabina
|
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
# A learning step consists of
|
|
65
|
+
# A learning step consists of
|
|
66
66
|
# a forward propagation, a backward propagation
|
|
67
67
|
# and updating the weights of this multi-layer perceptron.
|
|
68
68
|
def learn
|
data/lib/sabina/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sabina
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- seinosuke
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-10-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -94,7 +94,7 @@ files:
|
|
|
94
94
|
- lib/sabina/layer/mp_output_layer.rb
|
|
95
95
|
- lib/sabina/multilayer_perceptron.rb
|
|
96
96
|
- lib/sabina/sparse_auto_encoder.rb
|
|
97
|
-
- lib/sabina/
|
|
97
|
+
- lib/sabina/utils.rb
|
|
98
98
|
- lib/sabina/version.rb
|
|
99
99
|
- sabina.gemspec
|
|
100
100
|
homepage: https://github.com/seinosuke/sabina
|
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
117
117
|
version: '0'
|
|
118
118
|
requirements: []
|
|
119
119
|
rubyforge_project:
|
|
120
|
-
rubygems_version: 2.
|
|
120
|
+
rubygems_version: 2.5.1
|
|
121
121
|
signing_key:
|
|
122
122
|
specification_version: 4
|
|
123
123
|
summary: This gem is a machine learning library.
|