Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed broken merge of Hedge code

  • Loading branch information...
commit 17020b56e281e0271910e4dfa2896d79848a8d14 1 parent 4104232
John Myles White authored
0  julia/algorithms/hedge/hedge/hedge.jl → julia/algorithms/hedge/hedge.jl
View
File renamed without changes
0  julia/algorithms/hedge/hedge/test_hedge.jl → julia/algorithms/hedge/test_hedge.jl
View
File renamed without changes
0  python/algorithms/hedge/hedge/__init__.py
View
No changes.
37 python/algorithms/hedge/hedge/hedge.py
View
@@ -1,37 +0,0 @@
-import math
-import random
-
-def categorical_draw(probs):
- z = random.random()
- cum_prob = 0.0
- for i in range(len(probs)):
- prob = probs[i]
- cum_prob += prob
- if cum_prob > z:
- return i
-
- return len(probs) - 1
-
-class Hedge:
- def __init__(self, temperature, counts, values):
- self.temperature = temperature
- self.counts = counts
- self.values = values
- return
-
- def initialize(self, n_arms):
- self.counts = [0 for col in range(n_arms)]
- self.values = [0.0 for col in range(n_arms)]
- return
-
- def select_arm(self):
- z = sum([math.exp(v / self.temperature) for v in self.values])
- probs = [math.exp(v / self.temperature) / z for v in self.values]
- return categorical_draw(probs)
-
- def update(self, chosen_arm, reward):
- self.counts[chosen_arm] = self.counts[chosen_arm] + 1
-
- value = self.values[chosen_arm]
- self.values[chosen_arm] = value + reward
- return
Please sign in to comment.
Something went wrong with that request. Please try again.