コード例 #1
0
def sigmoid(self):
    out = Value(math.e**self / (math.e**self + 1), (self, ), f'sigmoid')

    def _backward():
        self.grad += math.e**self / ((math.e**self + 1) * (math.e**self + 1))

    out._backward = _backward

    return out
コード例 #2
0
def log(self, **kwargs):
    out = Value(math.log(self.data), (self, ), f'log')

    def _backward():
        self.grad += 1 / self.data * out.grad

    out._backward = _backward

    return out
コード例 #3
0
def __pow__(self, other):
    other = other if isinstance(other, Value) else Value(other)
    out = Value(self.data**other.data, (self, other), f'pow')

    def _backward():
        self.grad += (other.data * self.data**(other.data - 1)) * out.grad
        if other.data != 0:
            other.grad += (self.data**other.data) * math.log(abs(
                other.data)) * out.grad

    out._backward = _backward

    return out