boyu-ai/Hands-on-RL

第八章 `In [7]`代码块,VAnet() 疑似有误

Opened this issue · 1 comments

Q = V + A - A.mean(1).view(-1, 1) 疑似应为 Q = V + A - A.mean(-1).view(-1, 1)
否则传入单个状态,也就是state时,A的shape为(3),A.mean(1)会报错,因为只有一个维度;而传入批量状态states时,A的shape为(128,3),此时A.mean(1)不会报错;若修改为A.mean(-1),符合原本思路,且不会报错。

具体差别参考下图:
image

image

报错可能是因为state外面没加中括号[]
state = torch.tensor([state], dtype=torch.float).to(self.device)