bgalbraith / bandits Goto Github PK
View Code? Open in Web Editor NEWPython library for Multi-Armed Bandits
License: Apache License 2.0
Python library for Multi-Armed Bandits
License: Apache License 2.0
rt
Thank you very much for the code of n-armed bandits problem.
I read your code, and found there may be a mistake in the file
bandits/bandits/bandit.py
line 38: return (np.random.normal(self.action_values[action]),
I think the correct one should be the following
line 38: return (self.action_values[action],
If you use np.random.normal() here, a new random number will be generated with mean self.action_values[action], this is not what we want, right?
class EpsilonGreedyPolicy(Policy):
[................................]
def choose(self, agent):
if np.random.random() < self.epsilon:
return np.random.choice(len(agent.value_estimates))
else:
action = np.argmax(agent.value_estimates) <---------
check = np.where(agent.value_estimates == action)[0] <------
if len(check) == 0:
return action
else:
return np.random.choice(check)
I don't really get how the lines with "<-----------" work. Action is an index of value_estimates, okay, but in the second line I think you are comparing an index with value_estimates values!! This is the reason why len(check) can be 0. I believe the correct code would be:
def choose(self, agent):
if np.random.random() < self.epsilon:
return np.random.choice(len(agent.value_estimates))
else:
action = np.argmax(agent.value_estimates) <---------
check = np.where(agent.value_estimates == agent.value_estimates[action])[0] <------
if len(check) == 1: <--- At least there is going to be 1
return action
else: <---- Ties are solved randomly
return np.random.choice(check)
Please, let me know if I'm mistaking. Thank you!
I see your policy in bandits/agent.py
class EpsilonGreedyPolicy(Policy):
"""
The Epsilon-Greedy policy will choose a random action with probability
epsilon and take the best apparent approach with probability 1-epsilon. If
multiple actions are tied for best choice, then a random action from that
subset is selected.
"""
def __init__(self, epsilon):
self.epsilon = epsilon
def __str__(self):
return '\u03B5-greedy (\u03B5={})'.format(self.epsilon)
def choose(self, agent):
if np.random.random() < self.epsilon:
return np.random.choice(len(agent.value_estimates))
else:
action = np.argmax(agent.value_estimates)
check = np.where(agent.value_estimates == action)[0]
if len(check) == 0:
return action
else:
return np.random.choice(check)
I do not understand what check means. Action is the biggest element's indices in the array. And what check means? Also what does its length indicate?
Thank you~
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.