目录
2.贪心策略(The epsilon-greedy algorithm)
3.玻尔兹曼勘探(The softmax exploration algorithm)
4.置信上限算法(The upper confidence bound algorithm)
5.汤普森采样算法(The Thompson sampling algorithm)
问题描述:
多臂老虎机问题(Multi-Armed Bandit Problem)是强化学习的经典问题。MAB实际上是一个台机器,在赌场玩的一种赌博游戏,你拉动手臂(杠杆)并得到一个支付(奖励)基于随机生成的概率分布。
我们的目标是,随着时间序列,找出哪台机器可以得出最大的累计奖励,即最大化累计奖励

实现步骤:
1.环境的部署与实现
pip3 install gym_bandits
import gym
import gym_bandits
import numpy as np
env = gym.make("BanditTenArmedGaussian-v0")
print(env.action_space.n)
2.贪心策略(The epsilon-greedy algorithm)
在贪心策略中,我们要么选择表现最好的臂,要么是随机选择臂
'''initialize all variables'''
#number of rounds
num_rounds = 20000
#count of number of times an arm was pulled
count =np.zeros(10)
#sum of rewards of each arm
sum_rewards = np.zeros(10)
#q value is the average reward
Q = np.zeros(10)
#define epsilon_greedy function
def epsilon_greedy(epsilon):
rand = np.random.random()
if rand < epsilon:
action = env.action_space.sample()
else:
action = np.argmax(Q)
retu

最低0.47元/天 解锁文章
2630

被折叠的 条评论
为什么被折叠?



