red-datasets 0.0.4 → 0.0.5

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
  SHA256:
3
- metadata.gz: 56c3132aec99f8dab763d68d0b731df0e5b2c97ea9f88a847021210fda94b9ac
4
- data.tar.gz: 20e11d381718b801dac9c155385837b770c5067646ac235ade9c0f06f4d23cb8
3
+ metadata.gz: 1b52a97ab0ea10ea2d5ca5b873adab2e57aa8f8a71093e9e94c13da55bc8f774
4
+ data.tar.gz: 5f5525fc4cda3a9a57c08f6855fedd4da3c4be8b72fb7b35cee0e99133492c1f
5
5
  SHA512:
6
- metadata.gz: 1c3ccf7b09e6064cacc47c04dd972ef4ba9318278630446ae60911412e9dc5dced5c988423b78a1c0ae68d71ede6136ebd2ee9c86f4247fd56bbf940f7997f7e
7
- data.tar.gz: bebe49f31022dfeab1eb7626ef1eaf722d5dedf373dab89ba79e3e2afb4849ace50b5098688e4d0480f22719a758a086c288c600cdcb358099a7aa9d1e60eab1
6
+ metadata.gz: ae45fd3d9a6128ddca38c2b37a3a0c8fa89c831bdb1e14c1fdda2183be29385f74df6259ec4ae36934b8c0db57c9d2434208beeeaed854ea254ec6c327f21d64
7
+ data.tar.gz: 45209c6e106d78d008e73ab4414a933bc8f7333addf107c773b78f74359ef1fec262d5a22eeb9818db1512e1d0aab30f1baa00944bdd49eb7d8717f02454064b
data/README.md CHANGED
@@ -48,11 +48,10 @@ cifar = Datasets::CIFAR.new(n_classes: 10, type: :train)
48
48
  cifar.metadata
49
49
  #=> #<struct Datasets::Metadata name="CIFAR-10", url="https://www.cs.toronto.edu/~kriz/cifar.html", licenses=nil, description="CIFAR-10 is 32x32 image dataset">licenses=nil, description="CIFAR-10 is 32x32 image datasets">
50
50
  cifar.each do |record|
51
- p record.pixels
52
- # => [59, 43, 50, 68, 98, 119, 139, 145, 149, 143, .....]
53
- p record.label
54
- # => 6
55
- end
51
+ p record.pixels
52
+ # => [59, 43, 50, 68, 98, 119, 139, 145, 149, 143, .....]
53
+ p record.label
54
+ # => 6
56
55
  end
57
56
  ```
58
57
 
@@ -65,13 +64,12 @@ cifar = Datasets::CIFAR.new(n_classes: 100, type: :test)
65
64
  cifar.metadata
66
65
  #=> #<struct Datasets::Metadata name="CIFAR-100", url="https://www.cs.toronto.edu/~kriz/cifar.html", licenses=nil, description="CIFAR-100 is 32x32 image dataset">
67
66
  cifar.each do |record|
68
- p record.pixels
69
- #=> [199, 196, 195, 195, 196, 197, 198, 198, 199, .....]
70
- p record.coarse_label
71
- #=> 10
72
- p record.fine_label
73
- #=> 49
74
- end
67
+ p record.pixels
68
+ #=> [199, 196, 195, 195, 196, 197, 198, 198, 199, .....]
69
+ p record.coarse_label
70
+ #=> 10
71
+ p record.fine_label
72
+ #=> 49
75
73
  end
76
74
  ```
77
75
 
data/doc/text/news.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # News
2
2
 
