joddiy commented on a change in pull request #494: SINGA-475 add SoftPlus
operator
URL: https://github.com/apache/incubator-singa/pull/494#discussion_r309598220
##########
File path: python/singa/autograd.py
##########
@@ -1828,3 +1828,27 @@ def backward(self, dy):
def leakyrelu(x, a=0.01):
return LeakyRelu(a)(x)[0]
+
+
+class SoftPlus(Operation):
+ def __init__(self):
+ super(SoftPlus, self).__init__()
+
+ def forward(self, x):
+ #f(x) = ln(exp(x) + 1)
+ if training:
+ self.input = x
+ x1 = singa.AddFloat(singa.Exp(x),1.0)
+ y = singa.Log(x1)
+
+ return y
+
+ def backward(self, dy):
+ dx = singa.AddFloat(singa.Exp(self.input),1.0)
Review comment:
please use the formula: dx = 1 / (1 + exp(-x)). Your implement here has to
compute the exp(x) twice.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services