lib/field_test/calculations.rb in field_test-0.2.0 vs lib/field_test/calculations.rb in field_test-0.2.1
- old
+ new
@@ -1,8 +1,9 @@
+require "distribution/math_extension"
+
# formulas from
# http://www.evanmiller.org/bayesian-ab-testing.html
-
module FieldTest
module Calculations
def self.prob_b_beats_a(alpha_a, beta_a, alpha_b, beta_b)
total = 0.0
@@ -25,17 +26,15 @@
# for performance
logbeta_ac_bc = Math.logbeta(alpha_c, beta_c)
abc = beta_a + beta_b + beta_c
log_bb_j = []
logbeta_j_bb = []
+ logbeta_ac_i_j = []
0.upto(alpha_b - 1) do |j|
log_bb_j[j] = Math.log(beta_b + j)
logbeta_j_bb[j] = Math.logbeta(1 + j, beta_b)
- end
- logbeta_ac_i_j = []
- 0.upto(alpha_a - 1) do |i|
- 0.upto(alpha_b - 1) do |j|
+ 0.upto(alpha_a - 1) do |i|
logbeta_ac_i_j[i + j] ||= Math.logbeta(alpha_c + i + j, abc)
end
end
0.upto(alpha_a - 1) do |i|