Sha256: d2fd3a8839302e8242390d0e873d33493f16f8e99f1c0b8a2ed703ecc56d4b66
Contents?: true
Size: 964 Bytes
Versions: 9
Compression:
Stored size: 964 Bytes
Contents
# A multi-armed bandit implementation inspired by # @aaronsw and victorykit/whiplash require 'simple-random' module Split module Algorithms module Whiplash def self.choose_alternative(experiment) experiment[best_guess(experiment.alternatives)] end private def self.arm_guess(participants, completions) a = [participants, 0].max b = [participants-completions, 0].max s = SimpleRandom.new; s.set_seed; s.beta(a+fairness_constant, b+fairness_constant) end def self.best_guess(alternatives) guesses = {} alternatives.each do |alternative| guesses[alternative.name] = arm_guess(alternative.participant_count, alternative.all_completed_count) end gmax = guesses.values.max best = guesses.keys.select {|name| guesses[name] == gmax } return best.sample end def self.fairness_constant 7 end end end end
Version data entries
9 entries across 9 versions & 1 rubygems