Skip to content

Lecture 2: Logistic Regression, Artificial Neuron, MLP ​

Logistic Regression = One Neuron ​

z=w⊤x+b,y^=σ(z)=11+e−z=P(y=1∣x)

Binary Cross-Entropy Loss ​

J=−1m∑i=1m(y(i)log⁡y^(i)+(1−y(i))log⁡(1−y^(i)))

The loss is convex in y^.

Gradient Descent ​

w←w−α∂J∂w,b←b−α∂J∂b

Back-propagation ​

Purpose

Compute the gradient of the loss with respect to every parameter (∂J/∂w, ∂J/∂b). Gradient descent needs these to know which direction to move each parameter and by how much.

Order: Forward → Backward → Update

① Forward: input → loss. Compute the prediction and the loss, and cache the intermediate values (z, y^).

x→z=w⊤x+b→y^=σ(z)→J=L(y^,y)

② Backward: loss → input. Apply the chain rule in reverse, reusing the cached values.

∂J∂y^→∂J∂z=y^−y→∂J∂w=(y^−y)x,∂J∂b=y^−y

③ Update: apply gradient descent with these gradients.

Why forward first?

Every factor in the backward pass (y^, σ′(z), x) is a value computed during the forward pass.

MLP ​

① Forward: x→h→y^→J

h=σ(W1x+b1),y^=σ(W2h+b2),J=12(y^−y)2

② Backward: J→ output layer → hidden layer

  1. Output layer error, then W2:

    δ2=(y^−y)y^(1−y^),∂J∂W2=δ2h
  2. Hidden layer: pass the error back through W2, then compute W1:

    δ1=δ2W2h(1−h),∂J∂W1=δ1x

Why output layer first?

The hidden-layer gradient reuses δ2. Each layer's error is computed once and passed back to the layer before it, so no chain-rule product is recomputed.

③ Update: batch gradient descent. Sum the gradients over all m samples, then update W1,W2,b1,b2.

Terminology ​

TermMeaning
Batcha subset of the training set
Iterationone batch passed forward and backward
Epochthe whole dataset passed forward and backward once