joddiy commented on a change in pull request #482: SINGA-474 hardsigmoid 
operator
URL: https://github.com/apache/incubator-singa/pull/482#discussion_r309671456
 
 

 ##########
 File path: python/singa/autograd.py
 ##########
 @@ -358,6 +358,51 @@ def relu(x):
     return ReLU()(x)[0]
 
 
+class HardSigmoid(Operation):
+    def __init__(self,alpha=0.2,gamma=0.5):
+        super(HardSigmoid, self).__init__()
+        self.alpha=alpha
+        self.gamma=gamma
+
+    def forward(self, x):
+        """Do forward propgation.
+        #y = max(0, min(1, alpha * x + gamma))
+        Args:
+            x (CTensor): matrix
+        Returns:
+            a CTensor for the result
+        """
+        if training:
+            self.input = x
+
+        x = singa.AddFloat(singa.MultFloat(x,self.alpha),self.gamma)
+        x = singa.ReLU(x)
+        mask = singa.LTFloat(x, 1.0)
+        mask2 = singa.GEFloat(x, 1.0)
+
+        ans = singa.__add__(singa.__mul__(x, mask),mask2)
 
 Review comment:
   Please refer to the 
[implement](https://github.com/tensorflow/tensorflow/blob/6e60889d0e31c7ee13004322110eb77507fb2177/tensorflow/python/keras/backend.py#L4379-L4383)
 of Tensorflow.

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


With regards,
Apache Git Services

Reply via email to