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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a8910b216a26a625f79de9b5d434d9eb99bee26
4
- data.tar.gz: e4cc1963ab0f619713c933071f8c4cd2d517cb06
3
+ metadata.gz: 09d92303d891d1e1ea24dfe5e688e84debafb475
4
+ data.tar.gz: ef253703112d948b663dc3361f21663bc6a2ab1b
5
5
  SHA512:
6
- metadata.gz: 32f047a576d13cf21b1c7b672d76199d184bb7522e59eccd7d9578f99435b1385cc176ebc7b57d882ed30f85ad6a8e15b3e6b637cfabc342cdcc7d4b5639aaa7
7
- data.tar.gz: 53f9f1cb437b6d8fbed01100c2d60264beb891b28c5eacaa7eff41b51f05bb078acad8c7c8792f041c25802ef71c89080b8d711676f189ae3a7505e4a28775ad
6
+ metadata.gz: 139f3faf91df64f40ab2ad8619872e6701397f914aaf3a5b49aea3c16367b3cce2c97ed35a29c2bff2f0ed9bcfdf115856cba30c6896e200da81714e1b24ded6
7
+ data.tar.gz: b905b21b887a26eb915011345d74960d96ef41a88521c5acfca1b3bc05d1a146e7d7e6e74671fe8268902bf800c7f0640c23901366ed9e760bca0e3f3b89aecb
data/.gitignore CHANGED
@@ -8,3 +8,5 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /ex/
11
+ /bin/
12
+ /test/
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Sabina
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/sabina.svg)](https://badge.fury.io/rb/sabina) [![Build Status](https://travis-ci.org/seinosuke/sabina.svg?branch=master)](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
- LOOP_NUM = 100
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
- LOOP_NUM.times do |t|
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
- LOOP_NUM = 10
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
- LOOP_NUM.times do |t|
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
- ![ae_learning_process.gif](https://github.com/seinosuke/sabina/blob/master/examples/example_ae_01/mp_learning_process.gif)
191
+ ![ae_learning_process.gif](https://github.com/seinosuke/sabina/blob/master/examples/example_ae_01/ae_learning_process.gif)
192
+
193
+
194
+ ## MNIST Example
191
195
 
196
+ [https://github.com/seinosuke/sabina_mnist_example](https://github.com/seinosuke/sabina_mnist_example)
197
+
198
+ ![sabina_demo_01.gif](https://github.com/seinosuke/sabina_mnist_example/blob/master/images/sabina_demo_01.gif)
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
- LOOP_NUM = 100
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
- LOOP_NUM.times do |t|
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 / (LOOP_NUM / 10))).ljust(10, " ")}]"
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
- LOOP_NUM = 100
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
- LOOP_NUM.times do |t|
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:#{LOOP_NUM}]"
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 / (LOOP_NUM / 10))).ljust(10, " ")}]"
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
- LOOP_NUM = 100
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
- LOOP_NUM.times do |t|
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:#{LOOP_NUM}]"
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 / (LOOP_NUM / 10))).ljust(10, " ")}]"
162
+ puts " [#{("*"*((t.to_f / EPOCH)*10).to_i).ljust(9, " ")}]"
163
163
  print "\e[2A"; STDOUT.flush;
164
164
  end
165
165
 
@@ -2,7 +2,7 @@ require 'matrix'
2
2
  require 'csv'
3
3
 
4
4
  require "sabina/version"
5
- require "sabina/util"
5
+ require "sabina/utils"
6
6
  require "sabina/layer"
7
7
  require "sabina/layer/base_layer"
8
8
  require "sabina/configuration"
@@ -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 = (data.size-1).times.map { |d| data["x#{d}".to_sym] }
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
@@ -16,7 +16,7 @@ module Sabina::Layer
16
16
 
17
17
  # (J, I)
18
18
  @W = Array.new(@J) do
19
- Array.new(@I) { Sabina::Util.box_muller }
19
+ Array.new(@I) { Sabina::Utils.box_muller }
20
20
  end.tap { |ary| break Matrix[*ary] }
21
21
  end
22
22
 
@@ -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 = (data.size-1).times.map { |d| data["x#{d}".to_sym] }
12
- d = Array.new(k) { |i| i == data[:label] ? 1 : 0 }
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 size must be more than three."
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
@@ -1,5 +1,5 @@
1
1
  module Sabina
2
- module Util
2
+ module Utils
3
3
  def box_muller(s = 1.0)
4
4
  r_1 = rand
5
5
  r_2 = rand
@@ -1,3 +1,3 @@
1
1
  module Sabina
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-04-19 00:00:00.000000000 Z
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/util.rb
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.4.5
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.