BDS 761: Diagram Flashcards¶

Flashcards Index¶

  1. Reading the Notation · slides
  2. Single Neurons · slides
  3. Linear and Nonlinear Layers · slides
  4. Scalar and Vector Diagrams · slides
  5. Composition and Deep Networks · slides

Reading the Notation¶

Sources: BDS761_06_AutoDiff_02_MatrixCalculus

Question 1¶

Draw the diagram for $y=3x$.

Answer 1¶

x to y with weight 3

Question 2¶

three inputs with weights into a sum node

Write $y$ as a sum and as $\mathbf a^T\mathbf x$. What is the mapping?

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¶

four unlabeled arrows into a sum node

Question 4¶

Draw the diagram for $f(\mathbf x)=x_1-x_3$, with $\mathbf x\in\mathbb R^3$.

Answer 4¶

x1 and x3 into a sum node, x2 without an arrow

Question 5¶

vector x into box f, vector y out

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.

Single Neurons¶

Sources: BDS761_06_AutoDiff_02_MatrixCalculus

Question 1¶

Draw the diagram for $f(\mathbf x)=2x_1-x_2+5$.

Answer 1¶

affine neuron with bias 5

Question 2¶

affine neuron with two weighted inputs and a bias

Write $y=\mathbf a^T\mathbf x+b$. What are $\mathbf a$ and $b$?

Answer 2¶

$y=\tfrac12x_1-2x_2-1$, so $\mathbf a=\big(\tfrac12,-2\big)^T$ and $b=-1$.

Question 3¶

affine neuron with two weighted inputs and a bias

Compute $y$ for $\mathbf x=(2,1)^T$.

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¶

sum node, then sigma node

Question 5¶

sum node, then ReLU node

Write $y$ as a function of $\mathbf x$. What is the mapping?

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$

Linear and Nonlinear Layers¶

Sources: BDS761_06_AutoDiff_02_MatrixCalculus

Question 1¶

Draw the diagram for $f(x)=\begin{pmatrix}2x\\ -x\end{pmatrix}$.

Answer 1¶

x to y1 with weight 2 and to y2 with weight -1

Question 2¶

two inputs, two sum nodes, four weights

Write $\mathbf y=\mathbf W\mathbf x$. What is $\mathbf W$?

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¶

three inputs, two sum nodes, four arrows

Question 4¶

three inputs, two sum nodes with biases

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¶

three parallel weighted arrows

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¶

two sum nodes with biases, each followed by a sigma node

Question 7¶

two inputs u, three sum nodes v

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.

Scalar and Vector Diagrams¶

Sources: BDS761_06_AutoDiff_02_MatrixCalculus

Question 1¶

three inputs, two sum nodes with biases

Redraw this layer as a vector diagram (single vector input and output).

Answer 1¶

vector x into box Wx+b, vector y out

Question 2¶

vector x into box sigma(Wx+b), vector h out

Redraw this layer as a scalar diagram. How many weights and biases does it have?

Answer 2¶

two inputs, three sum nodes with biases and sigma nodes

6 weights, $\mathbf W\in\mathbb R^{3\times2}$, and 3 biases.

Question 3¶

three separate sigma nodes

Redraw this as a vector diagram.

Answer 3¶

vector z into box sigma, vector y out

Composition and Deep Networks¶

Sources: BDS761_06_AutoDiff_02_MatrixCalculus

Question 1¶

Draw the diagram for $h=2x$ followed by $y=3h$. Which single weight takes $x$ to $y$?

Answer 1¶

x to h with weight 2, h to y with weight 3

$y=6x$: weights multiply along a path.

Question 2¶

two stacked linear layers

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¶

three boxes in a chain

$\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¶

chain of boxes f1, f2, f3, loss

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 $$