joddiy commented on a change in pull request #489: SINGA-474 selu operator URL: https://github.com/apache/incubator-singa/pull/489#discussion_r309771204
########## 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) Review comment: can optimize: ``` singa.MultFloat(singa.SubFloat(singa.Exp(x1), 1.0), self.alpha * self.gamma) ``` ---------------------------------------------------------------- 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