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

Kl_Ucb implementation #1657

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6bf81df
v1test
W0lfgunbl00d Nov 5, 2024
6aa4869
Update rls.py
W0lfgunbl00d Nov 5, 2024
814fd8a
Added an v0 adpredictor
Mo3ad-S Nov 9, 2024
b309747
Added an v0 adpredictor
Mo3ad-S Nov 9, 2024
069cee9
Merge branch 'online-ml:main' into main
slach31 Nov 16, 2024
6a229d8
adpredictor algorithm
Mo3ad-S Nov 16, 2024
e0e6c75
add adpredictor
Mo3ad-S Nov 16, 2024
ff8c617
added an adpredictor function
Mo3ad-S Nov 16, 2024
67e7e14
remooved adpredictor here
Mo3ad-S Nov 16, 2024
6f43ec8
fixed bugs
Mo3ad-S Nov 17, 2024
89cd67e
fixed bugs
Mo3ad-S Nov 17, 2024
54a94e3
removed rls
Mo3ad-S Nov 17, 2024
4a7bc49
Fix test pre commit
Nov 17, 2024
7311788
Fixed imports
Nov 17, 2024
648b1a4
adjusted the adpredictor algorithm
Mo3ad-S Nov 26, 2024
322b924
Merge branch 'ad_predict' of https://github.com/slach31/riverIDLIB in…
Mo3ad-S Nov 26, 2024
dcb0f98
updated the rest of the project
Mo3ad-S Nov 26, 2024
2855d11
Merge branch 'online-ml:main' into ad_predict
slach31 Nov 26, 2024
1b82c24
modified defaultdict
Mo3ad-S Nov 26, 2024
11a0282
add KL-UCB skeleton
Nov 26, 2024
4d76a0f
added a first version of klucb
Mo3ad-S Nov 27, 2024
e518b8c
Merge branch 'online-ml:main' into KlUcb
slach31 Nov 27, 2024
df3beaa
added a new version of the algorithm
Mo3ad-S Nov 27, 2024
49aecc8
added a new version of the algorithm
Mo3ad-S Nov 27, 2024
65cb16c
added a first version of kl_ucb
Mo3ad-S Nov 27, 2024
7b54884
first round of tests KLUCB
Nov 27, 2024
d87fbaa
fix implementation KLUCB
Nov 27, 2024
165fbd3
Merge branch 'online-ml:main' into KlUcb
slach31 Nov 30, 2024
d5ca2ce
a new version of Kl_Ucb
Mo3ad-S Nov 30, 2024
9a28b0c
a new version of Kl_Ucb
Mo3ad-S Nov 30, 2024
0d60194
Final version of Kl_Ucb
Mo3ad-S Nov 30, 2024
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
Prev Previous commit
Next Next commit
fix implementation KLUCB
  • Loading branch information
s23lachg committed Nov 27, 2024
commit d87fbaa6cc8d152e203c9d7963ffb1ac2716436c
12 changes: 7 additions & 5 deletions river/bandit/kl_ucb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
class KLUCB():
"define the main class for the Klucb"

def __init__(self, n_arms, horizon, c=0):
def __init__(self, n_arms, horizon, c):
self.n_arms = n_arms
self.horizon = horizon
self.c = c
self.arm_count = [1 for _ in range (n_arms)]
self.rewards = [0.0 for _ in range (n_arms)]
self.arm = 0

def calculate_reward(self, arm):
return 1 if random.random() < self.rewards[arm] else 0

def update(self, arm, reward):
self.arm_count[arm] += 1
self.rewards[arm] += reward
Expand All @@ -32,7 +35,7 @@ def kl_index(self, arm):
if n_t == 0:
return float('inf') # Unseen arm
empirical_mean = self.rewards[arm] / n_t
log_t_over_n = math.log(self.t) / n_t
log_t_over_n = math.log(math.log(arm)) / n_t
c_factor = self.c * log_t_over_n

# Binary search to find the q that satisfies the KL-UCB condition
Expand All @@ -45,7 +48,6 @@ def kl_index(self, arm):
high = mid
else:
low = mid
return low

def pull_arm(self, arm):
return 1 if random.random() < self.rewards[arm] else 0
selected_arm = low
return selected_arm