BDS 761: Diagram Flashcards¶
Question 1¶
Draw the diagram for $y=3x$.
Answer 1¶
Answer 2¶
$y=2x_1-x_2+4x_3=\mathbf a^T\mathbf x$, with $\mathbf a=(2,-1,4)^T$.
$f:\mathbb R^3\to\mathbb R$
Question 3¶
Draw the diagram for $f(\mathbf x)=x_1+x_2+x_3+x_4$.
Answer 3¶
Question 4¶
Draw the diagram for $f(\mathbf x)=x_1-x_3$, with $\mathbf x\in\mathbb R^3$.
Answer 4¶
Question 5¶
How many scalar inputs and outputs does $f$ have? Write $\mathbf y$ with component functions.
Answer 5¶
Three inputs and two outputs, $f:\mathbb R^3\to\mathbb R^2$: $$ \mathbf y=\begin{pmatrix}f_1(x_1,x_2,x_3)\\ f_2(x_1,x_2,x_3)\end{pmatrix} $$ A thick arrow carries a whole vector; the box stands for both component functions.
Question 1¶
Draw the diagram for $f(\mathbf x)=2x_1-x_2+5$.
Answer 1¶
Answer 2¶
$y=\tfrac12x_1-2x_2-1$, so $\mathbf a=\big(\tfrac12,-2\big)^T$ and $b=-1$.
Answer 3¶
$y=\tfrac12(2)-2(1)-1=-2$
Question 4¶
Draw the diagram for $p=\sigma(x_1+3x_2-2)$. Label the output of the sum $z$.
Answer 4¶
Answer 5¶
$z=x_1-x_2+2x_3+1$
$y=\text{ReLU}(z)=\max(0,\ x_1-x_2+2x_3+1)$, $\quad\mathbb R^3\to\mathbb R$
Question 1¶
Draw the diagram for $f(x)=\begin{pmatrix}2x\\ -x\end{pmatrix}$.
Answer 1¶
Answer 2¶
$$ \mathbf W=\begin{pmatrix}3&-1\\ 2&5\end{pmatrix} $$ Row $i$ holds the weights into $y_i$: $W_{ij}$ is on the arrow from $x_j$ to $y_i$.
Question 3¶
Draw the diagram for $\mathbf y=\mathbf W\mathbf x$, with $\mathbf W=\begin{pmatrix}1&2&0\\ 0&-1&3\end{pmatrix}$.
Answer 3¶
Question 4¶
Write $\mathbf y=\mathbf W\mathbf x+\mathbf b$. Give $\mathbf W$, $\mathbf b$, and their shapes.
Answer 4¶
$$ \mathbf W=\begin{pmatrix}2&-1&1\\ 0&1&4\end{pmatrix}\in\mathbb R^{2\times3},\qquad \mathbf b=\begin{pmatrix}1\\ -3\end{pmatrix}\in\mathbb R^2 $$ The layer maps $\mathbb R^3\to\mathbb R^2$.
Question 5¶
Draw the diagram for $\mathbf y=\text{diag}(2,-1,3)\,\mathbf x$.
Answer 5¶
Question 6¶
Draw the diagram for $\mathbf y=\boldsymbol\sigma(\mathbf W\mathbf x+\mathbf b)$, with $\mathbf W=\begin{pmatrix}1&-2\\ 3&1\end{pmatrix}$ and $\mathbf b=\begin{pmatrix}1\\ -1\end{pmatrix}$. Label the sums $z_1,z_2$.
Answer 6¶
Question 7¶
Write $\mathbf v=\mathbf M\mathbf u$. How is $\mathbf M$ related to $\mathbf W=\begin{pmatrix}1&2&0\\ 0&-1&3\end{pmatrix}$?
Answer 7¶
$$ \mathbf M=\begin{pmatrix}1&0\\ 2&-1\\ 0&3\end{pmatrix}=\mathbf W^T $$ This is the diagram of $\mathbf W$ with every arrow reversed. Backpropagation sends gradients back through a layer this way.
Answer 1¶
Answer 3¶
Question 1¶
Draw the diagram for $h=2x$ followed by $y=3h$. Which single weight takes $x$ to $y$?
Question 2¶
Write $\mathbf y=\mathbf M\mathbf x$. Find $\mathbf M$ by adding up the products of the weights along each path.
Answer 2¶
$$ \mathbf M=\mathbf W_2\mathbf W_1=\begin{pmatrix}1&0\\ -1&3\end{pmatrix}\begin{pmatrix}1&2\\ 0&1\end{pmatrix}=\begin{pmatrix}1&2\\ -1&1\end{pmatrix} $$ For example, $M_{22}$ has two paths: $x_2\to h_1\to y_2$ gives $2\cdot(-1)$ and $x_2\to h_2\to y_2$ gives $1\cdot3$, so $M_{22}=1$. Without an activation layer, two linear layers are equivalent to one.
Question 3¶
Draw the vector diagram for
$$ \mathbf h_1=\text{ReLU}(\mathbf W_1\mathbf x+\mathbf b_1),\quad \mathbf h_2=\text{ReLU}(\mathbf W_2\mathbf h_1+\mathbf b_2),\quad \hat{\mathbf y}=\mathbf W_3\mathbf h_2+\mathbf b_3 $$
with $\mathbf x\in\mathbb R^4$, $\mathbf h_1,\mathbf h_2\in\mathbb R^8$, $\hat{\mathbf y}\in\mathbb R^3$. What are the shapes of $\mathbf W_1,\mathbf W_2,\mathbf W_3$?
Answer 3¶
$\mathbf W_1\in\mathbb R^{8\times4}$, $\ \mathbf W_2\in\mathbb R^{8\times8}$, $\ \mathbf W_3\in\mathbb R^{3\times8}$
Question 4¶
Write $L$ as a composition. What is the shape of each Jacobian in the chain rule for $\dfrac{dL}{d\mathbf x}$?
Answer 4¶
$L=\ell\big(f_3(f_2(f_1(\mathbf x)))\big)$
$$ \frac{dL}{d\mathbf x}=\frac{d\ell}{d\mathbf h_3}\,\frac{d\mathbf h_3}{d\mathbf h_2}\,\frac{d\mathbf h_2}{d\mathbf h_1}\,\frac{d\mathbf h_1}{d\mathbf x}:\qquad(1\times2)(2\times3)(3\times4)(4\times5)\to1\times5 $$