diff --git a/micrograd/engine.py b/micrograd/engine.py index afd82cc5..2f2d68c7 100644 --- a/micrograd/engine.py +++ b/micrograd/engine.py @@ -1,3 +1,4 @@ +import math class Value: """ stores a single scalar value and its gradient """ @@ -42,6 +43,16 @@ def _backward(): return out + def exp(self): + out = Value(math.exp(self.data), (self,), "e") + + def _backward(): + self.grad += math.exp(self.data) * out.grad + + out._backward = _backward + + return out + def relu(self): out = Value(0 if self.data < 0 else self.data, (self,), 'ReLU')