bae 0.0.9 → 0.1.0

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
  SHA1:
3
- metadata.gz: c28a60c92163259beddf8af99cd31357cf3a95a8
4
- data.tar.gz: 34cc3ee332ec6f79d74e2ab04f8d60227c49c1a9
3
+ metadata.gz: ae80b08d7f073815336ca2f4b6d485e63cc64a16
4
+ data.tar.gz: 318820b928f8d66049ad5f329b69cc6c47a1bee3
5
5
  SHA512:
6
- metadata.gz: 4f92cc52a40438b18bf543299345b1a9ae57443b53e8b8cae7169181a436dfc2e4c86627527239c6c0c29d99f0ff723c4f9272a994f4595d58c1f6d5c8acbd5c
7
- data.tar.gz: dfca0d36849a088fdc5c60cb62c9256a7743c329d8acbbdba87cac34f0fb3de1195909598474283a12862a5a1b92688258189b47945330dcf8cc6df563b77e19
6
+ metadata.gz: 9299062efc70e820d4b491e7b7e257f6cba19f49968e55f3e6c05bbee6b6b7af2178bd829ca019238e8e3b9d654b8082c376e91169202f8c41d49c84a0fafb7a
7
+ data.tar.gz: c8d55c7517dc22c9ab937e73d523132c68f940ebb297f9f8798a9b8d736011fbdbcdf60e1fc8b3a71aa039b33d505765bb2a2a14e36489e686efe98303baa0be
@@ -87,20 +87,13 @@ module Bae
87
87
  end
88
88
 
89
89
  def save_state(path)
90
- state = {}
91
- state['frequency_table'] = frequency_table
92
- state['label_instance_count'] = label_instance_count
93
- state['label_index'] = label_index
94
- state['label_index_sequence'] = label_index_sequence
95
- state['total_terms'] = total_terms
96
-
97
90
  ::File.open(::File.expand_path(path), 'w') do |handle|
98
- handle.write(state.to_json)
91
+ handle.write(to_json)
99
92
  end
100
93
  end
101
94
 
102
- def load_state(path)
103
- state = ::JSON.parse(::File.read(::File.expand_path(path)))
95
+ def load_from_json(json)
96
+ state = ::JSON.parse(json)
104
97
 
105
98
  fail 'Missing frequency_table' unless state['frequency_table']
106
99
  fail 'Missing label_instance_count' unless state['label_instance_count']
@@ -117,6 +110,21 @@ module Bae
117
110
  finish_training!
118
111
  end
119
112
 
113
+ def load_state(path)
114
+ state_json = ::File.read(::File.expand_path(path))
115
+ load_from_json(state_json)
116
+ end
117
+
118
+ def to_json
119
+ state = {}
120
+ state['frequency_table'] = frequency_table
121
+ state['label_instance_count'] = label_instance_count
122
+ state['label_index'] = label_index
123
+ state['label_index_sequence'] = label_index_sequence
124
+ state['total_terms'] = total_terms
125
+ state.to_json
126
+ end
127
+
120
128
  private
121
129
 
122
130
  def calculate_likelihoods!
@@ -1,3 +1,3 @@
1
1
  module Bae
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -47,6 +47,15 @@ describe ::Bae::Classifier do
47
47
  expect{ subject.classify(1337) }.to raise_error 'Training data must either be a string or hash'
48
48
  end
49
49
 
50
+ it "can dump the classifier as json" do
51
+ subject.train("positive", {"aaa" => 0, "bbb" => 1})
52
+ subject.train("negative", {"ccc" => 2, "ddd" => 3})
53
+
54
+ subject.finish_training!
55
+
56
+ expect(subject.to_json).to eq(state_json)
57
+ end
58
+
50
59
  it "can save the classifier state" do
51
60
  subject.train("positive", {"aaa" => 0, "bbb" => 1})
52
61
  subject.train("negative", {"ccc" => 2, "ddd" => 3})
@@ -63,7 +72,16 @@ describe ::Bae::Classifier do
63
72
  temp_file.unlink
64
73
  end
65
74
 
66
- it "can correctly load a classifier state and correctly classify" do
75
+ it "can correctly load a classifier state from json and correctly classify" do
76
+ subject.load_from_json(state_json)
77
+
78
+ results = subject.classify({"aaa" => 1, "bbb" => 1})
79
+
80
+ expect(results["positive"]).to be_within(0.001).of(0.94117)
81
+ expect(results["negative"]).to be_within(0.001).of(0.05882)
82
+ end
83
+
84
+ it "can correctly load a classifier state from a file and correctly classify" do
67
85
  temp_file = ::Tempfile.new('some_state')
68
86
  temp_file.write(state_json)
69
87
  temp_file.rewind
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bae
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garrett Thornburg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-27 00:00:00.000000000 Z
11
+ date: 2017-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - ~>
16
+ - - "~>"
17
17
  - !ruby/object:Gem::Version
18
18
  version: '1.6'
19
19
  name: bundler
@@ -21,13 +21,13 @@ dependencies:
21
21
  type: :development
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - '>='
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: '0'
33
33
  name: rspec
@@ -35,13 +35,13 @@ dependencies:
35
35
  type: :development
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  name: rake
@@ -49,7 +49,7 @@ dependencies:
49
49
  type: :development
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Multinomial naive bayes classifier with a kick of java
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
62
+ - ".gitignore"
63
63
  - Gemfile
64
64
  - LICENSE.txt
65
65
  - README.md
@@ -90,17 +90,17 @@ require_paths:
90
90
  - lib
91
91
  required_ruby_version: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '>='
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - '>='
98
+ - - ">="
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.2.2
103
+ rubygems_version: 2.6.10
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Multinomial naive bayes classifier with a kick of java