Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻

Siddharth Jain SidJain1412

👨‍💻
View GitHub Profile
View ab_testing_snippet.py
import random
# How many times each ad was clicked
ad_rewards = [0] * bandits
# How many times each ad was selected
ad_selection = [0] * bandits
# N: Number of users
N = df.shape[0]
# bandits: Number of ads
View ucb_reinforcement.py
def calculate_upper_bound(wins, num_selections, n):
average_reward = wins / num_selections
delta_i = math.sqrt(3/2 * math.log(n + 1) / num_selections)
upper_bound = average_reward + delta_i
return upper_bound
import math
import random
View thompson_sampling_snippet.py
from scipy.stats import beta
import random
ads_selected = []
# d = number of ads
number_of_wins = [0] * d
number_of_losses = [0] * d
total_reward = 0
View random_color.py
import numpy as np
def random_color():
ltemp = np.random.randint(0, 255, 3)
return "#%02x%02x%02x" % tuple(ltemp)
# col = random_color()
# print(col)
# '#eb4de9'