Skip to content

Commit

Permalink
Merge pull request #12 from dantp-ai/solution/task-1-1
Browse files Browse the repository at this point in the history
Implement approx to derivative of f wrt to arg using central diff approx
  • Loading branch information
dantp-ai authored Mar 20, 2024
2 parents b41dc13 + 13048eb commit 1b9cfe1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions minitorch/autodiff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Any, Iterable, List, Tuple # noqa: F401
from typing import Any, Iterable, Tuple

from typing_extensions import Protocol

Expand All @@ -22,8 +22,10 @@ def central_difference(f: Any, *vals: Any, arg: int = 0, epsilon: float = 1e-6)
Returns:
An approximation of $f'_i(x_0, \ldots, x_{n-1})$
"""
# TODO: Implement for Task 1.1.
raise NotImplementedError("Need to implement for Task 1.1")
return (
f(*[v + epsilon if i == arg else v for i, v in enumerate(vals)])
- f(*[v - epsilon if i == arg else v for i, v in enumerate(vals)])
) / (2 * epsilon)


variable_count = 1
Expand Down

0 comments on commit 1b9cfe1

Please sign in to comment.