Linear decision boundaries (hyperplanes, distance, separability), the perceptron, and logistic regression with the sigmoid, softmax and the cross-entropy loss trained by gradient steps.
Chain for logistic regression: score z=w⋅x→Sigmoid gives a probability → cross-entropy compares it with the label →σ′=σ(z)σ(−z) makes the gradient collapse to (σ(z)−y)x→ gradient step.
Sigmoid vs. softmax:softmax([x,0])=(σ(x),σ(−x)), so two-class softmax regression is logistic regression.
Limits: XOR-like data is not linearly separable, so no linear classifier gets all points right (WS 22/23). The perceptron does not converge there; logistic regression converges to a compromise.
SuccessSolution (not in the exam note; written by Claude, values checked by simulation)
4.1: after object 1 (boundary): w=−1, b=1; objects 2 to 4 are correct; object 5: w=4, b=0; objects 6 to 8 correct. End of round 1: w=4, b=0.
4.2: see the code in Perceptron > Example; the result is w∗=5, b∗=23.
4.3: induction over the update steps; if (wˉi,bˉi)=(−wi,−bi) then the test (−y)(wˉix−bˉi)≤0 is the same as y(wix−bi)≤0, so both runs update at the same steps, and wˉi+1=−wi−yx=−wi+1, bˉi+1=−bi+y=−bi+1. The base case is 0=−0. For the swapped labels the simulation gives (−5,−23).
SuccessSolution
The normal vector is w=(2,−2,1) with ∣w∣=4+4+1=3. dist(x,H)=∣w∣∣w⋅x−b∣ with w⋅x=2−4+3=1, so 3∣1−7∣=2.
Equivalently σ′(t)=1+e−t1⋅1+e−te−t; the first factor is σ(t).
Multiplying the second factor by et/et gives et+11=1+et1=σ(−t).
Hence σ′(t)=σ(t)σ(−t). ■
SuccessSolution
The origin is in H iff w⋅0=b, i.e. iff b=0. Distance: w⋅p=2, ∣w∣=4⋅41=1, so dist(p,H)=1∣2−0∣=2.
SuccessSolution
(⇐) P=R=1 gives F1=2/2=1. (⇒) F1=1 means 1/P+1/R=2; since 0<P,R≤1 we have 1/P≥1 and 1/R≥1, so both equal 1.
XOR-like points: (1,1) and (2,2) in class 0, (2,1) and (1,2) in class 1. F1=1 for both classes needs all points classified correctly, but class 0 sits on one diagonal and class 1 on the other, and no straight line separates them. (Proof by the midpoint argument in Linear Classifier > Properties.)
SuccessSolution
M(x,w)=σ(w∙x) with σ(z)=1+e−z1, and the binary cross-entropy L(y,y′)=−[ylny′+(1−y)ln(1−y′)].
SuccessSolution
defepoch(X: torch.Tensor, y: torch.Tensor, w: torch.Tensor) -> torch.Tensor:
for i in range(X.shape[0]):
xi = X[i] # the i-th input vector, a 1D tensor yi = y[i] # the i-th label, a single float factor =0.1* (yi - torch.sigmoid(torch.dot(xi, w)))
w = w + factor * xi
return w
For cross-entropy loss, the gradient step for one example is w←w+η(yi−σ(w⋅xi))xi with η=0.1; the bracket is the error between label and predicted probability.
SuccessSolution
softmax(x,0)=(ex+e0ex,ex+e0e0)=(ex+1ex,ex+11). Multiplying numerator and denominator of the first component by e−x gives 1+e−x1=σ(x); the second is 1+ex1=σ(−x). So softmax([x,0])=(σ(x),σ(−x)), consistent with σ(x)+σ(−x)=1.
No WS 25/26 lecture covers this topic. Sigmoid, softmax and logistic regression appear in the two WS 23/24 exams, which already include the PyTorch parts that the WS 25/26 course also uses (DBIS_VL11 introduces PyTorch).