Math for AI course · Lesson 37 of 180
How Affine Spaces Explain Bias and Decision Boundaries
See how a translation moves a line without changing its direction, and why a neural layer bias can move a classifier boundary away from the origin.
A classifier’s weights decide which direction separates two classes. Its bias lets the separating line sit somewhere other than the origin. That small addition is a geometric translation: it changes a linear boundary into an affine one while keeping the boundary’s direction fixed.
By the end, you will be able to distinguish a translated subspace from a subspace through the origin, test whether a mapping is linear or affine, and calculate how a bias changes a simple classifier’s boundary.
Learning outcome: Distinguish linear and affine sets and transformations.
This builds on Lesson 034, which showed that linear mappings preserve vector sums and scaling. Section 2.8 of Mathematics for Machine Learning extends that structure with offsets. The examples, classifier calculation, visual, and assessments here are original.
A line can keep its direction and move away from zero
A vector subspace must contain the zero vector. For example, all multiples of form a line through the origin:
Choose a point and add it to every vector in . The resulting set is a parallel line that no longer passes through the origin:
For this line, the parametric coordinates are . Eliminating gives . The direction vector is unchanged from , but every point on has moved by . In particular, : making the first coordinate zero forces , which leaves the second coordinate at . When the chosen point is in , the translate equals ; that is the special case where the affine subspace is also a vector subspace.
- No bias: 2x₁ − x₂ = 0
- Bias −1: 2x₁ − x₂ = 1
The two lines in the figure have the same direction vector , since it is perpendicular to their shared normal vector . The dashed line is a translation of the solid one. Its position changes, but its orientation does not. The labels and equations give the same information without relying on the colors.
Affine combinations preserve points in an offset set
A useful way to recognize affine geometry is to combine points with coefficients that sum to one. If and are in , then for any real number ,
The offset remains because , and the part in parentheses remains in because subspaces are closed under linear combinations. This is why points on a line stay on that line under interpolation, including extrapolation when is outside .
Ordinary sums have a different coefficient total. For , , which need not be in . With the example line, and give , which fails the line equation . So an affine subspace keeps affine combinations, while a vector subspace keeps all linear combinations and includes zero.
A chosen anchor is not unique. If , then because adding an element of only changes which point is used as the anchor. The direction space is the invariant part; the support point is one convenient representative.
A bias moves a classifier boundary
An affine mapping combines a linear map with a fixed translation:
For any two inputs, the translation cancels from their difference:
And for coefficients that add to one, the output respects their affine combination:
This differs from the linear-map rule for arbitrary sums. In particular, , so a nonzero bias moves the zero input away from the zero output.
Let be a two-feature input. Its score is
It assigns the positive class when and the negative class when . The decision boundary is where the score is zero:
The weight vector sets the boundary’s normal, while the bias sets the score level at . In two dimensions the boundary is a line; in higher-dimensional feature spaces, the corresponding flat set is called a hyperplane. The point is on it because . Adding the direction $d=(1,2) does not change the score:
Without the bias, the boundary would be and would contain the
origin. Adding changes its intercept, not its normal vector. More broadly,
a classifier score uses to orient a hyperplane and to
set its offset. PyTorch’s torch.nn.Linear documents this affine form as
and enables its learnable bias by default
(torch.nn.Linear documentation).
With one output, the layer can produce a score of this form; a following rule
such as thresholding that score assigns the class.
The bias moves a boundary parallel to itself only while the weights stay fixed. If training changes , it changes the orientation too. A bias also cannot make one affine boundary represent every possible classification pattern; it only adjusts the offset of this particular linear score.
Verify the geometry with NumPy
The example can be checked directly. The code computes the scores at the support point and two points reached by moving along the direction:
import numpy as np
w = np.array([2.0, -1.0])
b = -1.0
p = np.array([0.0, -1.0])
d = np.array([1.0, 2.0])
score = lambda x: w @ x + b
print(score(p)) # 0.0: p is on the boundary
print(score(p + d)) # 0.0: moving along d stays on it
print(score(p + 3 * d)) # 0.0: extrapolating along d also stays on it
print(score(np.zeros(2))) # -1.0: the origin is off the boundary
The calculations use column-vector geometry, while common tensor batches store
examples in rows. PyTorch writes its batched linear layer as ;
the transpose accounts for that row-oriented convention. With its default
bias, the operation is affine. Setting bias=False makes the layer’s mapping
linear, though a later nonlinear activation is a separate operation.
Check your understanding
Question 1
For U = span((1, 2)) and p = (0, −1), write p + U parametrically and state whether it contains the origin.
Show the step-by-step solution
Every point has the form for some and direction vector . Therefore . To reach the origin, the first coordinate requires , but then the second coordinate is . Thus the set does not contain the origin and is not a vector subspace.
Question 2
A line is given by (x₁, x₂) = (3, 1) + t(2, −1). Give one anchor and its direction space. Is the anchor unique?
Show the step-by-step solution
The displayed anchor is and the direction space is . If is any vector in , then , so another point on the line can serve as an anchor. The direction space does not change.
Question 3
Show that an affine subspace is closed under combinations λx + (1 − λ)y, even when λ is outside 0 to 1.
Show the step-by-step solution
Write and with . Then . The coefficients of sum to one, and the remaining vector is in by closure under linear combinations. This holds for every real ; values outside extrapolate beyond the segment but stay on the same affine subspace.
Question 4
For the affine line L = (0, −1) + span((1, 2)), test whether (0, −2), the sum of its anchor with itself, lies on L.
Show the step-by-step solution
A point belongs to this line exactly when . Substituting gives , not . Therefore the ordinary sum lies outside . The two copies have coefficient total , so their affine anchor offset is doubled rather than retained once.
Question 5
For F(x) = Ax + b, calculate F(0) and explain the condition for F to be a linear mapping.
Show the step-by-step solution
Substitute the zero vector: . Every linear mapping must map zero to zero, so if , is not linear. When , the rule becomes , which preserves sums and scalar multiples and is linear.
Question 6
For s(x) = 2x₁ − x₂ − 1, verify that p = (0, −1) is on the boundary and that d = (1, 2) follows the boundary direction.
Show the step-by-step solution
At , , so it lies on the zero-score boundary. The change in score when adding is , because the bias is constant and the weight dot direction is zero. Thus remains on the boundary.
Question 7
If a classifier score is wᵀx + b, what does changing b do when w is held fixed? What changes if w also changes during training?
Show the step-by-step solution
The boundary satisfies . Holding fixed keeps the normal vector and orientation fixed; changing changes the level set, translating the boundary. If changes, its normal changes too, so the boundary can rotate as well as move. The bias alone does not control orientation.
Question 8
PyTorch constructs nn.Linear(4, 2) with its default bias option. What is the resulting mapping, and what change would make that layer linear?
Show the step-by-step solution
For a row-oriented input with four features, the layer returns
with two output features. Its default bias=True adds the
learned vector , so it is affine. Constructing it with bias=False removes
that translation and leaves , a linear mapping.