3
+ ## 0.0.5 - 2018-06-06
4
+
5
+ ### Improvements
6
+
7
+ * `Datasets::Table#[]`: Added.
8
+
9
+ * `Datasets::Table#fetch_values`: Added.
10
+
11
+ * `Datasets::Table#each`: Added.
12
+
13
+ * `Datasets::CIFAR`: Added pixels data to `Datasets::Table`.
14
+
15
+ ### Fixes
16
+
17
+ * Fixed indent of sample codes in README.
18
+ [GitHub#11][Patch by FURUSAWA Tomohiro]
19
+
20
+ ### Thanks
21
+
22
+ * FURUSAWA Tomohiro
23
+
3
24
  ## 0.0.4 - 2018-05-03
4
25
 
5
26
  ### Improvements
@@ -5,16 +5,24 @@ require_relative "dataset"
5
5
 
6
6
  module Datasets
7
7
  class CIFAR < Dataset
8
- class Record10 < Struct.new(:data, :label)
8
+ module Pixelable
9
9
  def pixels
10
10
  data.unpack("C*")
11
11
  end
12
+
13
+ def to_h
14
+ hash = super
15
+ hash[:pixels] = pixels
16
+ hash
17
+ end
18
+ end
19
+
20
+ class Record10 < Struct.new(:data, :label)
21
+ include Pixelable
12
22
  end
13
23
 
14
24
  class Record100 < Struct.new(:data, :coarse_label, :fine_label)
15
- def pixels
16
- data.unpack("C*")
17
- end
25
+ include Pixelable
18
26
  end
19
27
 
20
28
  def initialize(n_classes: 10, type: :train)
@@ -1,9 +1,31 @@
1
1
  module Datasets
2
2
  class Table
3
+ include Enumerable
4
+
3
5
  def initialize(dataset)
4
6
  @dataset = dataset
5
7
  end
6
8
 
9
+ def each(&block)
10
+ columner_data.each(&block)
11
+ end
12
+
13
+ def [](name)
14
+ columner_data[name.to_sym]
15
+ end
16
+
17
+ def fetch_values(*keys)
18
+ data = columner_data
19
+ keys.collect do |key|
20
+ if data.key?(key)
21
+ data[key]
22
+ else
23
+ raise build_key_error(key) unless block_given?
24
+ yield(key)
25
+ end
26
+ end
27
+ end
28
+
7
29
  def to_h
8
30
  columns = {}
9
31
  @dataset.each do |record|
@@ -14,5 +36,24 @@ module Datasets
14
36
  end
15
37
  columns
16
38
  end
39
+
40
+ private
41
+ begin
42
+ KeyError.new("message", receiver: self, key: :key)
43
+ rescue ArgumentError
44
+ def build_key_error(key)
45
+ KeyError.new("key not found: #{key.inspect}")
46
+ end
47
+ else
48
+ def build_key_error(key)
49
+ KeyError.new("key not found: #{key.inspect}",
50
+ receiver: self,
51
+ key: key)
52
+ end
53
+ end
54
+
55
+ def columner_data
56
+ @columns ||= to_h
57
+ end
17
58
  end
18
59
  end
@@ -1,3 +1,3 @@
1
1
  module Datasets
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/test/test-cifar.rb CHANGED
@@ -168,6 +168,11 @@ class CIFARTest < Test::Unit::TestCase
168
168
  ],
169
169
  raw_dataset)
170
170
  end
171
+
172
+ test("#to_table") do
173
+ assert_equal([[10] * 3072, [20] * 3072],
174
+ @dataset.to_table[:pixels])
175
+ end
171
176
  end
172
177
 
173
178
  sub_test_case("test") do
@@ -204,6 +209,11 @@ class CIFARTest < Test::Unit::TestCase
204
209
  ],
205
210
  raw_dataset)
206
211
  end
212
+
213
+ test("#to_table") do
214
+ assert_equal([[100] * 3072, [200] * 3072],
215
+ @dataset.to_table[:pixels])
216
+ end
207
217
  end
208
218
  end
209
219
  end
data/test/test-table.rb CHANGED
@@ -3,6 +3,56 @@ class TableTest < Test::Unit::TestCase
3
3
  @table = Datasets::Iris.new.to_table
4
4
  end
5
5
 
6
+ test("#[]") do
7
+ assert_equal([1.4, 1.4, 1.3, 1.5, 1.4],
8
+ @table[:petal_length].first(5))
9
+ end
10
+
11
+ sub_test_case("#fetch_values") do
12
+ test("found") do
13
+ values = @table.fetch_values(:petal_length, :petal_width)
14
+ assert_equal([
15
+ [1.4, 1.4, 1.3, 1.5, 1.4],
16
+ [0.2, 0.2, 0.2, 0.2, 0.2],
17
+ ],
18
+ values.collect {|v| v.first(5)})
19
+ end
20
+
21
+ sub_test_case("not found") do
22
+ test("with block") do
23
+ values = @table.fetch_values(:petal_length, :unknown) do |key|
24
+ [key] * 5
25
+ end
26
+ assert_equal([
27
+ [1.4, 1.4, 1.3, 1.5, 1.4],
28
+ [:unknown] * 5,
29
+ ],
30
+ values.collect {|v| v.first(5)})
31
+ end
32
+
33
+ test("without block") do
34
+ assert_raise(KeyError) do
35
+ @table.fetch_values(:unknown)
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ test("#each") do
42
+ shorten_hash = {}
43
+ @table.each do |name, values|
44
+ shorten_hash[name] = values.first(5)
45
+ end
46
+ assert_equal({
47
+ :class => ["Iris-setosa"] * 5,
48
+ :petal_length => [1.4, 1.4, 1.3, 1.5, 1.4],
49
+ :petal_width => [0.2, 0.2, 0.2, 0.2, 0.2],
50
+ :sepal_length => [5.1, 4.9, 4.7, 4.6, 5.0],
51
+ :sepal_width => [3.5, 3.0, 3.2, 3.1, 3.6],
52
+ },
53
+ shorten_hash)
54
+ end
55
+
6
56
  test("#to_h") do
7
57
  shorten_hash = {}
8
58
  @table.to_h.each do |name, values|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red-datasets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - tomisuker
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-05-03 00:00:00.000000000 Z
12
+ date: 2018-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.7.6
137
+ rubygems_version: 3.0.0.beta1
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: Red Datasets provides classes that provide common datasets such as iris dataset.