tiny_outcome 3.0.0 → 3.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/lib/tiny_outcome.rb +33 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 117564a93dd35781e19d6f1420eb763f2a39ed5feb38a7a3bd3279ad8f1ed4d2
|
4
|
+
data.tar.gz: 5dd7829f20e626b261a004ef3f83a8e48d8e978fc8d400d36f63d62e6f6bfd42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02c0184cb9692db7ffce8fd91cd1ec1b830df1b0bebf453c7fd25744ead1cc2af5ba2e9c990b4eed23d3668231edeb79840b4121ddf65d5ac2bbf57a6e1a85c5
|
7
|
+
data.tar.gz: 3fb696f998d6598d04453b5dbe1ac70216ff340884b9a6d89a6b990338619e7c34197b43a10d7a2403ea4b5ff3ba915cd988c4c1a5b0982c6f39ca7383538006
|
data/lib/tiny_outcome.rb
CHANGED
@@ -32,7 +32,10 @@ class TinyOutcome
|
|
32
32
|
:warmup,
|
33
33
|
:probability,
|
34
34
|
:one_count,
|
35
|
-
:value
|
35
|
+
:value,
|
36
|
+
:min,
|
37
|
+
:max,
|
38
|
+
:avg
|
36
39
|
|
37
40
|
WARM_FULL = :full
|
38
41
|
WARM_TWO_THIRDS = :two_thirds
|
@@ -49,6 +52,9 @@ class TinyOutcome
|
|
49
52
|
@probability = 0.0
|
50
53
|
@one_count = 0
|
51
54
|
@samples = 0
|
55
|
+
@min = 1.0
|
56
|
+
@max = 0.0
|
57
|
+
@avg = 0.0
|
52
58
|
@warmth = 0
|
53
59
|
@value = [0] * @precision
|
54
60
|
@value_index = 0
|
@@ -68,10 +74,7 @@ class TinyOutcome
|
|
68
74
|
(full? ? @value.rotate(@value_index) : @value)[..(samples-1)].join.to_i(2)
|
69
75
|
end
|
70
76
|
|
71
|
-
# add a sample to the historic outcomes
|
72
|
-
# low-order bits. the new sample is literally left-shifted into the value. the
|
73
|
-
# only reason this is a custom method is because some metadata needs to be
|
74
|
-
# updated when a new sample is added
|
77
|
+
# add a sample to the historic outcomes
|
75
78
|
def <<(sample)
|
76
79
|
raise "Invalid sample: #{sample}" unless sample == 0 || sample == 1
|
77
80
|
|
@@ -91,7 +94,7 @@ class TinyOutcome
|
|
91
94
|
@one_count += 1 if sample == 1
|
92
95
|
@probability = @one_count / samples.to_f
|
93
96
|
|
94
|
-
value
|
97
|
+
@value
|
95
98
|
end
|
96
99
|
|
97
100
|
# true if #probability is >= percentage
|
@@ -117,6 +120,30 @@ class TinyOutcome
|
|
117
120
|
samples == precision
|
118
121
|
end
|
119
122
|
|
123
|
+
# updates, and memoizes, the min/max/avg numbers. if you read the min/max/avg
|
124
|
+
# attributes you are getting the MEMOIZED values.
|
125
|
+
def update_stats!
|
126
|
+
return if @samples == 0
|
127
|
+
|
128
|
+
@min = 1.0
|
129
|
+
@max = 0.0
|
130
|
+
@avg = 0.0
|
131
|
+
|
132
|
+
sum = 0.0
|
133
|
+
raw = (full? ? @value.rotate(@value_index) : @value)[..(samples-1)]
|
134
|
+
group_size = [@samples, 100].min
|
135
|
+
num_groups = @samples - group_size
|
136
|
+
raw.each_cons(group_size) do |samples_group|
|
137
|
+
curr = samples_group.count(1) / samples.to_f
|
138
|
+
sum += curr
|
139
|
+
|
140
|
+
@min = curr if curr < @min
|
141
|
+
@max = curr if curr > @max
|
142
|
+
end
|
143
|
+
|
144
|
+
@avg = sum / (@num_groups.to_f + 1.0)
|
145
|
+
end
|
146
|
+
|
120
147
|
# convenient way to see what's up
|
121
148
|
def to_hash
|
122
149
|
[:value,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_outcome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Lunt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|