Decision Boundaries

This ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍warmup ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍assignment ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍continues ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍our ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍development ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍of ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍the ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍idea ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍of ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍decision ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍boundaries ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍in ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍a ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍more ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍advanced ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍and ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍generalizable ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍way.

Part A

Sketch ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍the ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍line ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍in ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍\(\R^2\) ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍described ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍by ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍the ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍equation ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍\[ \bracket{\vw, \vx} = b\;, \tag{1}\]

where ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍\(\vw = \paren{1, -\frac{1}{2}}^T \in \R^2\) ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍and ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍\(b = \frac{1}{2}\). ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍Here, ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍\(\bracket{\vw, \vx} = \sum_{i = 1}^p w_i x_i\) ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍is ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍the ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍inner ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍product ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍(or ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍dot ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍product) ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍between ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍the ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍vectors ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍\(\vw,\vx \in \R^p\).

Part B

You can create numpy arrays like this: x = np.array([0.2, 4.3]). The syntax x@w can also be used as a convenient shorthand for np.dot(x, w).

Write ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍a ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍quick ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍Python ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍function ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍called ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍linear_classify(x, w, b). ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍w ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍and ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍x ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍should ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍both ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍be ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍1d ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍numpy ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍arrays ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍of ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍the ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍same ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍length, ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍and ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍b ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍should ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍be ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍a ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍scalar. ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍The ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍function ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍np.dot(x, w) ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍will ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍compute ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍the ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍inner ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍product ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍of ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍x ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍and ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍w. ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍Argument ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍b ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍should ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍be ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍a ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍scalar ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍number. ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍Your ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍function ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍should ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍return ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍0 ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍if ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍if ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍\(\bracket{\vw, \vx} < b\) ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍and ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍1 ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍if ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍\(\bracket{\vw, \vx} \geq b\).

Verify ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍that ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍your ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍function ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍works ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍on ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍a ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍few ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍simple ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍examples.

Part C

The function \(\phi\) is an example of a feature ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍map, which we will discuss soon.

Let ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍\(\phi:\mathbb{R}^2\rightarrow \mathbb{R}^5\) ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍be ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍the ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍function

\[ \phi(\mathbf{x}) = \phi(x_1, x_2) = (x_1, x_2, x_1^2, x_2^2, x_1x_2)^T\;. \]

Make ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍a ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍sketch ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍of ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍the ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍curve ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍in ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍\(\R^2_+\) ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍(the ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍nonnegative ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍quadrant) ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍defined ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍by ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍the ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍equation

\[ \bracket{\vw, \phi(\vx)} = b\;, \]

where ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍\(\vw = (0, 0, 1, \frac{1}{4}, 0)^T\) ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍and ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍\(b = 1\).

Part D (optional)

Write ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍a ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍Python ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍function ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍called ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍quadratic_classify(x, w, b). ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍w ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍should ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍be ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍a ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍1d ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍numpy ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍array, ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍this ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍time ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍of ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍length ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍5. ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍x ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍should ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍still ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍have ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍length ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍2, ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍and ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍b ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍should ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍still ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍be ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍a ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍scalar. ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍Your ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍function ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍should ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍return ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍0 ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍if ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍if ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍\(\bracket{\vw, \phi(\vx)} < b\) ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍and ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍1 ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍if ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍\(\bracket{\vw, \phi(\vx)} \geq b\).



© Phil Chodrow, 2025