singa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-singa] joddiy commented on a change in pull request #489: SINGA-474 selu operator
Date Thu, 01 Aug 2019 15:59:16 GMT
joddiy commented on a change in pull request #489: SINGA-474 selu operator
URL: https://github.com/apache/incubator-singa/pull/489#discussion_r309770208
 
 

 ##########
 File path: python/singa/autograd.py
 ##########
 @@ -357,6 +357,52 @@ def backward(self, dy):
 def relu(x):
     return ReLU()(x)[0]
 
+class SeLU(Operation):
+    def __init__(self,alpha=1.67326,gamma=1.0507):
+        super(SeLU, self).__init__()
+        self.alpha=alpha
+        self.gamma=gamma
+
+    def forward(self, x):
+        """Do forward propgation.
+        Store the x if x requires gradient.
+        Args:
+            x (CTensor): matrix
+        Returns:
+            a CTensor for the result
+        """
+        #y = gamma * (alpha * e^x - alpha) for x <= 0, y = gamma * x for x > 0
+        if training:
+            self.input = x
+        x1 = singa.LTFloat(x, 0.0)
+        x1 = singa.__mul__(x, x1)
+        x1 = singa.MultFloat(singa.SubFloat(singa.MultFloat(singa.Exp(x1),self.alpha),self.alpha),self.gamma)
+        x2 = singa.ReLU(x)
+        x2 = singa.MultFloat(x2,self.gamma)
+        x1 = singa.__add__(x1, x2)
+        return x1
+
+    def backward(self, dy):
+        """
+        Args:
+            dy (CTensor): data for the dL / dy, L is the loss
+        Returns:
+            dx
+        """
+        dx1mask = singa.LTFloat(self.input, 0.0)
 
 Review comment:
   should by LEFloat

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message