tiny_outcome 1.0.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tiny_outcome.rb +9 -42
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abde8e389e945ae56753b61b75b9f7df7474044820cff7250874a73286a2f8bb
4
- data.tar.gz: 59f041591c740d22a42f55ef7e6a2363854d9715a4aa22775fb80f8384836aee
3
+ metadata.gz: 3611d8970ea3a209328e2149c518dc2c8ea0e15c8297ec6951d63c0d2c9d2ce1
4
+ data.tar.gz: 0bb76d7481157879e2d7a4e0b0d3edfc87bb96af5a85c5c3dc64187e9b53c6af
5
5
  SHA512:
6
- metadata.gz: b6c89f18a20e5b2c4e0b0fbaff9391680b98901a6f2ee6cfc6af09089027c9b9642fafb28ea46c46ec7af42282c083a3fc98477413ea3510ed2d072764a4200f
7
- data.tar.gz: ec5e0b226364e2d8f7810fa9fd4691acb8fc3dae2dc704c9566ba0d27c05f571252b14b47d5d077a646927a5c31869356b7f0a6145ca3b2b20ecb5178581d574
6
+ metadata.gz: 10d7cea58b4f4bdf02988ff2ab3fcb91ee3f28dea1df19ddaa2e0fff2d3f7090e39dd4f696985926e688ae320128dab7d96708aee3f87c3cb8bff026d075c353
7
+ data.tar.gz: 5646f503b6998e99df4d68e21a10f70344d3e9e9f0aa363e9b751d2def1664924a286319c022867fc0019cce5f2f40ee74b0792bf18ef67c156af88681805da8
data/lib/tiny_outcome.rb CHANGED
@@ -20,17 +20,11 @@
20
20
  # 87.times { o << rand(2) }
21
21
  #
22
22
  # to_s reveals how we're doing:
23
- # L10 1111000110 coinflip 0.49 84/84::128/128
23
+ # L10 1111000110 w 0.49 84/84::128/128
24
24
  #
25
25
  # this tells us that of the 128 precision capacity, we're currently warmed up
26
- # because we have the minimum (at least 84 samples) to be considered warmed up.
27
- # there's also a prediction here: that the outcome is essentially a coinflip.
28
- # this is because the observed likelihood of an outcome of 1 is 49% in this
29
- # example, well within the range of random chance. if we had a TinyOutcome with
30
- # a precision of 10,000 we wouldn't necessarily consider 49% a true coinflip,
31
- # but because we're trying to predict things within a relatively small sample
32
- # size, we don't want to go all the way to that level of precision, it's more
33
- # like just trying to win more than we lose.
26
+ # because we have the minimum (at least 84 samples) to be considered warmed up
27
+ # (this is also indicated with the lowercase 'w').
34
28
  class TinyOutcome
35
29
  attr_reader :precision,
36
30
  :samples,
@@ -60,7 +54,8 @@ class TinyOutcome
60
54
  when WARM_ONE_THIRD then precision / 3
61
55
  when WARM_NONE then 0
62
56
  else
63
- raise "Invalid warmup: #{warmup.inspect}"
57
+ raise "Invalid warmup: #{warmup.inspect}" if (!warmup.is_a?(Integer) || warmup < 1)
58
+ warmup
64
59
  end
65
60
  end
66
61
 
@@ -91,41 +86,13 @@ class TinyOutcome
91
86
  # probabilty = ---------------
92
87
  # total samples
93
88
  def probability
94
- return -1 unless warm?
95
- value.to_s(2).count('1') / samples.to_f
96
- end
97
-
98
- # classifies the probability of the next outcome
99
- #
100
- # :cold - if this Outcome isn't yet warm
101
- # :highly_positive - greater than 95% chance that the next outcome will be a 1
102
- # :positive - greater than 90% chance the next outcome will be a 1
103
- # :coinflip - 50% chance (+/- 5%) that the next outcome will be a 1
104
- # :negative - less than 10% chance the next outcome will be a 1
105
- # :highly_negative - less than 5% chance the next outcome will be a 1
106
- # :weak - for all other outcomes
107
- def prediction
108
- return :cold unless warm?
109
-
110
- case probability
111
- when 0...0.05 then :disaster
112
- when 0.05...0.1 then :strongly_negative
113
- when 0.1...0.32 then :negative
114
- when 0.32..0.34 then :one_third
115
- when 0.34...0.48 then :weakly_negative
116
- when 0.48..0.52 then :coinflip
117
- when 0.52...0.65 then :weakly_positive
118
- when 0.65..0.67 then :two_thirds
119
- when 0.67..0.9 then :positive
120
- when 0.9...0.95 then :strongly_positive
121
- when 0.95..1.0 then :amazing
122
- end
89
+ (value.to_s(2).count('1') / samples.to_f).round(2)
123
90
  end
124
91
 
125
92
  # true if we've received at least warmup number of samples
126
93
  # false otherwise
127
94
  def warm?
128
- warmth == warmup
95
+ warmth >= warmup
129
96
  end
130
97
 
131
98
  # the opposite of warm: a TinyOutcome can only be cold or warm
@@ -146,15 +113,15 @@ class TinyOutcome
146
113
  :warmth,
147
114
  :warmup,:warm?,
148
115
  :probability,
149
- :prediction,
150
116
  ].each_with_object({}) do |attr, memo|
151
117
  memo[attr] = send(attr)
152
118
  memo
153
119
  end
154
120
  end
155
121
 
122
+ # L10 = last 10 samples
156
123
  def to_s
157
124
  max_backward = [value.to_s(2).length, 10].min
158
- "L10 #{value.to_s(2)[-max_backward..-1].rjust(10, '?')} #{prediction} #{'%.2f' % probability} #{warmth}/#{warmup}::#{samples}/#{precision}"
125
+ "L10 #{value.to_s(2)[-max_backward..-1].rjust(10, '?')} #{warm? ? 'W' : 'c'} #{'%.2f' % probability} #{warmth}/#{warmup}::#{samples}/#{precision}"
159
126
  end
160
127
  end
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: 1.0.1
4
+ version: 2.0.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: 2022-12-04 00:00:00.000000000 Z
11
+ date: 2022-12-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: a tiny outcome tracker with almost no features
14
14
  email: jefflunt@gmail.com