diff --git a/minitorch/operators.py b/minitorch/operators.py index 35b5a15..895408d 100644 --- a/minitorch/operators.py +++ b/minitorch/operators.py @@ -74,7 +74,7 @@ def sigmoid(x: float) -> float: for stability. """ # TODO: Implement for Task 0.1. - raise NotImplementedError("Need to implement for Task 0.1") + return (1.0 / (1.0 + math.exp(-x))) if x >= 0 else math.exp(x) / (1 + math.exp(x)) def relu(x: float) -> float: @@ -103,7 +103,7 @@ def exp(x: float) -> float: def log_back(x: float, d: float) -> float: r"If $f = log$ as above, compute $d \times f'(x)$" # TODO: Implement for Task 0.1. - raise NotImplementedError("Need to implement for Task 0.1") + return d / x def inv(x: float) -> float: @@ -116,7 +116,7 @@ def inv(x: float) -> float: def inv_back(x: float, d: float) -> float: r"If $f(x) = 1/x$ compute $d \times f'(x)$" # TODO: Implement for Task 0.1. - raise NotImplementedError("Need to implement for Task 0.1") + return -(x ** (-2)) * d def relu_back(x: float, d: float) -> float: