Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coma td_error 中target q的计算问题 #25

Closed
yywe opened this issue May 26, 2020 · 5 comments
Closed

coma td_error 中target q的计算问题 #25

yywe opened this issue May 26, 2020 · 5 comments

Comments

@yywe
Copy link

yywe commented May 26, 2020

Hi, 老兄,又来请教一番,哈哈。

我注意到在coma中q_next_target的计算,有点不太理解,为啥这么计算。
282 q_evals = torch.gather(q_evals, dim=3, index=u).squeeze(3)
283 q_next_target = torch.gather(q_next_target, dim=3, index=u_next).squeeze(3)

根据我的理解,一般有两种计算target的方式,dqn, 或者ddqn. 前者用eval net的argmax取action, 后者直接target net取argmax.

这里我有2个问题:
(1) 为啥用执行的u_next来选取动作呢, 不用dqn或者ddqn的方式?
(2) 这个u_next的最后一步(因为实际最后teminate的时候没动作)是用0填充的,我看了看smac的源码, 0大概是noop,但是noop对活的agent是不可用的。所以这样会不会有问题?

@starry-sky6688
Copy link
Owner

(1)COMA是on-policy,所以只能用当前策略去选择下一个动作,而不能像DQN那样选择最大的。
(2)如果是填充的话,那么mask那里应该会抹掉,不会影响网络的更新。

@yywe
Copy link
Author

yywe commented May 26, 2020

(1) make sense
(2) 我之前这么想过,但是我感觉这里mask 抹不掉?
因为这里最后一步的target其实是为了计算最后一步的td error.
比如说这里假设最后一步是取的a,就是q_evals[-1] (就是q [a]是其中的某个值), 然后 terminated 了。
对应的,q_target,因为没有下一步了,填充的。
所以这里最后一步有个td error: (q_evals[-1][a] - q_target[-1][0]) **2
虽然q_target的最后一个是填充的,但是q-evals全部都不是填充的?
就是说, mask跟terminated不会截断最后一步,毕竟最后一步是真实的。

这个跟q-learning不一样的地方在于,q-learning的最后一步没有predicted target再选值这一步。q_learning最后一步的target直接就是最后的reward 数值,没有经过neural network。所以感觉不一样

@yywe
Copy link
Author

yywe commented May 26, 2020

关于(1), 有更多的指教吗,就是说, 如果像dqn那样选最大的,会又啥问题??

另外,policy gradient这类算法一般是on-policy的。value-based一般是off policy训练。但是td error本身一般都是用在off policy方法上。
这里coma其实是分两部分,eval部分是on policy 的policy gradient, 只是advantage是用critic网络来估计的,而且这个critic网络是用td_error来优化的。
所以这里算是actor critic, actor critic本身算法 policy based 跟value based的一个组合。
所以这里对critic 我不太理解为啥不能用dqn那样选择.

多谢!🙏

@starry-sky6688
Copy link
Owner

最后一步真实,u_next是填充,但是由于terminated的存在,计算q_target时会抹掉u_next对应的Q值,只剩下r。

COMA的Critic也需要是on-policy来更新,更新actor的advantage需要服从策略对应的分布,而advantage是critic计算出来的。

@yywe
Copy link
Author

yywe commented May 27, 2020

豁然开朗,非常感谢。
忽视了td lambda target

@yywe yywe closed this as completed May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants