Skip to the content.

Deep Learning - Week 2 Lecture Notes

This is my notes for Deep Learning Course in Coursera. I jumped straight to week 2 because week 1 is about introduction that I’ve known. Week 2 in summary is structured as: starting from binary classification with logistic regression, loss function and cost function, computational graph.

Binary Classification

in image classification you will have to process and image that would most probably consists of RGB image.

Notation

$m$ training example denoted by

Logistic Regression

Given x, want $\hat y = P (y=1 \mid x)$

output $\hat y = \sigma(w^{T}x + b)$

sigmoid function with input variable z definition:

Logistic Regression Cost Function

Usually we use loss function as follow

but this is non-convex function, so no single solution exists. We need to find another loss function for logistic regression!

Cost function

Gradient Descent

for training or learning how to get logistic regression parameters.

Repeat
w := w - \alpha dJ(w) / dw

where $\alpha$ is the learning rate

Computation Graph

Computation graph explains the use of backpropagation mechanism. Backward function computes the gradient of a cost function. Backpropagation distribute/propagate the gradient of a cost function to all the layers before.

assume we have function $J(a,b,c) = 3(a + bc)$, then we further define:

$u = bc$

$v = a + u$

$J = 3v$

graph LR B[b=3] --> U[u=bc -> 6] C[c=2] --> U A[a=5] --> V[v=a+u -> 11] U --> V V --> J[J=3v -> 33]

then we want to optimize function $J$, which in the past lectures, $J$ is the cost function. Remember the difference between cost function and loss function: cost funtion is the average of loss function, while loss function is the single instance loss or error made by our prediction.

Since we have this graph, now one of the question that we would like to answer is

how much of $J$ value change if we change $a$

from $J = 3v$ we know that:

now we wanted to answer $\frac{dJ}{da} = ?$

we know that $a$ affect $v$ and $v$ affect $J$

graph LR A[a] --> V[v] V --> J[J]

so following the chain rule:

we have $\frac{dJ}{dv} = 3$ and $\frac{dv}{da} = 1$ (this from calculus derivative, for more practical explanation please see the lecture video). Then we got:

What does this means? it means if we change the value of $a$ by some number, it would change the final function $J$ in magnitude of 3. Say if we change the value of $a$ to $5.0001$, then $v = 11.001$ and $J = 33.003$.

Incorporating Computation Graph Into Logistic Regression

we have

then we can construct computation graph as follow

graph LR X1[x1] --> Z[z=w1 x1 + w2 x2 + b] W1[w1] --> Z X2[x2] --> Z W1[w2] --> Z B[b] --> Z Z --> Y[yhat = σ of z] Y --> L[L yhat, y]

so we got (like Andrew Ng said: don’t worry about the calculus now)

then we can update weights as follow:

where $\alpha$ is the learning rate that we set. Well this all is for single training set, if we wanted to calculate, say $w1$ from overall cost function, where:

then

Written on January 5, 2019