Key Word(s): Forwward mode, Reverse mode
Exercise 1¶
Consider the function \begin{align*} f\left(x,y\right) = \begin{bmatrix} x^{2} + y^{2} \\ e^{x+y} \end{bmatrix} . \end{align*}
Part A¶
Calculate the Jacobian by hand and evaluate it at the point $\left(1,1\right)$.
Part B¶
Calculate $J_{p}$ ($J$ evaluated at $p$) for:
i.) $$p = \begin{bmatrix}1 \\ -2\end{bmatrix}$$ ii.) $$p = \begin{bmatrix}1 \\ 1\end{bmatrix}$$
Part C¶
Repeat Part B using the evaluation trace provided below. Take note of how the seed vectors enter the process! Compare the end of the AD process with the results from Part B.
Note: $x_1$ and $x_2$ represent x and y respectively.
Deliverables¶
There are different options for submitting this exercise. You can choose whichever you prefer.
- Take a picture of your work and submit work as a
.png
file. - Write everything up in Latex.
- Write everything up in Markdown / Latex. Make sure it renders in a Jupyter notebook cell.
Exercise 2¶
Write a code to do forward mode on the function $$f\left(x\right) = x^{r}$$ where $r\in\mathbb{R}$. Test your implementation by evaluating the derivative and function at the point $x = 3$ for $r=4$.
You have broad freedom on how you implement this. Here are some options:
- Write a function called
my_pow
that returns a datastructure (e.g.list
ortuple
or something else) containing $f\left(3\right)$ and $f^{\prime}\left(3\right)$. This is the simplest approach but it's also the least reusable. - Implement with a closure. The outer function will take in the value of $r$. The inner function will take in a datastructure representing the point to evaluate the function at and the seed for the derivative.
- Implement with a class. Overload the
__pow__
method to accomplish your goals!
The goal of this exercise is for you to start thinking about how you would go about implementing some elemental functions for your final project.
Deliverables¶
exercise_2.py
- Contains your code
- Contains a demo inside ablock.
if __name__ == "__main__":