sooth 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -12
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/ext/sooth_native/extconf.rb +3 -0
- data/ext/sooth_native/sooth_context.h +3 -1
- data/ext/sooth_native/sooth_predictor.c +22 -28
- data/ext/sooth_native/sooth_predictor.h +0 -3
- data/sooth.gemspec +5 -5
- data/spec/predictor_spec.rb +27 -0
- 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: 4a0e008c93f017523bc6e99798d7542834d420e7
|
4
|
+
data.tar.gz: 7a4db4e52debe1fceecd1c6d5e4f72117e01de9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd0f597a68319410bc4022d1fde21c7e62571568e536ebdf281f7eeb0eb336271c960682aa910963dad1a58892b64f0bf7cfc177ce04949238d08c8766675ec0
|
7
|
+
data.tar.gz: 5c7d01ff70fac54ad884303341c3c9de87d9ef4ad5fd7528b8b52a49c3f2b1eef42b100d4a5d9137dc432fc61b32ac643cf64a245edba96bd756ea4d965cf455
|
data/README.md
CHANGED
@@ -1,27 +1,17 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/sooth.svg)](http://badge.fury.io/rb/sooth)
|
2
2
|
[![Dependency Status](https://gemnasium.com/jasonhutchens/sooth.png)](https://gemnasium.com/jasonhutchens/sooth)
|
3
|
-
[![Build Status](https://
|
4
|
-
[![Code Climate](https://codeclimate.com/github/jasonhutchens/sooth.png)](https://codeclimate.com/github/jasonhutchens/sooth)
|
3
|
+
[![Build Status](https://semaphoreapp.com/api/v1/projects/6889bf33-e547-4200-a4fb-66b339a83d82/307128/shields_badge.svg)](https://semaphoreapp.com/jasonhutchens/sooth)
|
5
4
|
|
6
5
|
Sooth
|
7
6
|
=====
|
8
7
|
|
9
|
-
Sooth is a simple stochastic predictive model.
|
8
|
+
Sooth is a simple stochastic predictive model. It is used by [MegaHAL](https://github.com/jasonhutchens/megahal).
|
10
9
|
|
11
10
|
Getting Started
|
12
11
|
---------------
|
13
12
|
|
14
13
|
Apart from the specs, look at the [API docs](http://rubydoc.info/github/jasonhutchens/sooth/master/frames) to get up to speed.
|
15
14
|
|
16
|
-
Next
|
17
|
-
----
|
18
|
-
|
19
|
-
* Implement save and load (with specs)
|
20
|
-
* Version 0.9
|
21
|
-
* Hook up to all services
|
22
|
-
* Version 1
|
23
|
-
* MegaHAL that uses it
|
24
|
-
|
25
15
|
Copyright
|
26
16
|
---------
|
27
17
|
|
data/Rakefile
CHANGED
@@ -16,9 +16,9 @@ Jeweler::Tasks.new do |gem|
|
|
16
16
|
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
17
|
gem.name = "sooth"
|
18
18
|
gem.homepage = "http://github.com/jasonhutchens/sooth"
|
19
|
-
gem.license = "
|
20
|
-
gem.summary = %Q{
|
21
|
-
gem.description = %Q{
|
19
|
+
gem.license = "UNLICENSE"
|
20
|
+
gem.summary = %Q{Sooth is a simple stochastic predictive model.}
|
21
|
+
gem.description = %Q{Sooth is a simple stochastic predictive model.}
|
22
22
|
gem.email = "jasonhutchens@gmail.com"
|
23
23
|
gem.authors = ["Jason Hutchens"]
|
24
24
|
gem.required_ruby_version = "~> 2.1"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/ext/sooth_native/extconf.rb
CHANGED
@@ -22,9 +22,6 @@ sooth_predictor_init()
|
|
22
22
|
predictor->contexts = NULL;
|
23
23
|
predictor->contexts_size = 0;
|
24
24
|
|
25
|
-
predictor->statistics = NULL;
|
26
|
-
predictor->statistics_size = 0;
|
27
|
-
|
28
25
|
return predictor;
|
29
26
|
}
|
30
27
|
|
@@ -33,15 +30,18 @@ sooth_predictor_init()
|
|
33
30
|
void
|
34
31
|
sooth_predictor_free(SoothPredictor * predictor)
|
35
32
|
{
|
36
|
-
|
37
|
-
|
33
|
+
for (uint64_t i = 0; i < predictor->contexts_size; ++i)
|
34
|
+
{
|
35
|
+
SoothContext * context = &(predictor->contexts[i]);
|
36
|
+
free(context->statistics);
|
37
|
+
context->statistics = NULL;
|
38
|
+
context->statistics_size = 0;
|
39
|
+
}
|
38
40
|
|
41
|
+
free(predictor->contexts);
|
39
42
|
predictor->contexts = NULL;
|
40
43
|
predictor->contexts_size = 0;
|
41
44
|
|
42
|
-
predictor->statistics = NULL;
|
43
|
-
predictor->statistics_size = 0;
|
44
|
-
|
45
45
|
free(predictor);
|
46
46
|
}
|
47
47
|
|
@@ -76,11 +76,11 @@ sooth_predictor_find_context(SoothPredictor * predictor, uint32_t bigram[2])
|
|
76
76
|
{
|
77
77
|
mid = low + (high - low) / 2;
|
78
78
|
context = &(predictor->contexts[mid]);
|
79
|
-
if (context->bigram[0] < bigram[0] || context->bigram[0] == bigram[0] && context->bigram[1] < bigram[1])
|
79
|
+
if (context->bigram[0] < bigram[0] || (context->bigram[0] == bigram[0] && context->bigram[1] < bigram[1]))
|
80
80
|
{
|
81
81
|
low = mid + 1;
|
82
82
|
}
|
83
|
-
else if (context->bigram[0] > bigram[0] || context->bigram[0] == bigram[0] && context->bigram[1] > bigram[1])
|
83
|
+
else if (context->bigram[0] > bigram[0] || (context->bigram[0] == bigram[0] && context->bigram[1] > bigram[1]))
|
84
84
|
{
|
85
85
|
if (mid == 0)
|
86
86
|
{
|
@@ -117,6 +117,7 @@ sooth_predictor_find_context(SoothPredictor * predictor, uint32_t bigram[2])
|
|
117
117
|
context->bigram[1] = bigram[1];
|
118
118
|
context->count = 0;
|
119
119
|
context->statistics_size = 0;
|
120
|
+
context->statistics = NULL;
|
120
121
|
|
121
122
|
return context;
|
122
123
|
}
|
@@ -124,7 +125,7 @@ sooth_predictor_find_context(SoothPredictor * predictor, uint32_t bigram[2])
|
|
124
125
|
//------------------------------------------------------------------------------
|
125
126
|
|
126
127
|
SoothStatistic *
|
127
|
-
sooth_predictor_find_statistic(
|
128
|
+
sooth_predictor_find_statistic(SoothContext * context, uint32_t symbol)
|
128
129
|
{
|
129
130
|
SoothStatistic * statistic = NULL;
|
130
131
|
uint64_t mid = 0;
|
@@ -137,7 +138,7 @@ sooth_predictor_find_statistic(SoothPredictor * predictor, SoothContext * contex
|
|
137
138
|
while (low <= high)
|
138
139
|
{
|
139
140
|
mid = low + (high - low) / 2;
|
140
|
-
statistic = &(
|
141
|
+
statistic = &(context->statistics[mid]);
|
141
142
|
if (statistic->symbol < symbol)
|
142
143
|
{
|
143
144
|
low = mid + 1;
|
@@ -159,29 +160,22 @@ sooth_predictor_find_statistic(SoothPredictor * predictor, SoothContext * contex
|
|
159
160
|
mid = low;
|
160
161
|
}
|
161
162
|
|
162
|
-
if (context->statistics_size == 0)
|
163
|
-
{
|
164
|
-
context->statistics_offset = predictor->statistics_size;
|
165
|
-
}
|
166
163
|
context->statistics_size += 1;
|
167
|
-
|
168
|
-
|
169
|
-
predictor->statistics_size += 1;
|
170
|
-
SoothStatistic * new_memory = realloc(predictor->statistics, sizeof(SoothStatistic) * predictor->statistics_size);
|
164
|
+
SoothStatistic * new_memory = realloc(context->statistics, sizeof(SoothStatistic) * context->statistics_size);
|
171
165
|
if (new_memory == NULL)
|
172
166
|
{
|
173
167
|
return NULL;
|
174
168
|
}
|
175
|
-
|
169
|
+
context->statistics = new_memory;
|
176
170
|
|
177
|
-
if ((mid + 1) <
|
171
|
+
if ((mid + 1) < context->statistics_size)
|
178
172
|
{
|
179
|
-
SoothStatistic * src = &(
|
180
|
-
SoothStatistic * dest = &(
|
181
|
-
(void)memmove(dest, src, sizeof(SoothStatistic) * (
|
173
|
+
SoothStatistic * src = &(context->statistics[mid]);
|
174
|
+
SoothStatistic * dest = &(context->statistics[mid+1]);
|
175
|
+
(void)memmove(dest, src, sizeof(SoothStatistic) * (context->statistics_size - mid - 1));
|
182
176
|
}
|
183
177
|
|
184
|
-
statistic = &(
|
178
|
+
statistic = &(context->statistics[mid]);
|
185
179
|
statistic->symbol = symbol;
|
186
180
|
statistic->count = 0;
|
187
181
|
|
@@ -200,7 +194,7 @@ sooth_predictor_observe(SoothPredictor * predictor, uint32_t bigram[2], uint32_t
|
|
200
194
|
return 0;
|
201
195
|
}
|
202
196
|
|
203
|
-
SoothStatistic * statistic = sooth_predictor_find_statistic(
|
197
|
+
SoothStatistic * statistic = sooth_predictor_find_statistic(context, symbol);
|
204
198
|
|
205
199
|
if (statistic == NULL)
|
206
200
|
{
|
@@ -242,7 +236,7 @@ sooth_predictor_select(SoothPredictor * predictor, uint32_t bigram[2], uint64_t
|
|
242
236
|
|
243
237
|
for (uint64_t i = 0; i < context->statistics_size; ++i)
|
244
238
|
{
|
245
|
-
SoothStatistic statistic =
|
239
|
+
SoothStatistic statistic = context->statistics[i];
|
246
240
|
if (limit > statistic.count)
|
247
241
|
{
|
248
242
|
limit -= statistic.count;
|
@@ -6,15 +6,12 @@
|
|
6
6
|
#include <stdint.h>
|
7
7
|
|
8
8
|
#include "sooth_context.h"
|
9
|
-
#include "sooth_statistic.h"
|
10
9
|
|
11
10
|
typedef struct
|
12
11
|
{
|
13
12
|
uint32_t error_symbol;
|
14
13
|
uint64_t contexts_size;
|
15
14
|
SoothContext * contexts;
|
16
|
-
uint64_t statistics_size;
|
17
|
-
SoothStatistic * statistics;
|
18
15
|
}
|
19
16
|
SoothPredictor;
|
20
17
|
|
data/sooth.gemspec
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: sooth 0.
|
5
|
+
# stub: sooth 0.2.0 ruby lib
|
6
6
|
# stub: ext/sooth_native/extconf.rb
|
7
7
|
|
8
8
|
Gem::Specification.new do |s|
|
9
9
|
s.name = "sooth"
|
10
|
-
s.version = "0.
|
10
|
+
s.version = "0.2.0"
|
11
11
|
|
12
12
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
13
13
|
s.require_paths = ["lib"]
|
14
14
|
s.authors = ["Jason Hutchens"]
|
15
15
|
s.date = "2014-12-10"
|
16
|
-
s.description = "
|
16
|
+
s.description = "Sooth is a simple stochastic predictive model."
|
17
17
|
s.email = "jasonhutchens@gmail.com"
|
18
18
|
s.extensions = ["ext/sooth_native/extconf.rb"]
|
19
19
|
s.extra_rdoc_files = [
|
@@ -39,10 +39,10 @@ Gem::Specification.new do |s|
|
|
39
39
|
"spec/spec_helper.rb"
|
40
40
|
]
|
41
41
|
s.homepage = "http://github.com/jasonhutchens/sooth"
|
42
|
-
s.licenses = ["
|
42
|
+
s.licenses = ["UNLICENSE"]
|
43
43
|
s.required_ruby_version = Gem::Requirement.new("~> 2.1")
|
44
44
|
s.rubygems_version = "2.4.4"
|
45
|
-
s.summary = "
|
45
|
+
s.summary = "Sooth is a simple stochastic predictive model."
|
46
46
|
|
47
47
|
if s.respond_to? :specification_version then
|
48
48
|
s.specification_version = 4
|
data/spec/predictor_spec.rb
CHANGED
@@ -60,5 +60,32 @@ describe Sooth::Predictor do
|
|
60
60
|
expect(predictor.select([1,2], 0)).to eq(42)
|
61
61
|
expect(predictor.select([1,2], 4)).to eq(42)
|
62
62
|
end
|
63
|
+
|
64
|
+
it "selects the correct symbol with many contexts" do
|
65
|
+
predictor.observe([2,1], 4)
|
66
|
+
predictor.observe([1,3], 5)
|
67
|
+
predictor.observe([3,2], 6)
|
68
|
+
predictor.observe([1,3], 7)
|
69
|
+
predictor.observe([2,1], 8)
|
70
|
+
predictor.observe([3,2], 9)
|
71
|
+
predictor.observe([1,3], 1)
|
72
|
+
predictor.observe([2,1], 2)
|
73
|
+
predictor.observe([3,2], 3)
|
74
|
+
expect(predictor.select([2,1], 0)).to eq(42)
|
75
|
+
expect(predictor.select([2,1], 1)).to eq(2)
|
76
|
+
expect(predictor.select([2,1], 2)).to eq(4)
|
77
|
+
expect(predictor.select([2,1], 3)).to eq(8)
|
78
|
+
expect(predictor.select([2,1], 4)).to eq(42)
|
79
|
+
expect(predictor.select([1,3], 0)).to eq(42)
|
80
|
+
expect(predictor.select([1,3], 1)).to eq(1)
|
81
|
+
expect(predictor.select([1,3], 2)).to eq(5)
|
82
|
+
expect(predictor.select([1,3], 3)).to eq(7)
|
83
|
+
expect(predictor.select([1,3], 4)).to eq(42)
|
84
|
+
expect(predictor.select([3,2], 0)).to eq(42)
|
85
|
+
expect(predictor.select([3,2], 1)).to eq(3)
|
86
|
+
expect(predictor.select([3,2], 2)).to eq(6)
|
87
|
+
expect(predictor.select([3,2], 3)).to eq(9)
|
88
|
+
expect(predictor.select([3,2], 4)).to eq(42)
|
89
|
+
end
|
63
90
|
end
|
64
91
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sooth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Hutchens
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0.9'
|
125
|
-
description:
|
125
|
+
description: Sooth is a simple stochastic predictive model.
|
126
126
|
email: jasonhutchens@gmail.com
|
127
127
|
executables: []
|
128
128
|
extensions:
|
@@ -149,7 +149,7 @@ files:
|
|
149
149
|
- spec/spec_helper.rb
|
150
150
|
homepage: http://github.com/jasonhutchens/sooth
|
151
151
|
licenses:
|
152
|
-
-
|
152
|
+
- UNLICENSE
|
153
153
|
metadata: {}
|
154
154
|
post_install_message:
|
155
155
|
rdoc_options: []
|
@@ -170,5 +170,5 @@ rubyforge_project:
|
|
170
170
|
rubygems_version: 2.4.4
|
171
171
|
signing_key:
|
172
172
|
specification_version: 4
|
173
|
-
summary:
|
173
|
+
summary: Sooth is a simple stochastic predictive model.
|
174
174
|
test_files: []
|