Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix up whiplash math again

  • Loading branch information...
commit 9357cdbb3fef092774cd55f6f3da99497b90f46f 1 parent 3c130ca
@aaronsw aaronsw authored
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/whiplash.rb
View
14 lib/whiplash.rb
@@ -11,11 +11,17 @@ def to_1if0
module Bandit
def arm_guess(observations, victories)
+ nonvictories = [0, (observations - victories)].max
+ df = observations-1
+ df = 1 if df <= 0
+ df = df.to_f
mean = victories.to_f/observations.to_f.to_1if0
- stddev = victories * ((1-mean)**2)
- stddev += [0, (observations - victories)].max * ((0-mean)**2)
- stddev = Math.sqrt(stddev * (1.0/(([0.0, observations.to_f-1].max).to_1if0)))
- stddev = stddev.to_1if0/Math.sqrt(observations.to_f.to_1if0)
+
+ stddev = 0
+ stddev += victories * ((1-mean)**2)
+ stddev += nonvictories * ((0-mean)**2)
+ stddev = 1.0/observations if stddev == 0
+ stddev = Math.sqrt(stddev/df)
out = [0, Distribution::Normal.rng(mean, stddev).call].max
return out + (FAIRNESS_CONSTANT * (1.0/observations.to_f.to_1if0))
end
Please sign in to comment.
Something went wrong with that request. Please try again.