利用分布Q学习玩《高速公路》游戏及好奇心驱动探索
1. 分布Q学习玩《高速公路》游戏
在使用分布Q学习玩《高速公路》游戏时,首先需要对状态进行预处理,将其转换为PyTorch张量,并将值归一化到0到1之间,以控制梯度的大小。同时,还需要一个策略函数来决定采取何种行动。
import torch
import numpy as np
def preproc_state(state):
p_state = torch.from_numpy(state).unsqueeze(dim=0).float()
p_state = torch.nn.functional.normalize(p_state,dim=1)
return p_state
def get_action(dist,support):
actions = []
for b in range(dist.shape[0]):
expectations = [support @ dist[b,a,:] for a in range(dist.shape[1])]
action = int(np.argmax(expectations))
actions.append(action)
actions = torch.Tensor(actions).int()
return actions
这里, preproc_state 函数将状态转换为张量并归一化, get_ac
超级会员免费看
订阅专栏 解锁全文
547

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



