ql

ql

import numpy as np

Q 矩阵初始化为0

q = np.matrix(np.zeros([6, 6]))

Reward 矩阵为提前定义好的。 类似与HMM的生成矩阵。-1表示无相连接的边

r = np.matrix([[-1, -1, -1, -1, 0, -1],
[-1, -1, -1, 0, -1, 100],
[-1, -1, -1, 0, -1, -1],
[-1, 0, 0, -1, 0, -1],
[ 0, -1, -1, 0, -1, 100],
[-1, 0, -1, -1, 0, 100]])

hyperparameter

#折扣因子
gamma = 0.8
#是否选择最后策略的概率
epsilon = 0.4

the main training loop

for episode in range(101):
# random initial state
state = np.random.randint(0, 6)
# 如果不是最终转态
while (state != 5):
# 选择可能的动作
# Even in random case, we cannot choose actions whose r[state, action] = -1.
possible_actions = []
possible_q = []
for action in range(6):
if r[state, action] >= 0:
possible_actions.append(action)
possible_q.append(q[state, action])

    # Step next state, here we use epsilon-greedy algorithm.action = -1if np.random.random() < epsilon:# choose random actionaction = possible_actions[np.random.randint(0, len(possible_actions))]else:# greedyaction = possible_actions[np.argmax(possible_q)]# Update Q valueq[state, action] = r[state, action] + gamma * q[action].max()# Go to the next statestate = action# Display training progress
if episode % 10 == 0:print("------------------------------------------------")print("Training episode: %d" % episode)print(q)

发布者:admin,转转请注明出处:http://www.yc00.com/news/1689658235a274439.html

相关推荐

  • ql

    2023-7-18
    210
  • Wky刷armbian安装docker,ql

    一,安装armbian 使用Aml Burn Tool软件烧录首选底包至固件。烧录完成后断开玩客云电源备用。(靠近hdmi的那个口子。)使用WIn32 disk imager软件将emmc固件写入U盘。写入成功后,先将U盘插入玩客云

    7月前
    330
  • phoenix支持的QL语法

    支持的命令如下&#xff1a; SELECT Example:SELECT * FROM TEST LIMIT 1000;SELECT * FROM TEST LIMIT 1000 OFFSET 100;SELECT ful

    6月前
    320

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信