From dev-return-3101-archive-asf-public=cust-asf.ponee.io@singa.incubator.apache.org Thu Aug 1 13:38:15 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 270A2180644 for ; Thu, 1 Aug 2019 15:38:15 +0200 (CEST) Received: (qmail 66068 invoked by uid 500); 1 Aug 2019 13:38:14 -0000 Mailing-List: contact dev-help@singa.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@singa.incubator.apache.org Delivered-To: mailing list dev@singa.incubator.apache.org Received: (qmail 66058 invoked by uid 99); 1 Aug 2019 13:38:14 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Aug 2019 13:38:14 +0000 From: GitBox To: dev@singa.apache.org Subject: [GitHub] [incubator-singa] joddiy commented on a change in pull request #482: SINGA-474 hardsigmoid operator Message-ID: <156466669445.21556.4928348876746215924.gitbox@gitbox.apache.org> Date: Thu, 01 Aug 2019 13:38:14 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit joddiy commented on a change in pull request #482: SINGA-474 hardsigmoid operator URL: https://github.com/apache/incubator-singa/pull/482#discussion_r309685974 ########## 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: can we write like this? ``` x = singa.AddFloat(singa.MultFloat(x, self.alpha), self.gamma) x = singa.__clamp__(x, 0.0, 1.0) ``` ---------------------------------------------------------------- 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