Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace usage of SimpleRandom with RubyStats #616

Merged
merged 1 commit into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/split/algorithms/whiplash.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# A multi-armed bandit implementation inspired by
# @aaronsw and victorykit/whiplash
require 'simple-random'
require 'rubystats'

module Split
module Algorithms
Expand All @@ -16,7 +16,7 @@ def choose_alternative(experiment)
def 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)
Rubystats::BetaDistribution.new(a+fairness_constant, b+fairness_constant).rng
end

def best_guess(alternatives)
Expand Down
9 changes: 4 additions & 5 deletions lib/split/experiment.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# frozen_string_literal: true

require 'rubystats'

module Split
class Experiment
attr_accessor :name
Expand Down Expand Up @@ -354,17 +357,13 @@ def find_simulated_winner(simulated_cr_hash)
end

def calc_simulated_conversion_rates(beta_params)
# initialize a random variable (from which to simulate conversion rates ~beta-distributed)
rand = SimpleRandom.new
rand.set_seed

simulated_cr_hash = {}

# create a hash which has the conversion rate pulled from each alternative's beta distribution
beta_params.each do |alternative, params|
alpha = params[0]
beta = params[1]
simulated_conversion_rate = rand.beta(alpha, beta)
simulated_conversion_rate = Rubystats::BetaDistribution.new(alpha, beta).rng
simulated_cr_hash[alternative] = simulated_conversion_rate
end

Expand Down
2 changes: 1 addition & 1 deletion split.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Gem::Specification.new do |s|

s.add_dependency 'redis', '>= 2.1'
s.add_dependency 'sinatra', '>= 1.2.6'
s.add_dependency 'simple-random', '>= 0.9.3'
s.add_dependency 'rubystats', '>= 0.3.0'

s.add_development_dependency 'bundler', '>= 1.17'
s.add_development_dependency 'simplecov', '~> 0.15'
Expand Down