Sha256: 71b18535b5a062f9ea593e50fad3a6b9f7ea82e88a4fb9677a55068e8e50e813
Contents?: true
Size: 1.01 KB
Versions: 3
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true # A multi-armed bandit implementation inspired by # @aaronsw and victorykit/whiplash require 'rubystats' module Split module Algorithms module Whiplash class << self def choose_alternative(experiment) experiment[best_guess(experiment.alternatives)] end private def arm_guess(participants, completions) a = [participants, 0].max b = [participants-completions, 0].max Rubystats::BetaDistribution.new(a+fairness_constant, b+fairness_constant).rng end def 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 } best.sample end def fairness_constant 7 end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
split-4.0.1 | lib/split/algorithms/whiplash.rb |
split-4.0.0.pre2 | lib/split/algorithms/whiplash.rb |
split-4.0.0.pre | lib/split/algorithms/whiplash.rb |