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

激活函数Tanh的反向传播 #6

Open
qianchne opened this issue Nov 26, 2020 · 3 comments
Open

激活函数Tanh的反向传播 #6

qianchne opened this issue Nov 26, 2020 · 3 comments

Comments

@qianchne
Copy link

您好,最近阅读了您的这个仓库,受益非浅,非常感谢。
但是我对您在nn/activations.py 中的Tanh的反向传播函数有点疑惑。
def tanh_backward(next_dz):
"""
tanh激活反向过程
:param next_dz:
:return:
"""
return 1 - np.square(np.tanh(next_dz))
根据反向传播的求导,我觉得Tanh的反向函数应该是:
def tanh_backward(next_dz, z):
return next_dz*(1 - np.square(np.tanh(z)))
谢谢您的指教。

@qianchne
Copy link
Author

还有在nn/optimizers.py中我有些疑问:
AdaGrad和RMSProp的权重更新中,
(adagrad)self.s[key] += np.square(layer.weights[key])
(rmsprop)self.s[key] = self.gamma * self.s[key] + (1 - self.gamma) * np.square(layer.weights[key])
我觉得根据定义,应该是:
(adagrad)self.s[key] += np.square(layer.gradients[key])
(rmsprop)self.s[key] = self.gamma * self.s[key] + (1 - self.gamma) * np.square(layer.gradients[key])

@yizt
Copy link
Owner

yizt commented Nov 28, 2020

您好,最近阅读了您的这个仓库,受益非浅,非常感谢。
但是我对您在nn/activations.py 中的Tanh的反向传播函数有点疑惑。
def tanh_backward(next_dz):
"""
tanh激活反向过程
:param next_dz:
:return:
"""
return 1 - np.square(np.tanh(next_dz))
根据反向传播的求导,我觉得Tanh的反向函数应该是:
def tanh_backward(next_dz, z):
return next_dz*(1 - np.square(np.tanh(z)))
谢谢您的指教。

@qianchne 感谢您的反馈,已修正

@yizt
Copy link
Owner

yizt commented Nov 28, 2020

还有在nn/optimizers.py中我有些疑问:
AdaGrad和RMSProp的权重更新中,
(adagrad)self.s[key] += np.square(layer.weights[key])
(rmsprop)self.s[key] = self.gamma * self.s[key] + (1 - self.gamma) * np.square(layer.weights[key])
我觉得根据定义,应该是:
(adagrad)self.s[key] += np.square(layer.gradients[key])
(rmsprop)self.s[key] = self.gamma * self.s[key] + (1 - self.gamma) * np.square(layer.gradients[key])

@qianchne 确实是写错了,感谢您的反馈!

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