コード例 #1
0
    def __call__(self, *args, **kwargs):
        arg0 = args[0]

        out = self.__creator__(-arg0.value)
        out.graph = GraphPartial([arg0], self.name, out, lambda g, a0: (-g, ))

        return out
コード例 #2
0
    def __call__(self, *args, **kwargs):
        arg0 = args[0]

        out = self.__creator__(np.log(arg0.value))
        out.graph = GraphPartial([arg0], self.name, out, self.grad_fn)

        return out
コード例 #3
0
    def __call__(self, *args, **kwargs):
        arg0 = args[0]

        out = self.__creator__(np.exp(arg0.value))
        out.graph = GraphPartial([arg0], self.name, out,
                                 lambda g, a0: self.grad_fn(g, a0, out.value))

        return out
コード例 #4
0
    def __call__(self, *args, **kwargs):
        arg0 = args[0]

        v = arg0.value
        out = self.__creator__(1 / (1 + np.exp(-v)))
        out.graph = GraphPartial([arg0], self.name, out, self.grad_fn)

        return out
コード例 #5
0
    def __call__(self, *args, **kwargs):
        arg0 = args[0]
        arg1 = args[1]

        out = self.__creator__(np.matmul(arg0.value, arg1.value))
        out.graph = GraphPartial([arg0, arg1], self.name, out, self.grad_fn)

        return out
コード例 #6
0
    def __call__(self, *args, **kwargs):
        arg0 = args[0]

        out = self.__creator__(np.sqrt(arg0.value))
        out.graph = GraphPartial([arg0], self.name, out, lambda g, a0:
                                 (g * 0.5 * a0**-0.5))

        return out
コード例 #7
0
    def __call__(self, *args, **kwargs):
        arg0 = args[0]
        arg1 = args[1]

        out = self.__creator__(arg0.value - arg1.value)
        out.graph = GraphPartial([arg0, arg1], self.name, out,
                                 lambda g, a0, a1: (g, -g))

        return out
コード例 #8
0
    def __call__(self, *args, **kwargs):
        arg0 = args[0]
        axis = kwargs.get('axis', None)

        out = self.__creator__(np.transpose(arg0.value, axis))
        out.graph = GraphPartial([arg0], self.name, out,
                                 lambda g, a0: self.grad_fn(g, a0, axis))

        return out
コード例 #9
0
    def __call__(self, *args, **kwargs):
        arg0 = args[0]
        axis = kwargs.get('axis', 0) or 0

        out = self.__creator__(arg0.value.sum(axis))
        out.graph = GraphPartial(
            [arg0], self.name, out,
            lambda g, a0: self.grad_fn(g, a0, arg0.value.shape[axis]))

        return out
コード例 #10
0
    def __call__(self, *args, **kwargs):
        arg0 = args[0]

        v = arg0.value
        # mask =np.ma.masked_less_equal(v, 0)
        mask = np.ma.masked_greater(v, 0)
        v[v <= 0] = 0
        out = self.__creator__(v)
        out.graph = GraphPartial([arg0], self.name, out,
                                 lambda g, a0: self.grad_fn(g, a0, mask))

        return out
コード例 #11
0
    def __call__(self, *args, **kwargs):
        arg0 = args[0]
        idx = args[1]

        out = self.__creator__(arg0.value[idx])

        if isinstance(idx, list) and (len(idx) == 0
                                      or not isinstance(idx[0], slice)):
            idx = np.array(idx, dtype='int64')

        out.graph = GraphPartial([arg0], self.name, out,
                                 lambda g, a0: self.grad_fn(g, a0, idx))

        return out