Class: Vanity::Experiment::BayesianBanditScore

Inherits:
Score
  • Object
show all
Defined in:
lib/vanity/experiment/bayesian_bandit_score.rb

Constant Summary collapse

DEFAULT_PROBABILITY =
90

Instance Attribute Summary

Attributes inherited from Score

#alts, #base, #best, #choice, #least, #method

Instance Method Summary collapse

Constructor Details

#initialize(alternatives, outcome) ⇒ BayesianBanditScore

rubocop:todo Lint/MissingSuper



10
11
12
13
14
# File 'lib/vanity/experiment/bayesian_bandit_score.rb', line 10

def initialize(alternatives, outcome) # rubocop:todo Lint/MissingSuper
  @alternatives = alternatives
  @outcome = outcome
  @method = :bayes_bandit_score
end

Instance Method Details

#calculate!(probability = DEFAULT_PROBABILITY) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vanity/experiment/bayesian_bandit_score.rb', line 16

def calculate!(probability = DEFAULT_PROBABILITY)
  # sort by conversion rate to find second best
  @alts = @alternatives.sort_by(&:measure)
  @base = @alts[-2]

  assign_alternatives_bayesian_probability(@alts)

  @least = assign_alternatives_difference(@alts)

  # best alternative is one with highest conversion rate (best shot).
  @best = @alts.last if @alts.last.measure > 0.0
  # choice alternative can only pick best if we have high probability (>90%).
  @choice = outcome_or_best_probability(@alternatives, @outcome, @best, probability)
  self
end