import%20marimo%0A%0A__generated_with%20%3D%20%220.24.0%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20plotly.graph_objects%20as%20go%0A%0A%20%20%20%20return%20go%2C%20mo%2C%20np%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Note%2003%3A%20Hyperplanes%2C%20Half-Spaces%2C%20and%20Separation%20Distance%0A%0A%20%20%20%20%26larr%3B%20Previous%20Note%3A%20%5B02%20Norm%20and%20Metric%5D(02_norm_and_metric.py)%20%7C%20Next%20Note%3A%20%5B04%20Rank-One%20Matrices%5D(04_rank_one_matrices.py)%20%26rarr%3B%0A%0A%20%20%20%20---%0A%0A%20%20%20%20%23%23%20%5Ba%5D%20Why%20do%20you%20need%20to%20know%20these%20concepts%3F%0A%0A%20%20%20%20Hyperplanes%20are%20the%20fundamental%20geometric%20building%20blocks%20of%20linear%20decision%20boundaries%20in%20machine%20learning%2C%20statistics%2C%20and%20optimization.%20Whenever%20a%20model%20splits%20data%20into%20discrete%20categories%20using%20a%20linear%20weighting%20of%20features%2C%20it%20constructs%20a%20hyperplane.%0A%0A%20%20%20%20Mastering%20the%20geometry%20of%20hyperplanes%20allows%20you%20to%3A%0A%0A%20%20%20%201.%20Understand%20how%20linear%20classifiers%20(Perceptrons%2C%20Logistic%20Regression%2C%20Support%20Vector%20Machines)%20partition%20an%20%24n%24-dimensional%20feature%20space%20into%20decision%20regions.%0A%20%20%20%202.%20Compute%20exact%20orthogonal%20distances%20from%20observations%20to%20decision%20boundaries%20to%20evaluate%20prediction%20certainty%20and%20margins.%0A%20%20%20%203.%20Formalize%20the%20concept%20of%20maximum-margin%20classification%2C%20directly%20motivating%20the%20primal%20and%20dual%20formulations%20of%20Support%20Vector%20Machines.%0A%20%20%20%204.%20Quantify%20adversarial%20vulnerability%20by%20calculating%20the%20minimal%20perturbation%20needed%20to%20push%20a%20data%20point%20across%20a%20decision%20threshold%20into%20an%20opposing%20class.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20---%0A%0A%20%20%20%20%23%23%20%5Bb%5D%20Concept%20explanation%20with%20their%20role%20in%20ML%2FAI%2FStats%3F%0A%0A%20%20%20%20%23%23%23%20Definition%20of%20a%20Hyperplane%0A%0A%20%20%20%20An%20affine%20hyperplane%20%24H%24%20in%20%24%5Cmathbb%7BR%7D%5En%24%20is%20an%20%24(n-1)%24-dimensional%20subspace%20shifted%20by%20an%20intercept.%20It%20is%20defined%20algebraically%20as%20the%20set%20of%20all%20points%20%24%5Cmathbf%7Bx%7D%20%5Cin%20%5Cmathbb%7BR%7D%5En%24%20satisfying%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20H%20%3D%20%5C%7B%5Cmathbf%7Bx%7D%20%5Cin%20%5Cmathbb%7BR%7D%5En%20%3A%20%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D%20%2B%20b%20%3D%200%5C%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%3A%0A%20%20%20%20*%20%24%5Cmathbf%7Bw%7D%20%3D%20%5Bw_1%2C%20w_2%2C%20%5Cdots%2C%20w_n%5D%5ET%20%5Cin%20%5Cmathbb%7BR%7D%5En%20%5Csetminus%20%5C%7B%5Cmathbf%7B0%7D%5C%7D%24%20is%20the%20**normal%20vector**%2C%20orthogonal%20to%20every%20directional%20vector%20lying%20within%20the%20hyperplane.%0A%20%20%20%20*%20%24b%20%5Cin%20%5Cmathbb%7BR%7D%24%20is%20the%20**bias**%20or%20**offset**%2C%20determining%20the%20position%20of%20the%20hyperplane%20relative%20to%20the%20origin.%0A%20%20%20%20*%20When%20%24b%20%3D%200%24%2C%20the%20hyperplane%20passes%20directly%20through%20the%20origin%20and%20forms%20an%20%24(n-1)%24-dimensional%20linear%20subspace.%0A%0A%20%20%20%20%23%23%23%20Half-Spaces%0A%0A%20%20%20%20A%20hyperplane%20splits%20%24%5Cmathbb%7BR%7D%5En%24%20into%20two%20closed%2C%20convex%20half-spaces%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20H%5E%2B%20%3D%20%5C%7B%5Cmathbf%7Bx%7D%20%5Cin%20%5Cmathbb%7BR%7D%5En%20%3A%20%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D%20%2B%20b%20%5Cge%200%5C%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20H%5E-%20%3D%20%5C%7B%5Cmathbf%7Bx%7D%20%5Cin%20%5Cmathbb%7BR%7D%5En%20%3A%20%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D%20%2B%20b%20%5Cle%200%5C%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20In%20binary%20classification%2C%20the%20decision%20rule%20assigns%20class%20labels%20according%20to%20the%20sign%20of%20the%20linear%20score%3A%20%24%5Chat%7By%7D%20%3D%20%5Ctext%7Bsgn%7D(%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D%20%2B%20b)%24.%0A%0A%20%20%20%20%23%23%23%20Orthogonal%20Distance%20from%20a%20Point%20to%20a%20Hyperplane%0A%0A%20%20%20%20Let%20%24%5Cmathbf%7Bx%7D_0%20%5Cin%20%5Cmathbb%7BR%7D%5En%24%20be%20an%20arbitrary%20observation%2C%20and%20let%20%24%5Cmathbf%7Bx%7D_p%20%5Cin%20H%24%20be%20its%20orthogonal%20projection%20onto%20%24H%24.%20The%20displacement%20vector%20%24%5Cmathbf%7Bx%7D_0%20-%20%5Cmathbf%7Bx%7D_p%24%20is%20collinear%20with%20the%20unit%20normal%20vector%20%24%5Chat%7B%5Cmathbf%7Bw%7D%7D%20%3D%20%5Cfrac%7B%5Cmathbf%7Bw%7D%7D%7B%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%7D%24%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathbf%7Bx%7D_0%20-%20%5Cmathbf%7Bx%7D_p%20%3D%20d_%7B%5Ctext%7Bsigned%7D%7D%20%5Ccdot%20%5Cfrac%7B%5Cmathbf%7Bw%7D%7D%7B%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Taking%20the%20inner%20product%20of%20both%20sides%20with%20%24%5Cmathbf%7Bw%7D%24%20and%20substituting%20%24%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D_p%20%3D%20-b%24%20gives%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D_0%20-%20%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D_p%20%3D%20d_%7B%5Ctext%7Bsigned%7D%7D%20%5Ccdot%20%5Cfrac%7B%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bw%7D%7D%7B%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%7D%20%3D%20d_%7B%5Ctext%7Bsigned%7D%7D%20%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D_0%20%2B%20b%20%3D%20d_%7B%5Ctext%7Bsigned%7D%7D%20%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Solving%20for%20the%20absolute%20geometric%20Euclidean%20distance%20yields%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20d(%5Cmathbf%7Bx%7D_0%2C%20H)%20%3D%20%5Cfrac%7B%7C%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D_0%20%2B%20b%7C%7D%7B%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%23%23%23%20Distance%20Between%20Two%20Parallel%20Hyperplanes%0A%0A%20%20%20%20Consider%20two%20parallel%20hyperplanes%20sharing%20the%20same%20normal%20vector%20%24%5Cmathbf%7Bw%7D%24%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20P_1%3A%20%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D%20%2B%20b_1%20%3D%200%20%5Cquad%20%5Ctext%7Band%7D%20%5Cquad%20P_2%3A%20%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D%20%2B%20b_2%20%3D%200%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Pick%20any%20point%20%24%5Cmathbf%7Bx%7D_1%20%5Cin%20P_1%24%2C%20so%20%24%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D_1%20%3D%20-b_1%24.%20The%20perpendicular%20distance%20from%20%24%5Cmathbf%7Bx%7D_1%24%20to%20%24P_2%24%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20D%20%3D%20d(%5Cmathbf%7Bx%7D_1%2C%20P_2)%20%3D%20%5Cfrac%7B%7C%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D_1%20%2B%20b_2%7C%7D%7B%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%7D%20%3D%20%5Cfrac%7B%7C-b_1%20%2B%20b_2%7C%7D%7B%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%7D%20%3D%20%5Cfrac%7B%7Cb_2%20-%20b_1%7C%7D%7B%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20This%20separation%20distance%20depends%20purely%20on%20the%20difference%20in%20offsets%20normalized%20by%20the%20Euclidean%20norm%20of%20the%20weight%20vector.%0A%0A%20%20%20%20%23%23%23%20Role%20in%20ML%2C%20AI%2C%20and%20Statistics%0A%0A%20%20%20%20**Support%20Vector%20Machine%20Margins**%3A%20The%20hard-margin%20SVM%20defines%20two%20bounding%20canonical%20hyperplanes%20supporting%20the%20margin%3A%20%24%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D%20%2B%20b%20%3D%201%24%20and%20%24%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D%20%2B%20b%20%3D%20-1%24.%20Applying%20the%20parallel%20hyperplane%20distance%20formula%20yields%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Ctext%7BMargin%7D%20%3D%20%5Cfrac%7B%7C1%20-%20(-1)%7C%7D%7B%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%7D%20%3D%20%5Cfrac%7B2%7D%7B%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Maximizing%20this%20separation%20margin%20is%20equivalent%20to%20minimizing%20%24%5Cfrac%7B1%7D%7B2%7D%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%5E2%24%2C%20establishing%20%24L_2%24%20regularization%20as%20a%20geometric%20imperative.%0A%0A%20%20%20%20**Logistic%20Regression%20Level%20Sets**%3A%20The%20log-odds%20%24%5Cln%20%5Cfrac%7Bp%7D%7B1-p%7D%20%3D%20%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D%20%2B%20b%24%20defines%20a%20continuum%20of%20parallel%20level%20sets.%20The%20decision%20boundary%20%24p%20%3D%200.5%24%20is%20the%20central%20hyperplane%2C%20while%20parallel%20planes%20%24p%20%3D%200.9%24%20or%20%24p%20%3D%200.99%24%20correspond%20to%20confidence%20contours%20whose%20distance%20from%20the%20boundary%20scales%20with%20%24%5Cfrac%7B1%7D%7B%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%7D%24.%0A%0A%20%20%20%20**Adversarial%20Perturbations**%3A%20For%20a%20linear%20decision%20rule%2C%20the%20minimal%20%24L_2%24%20perturbation%20%24%5Cboldsymbol%7B%5Cdelta%7D%24%20required%20to%20flip%20the%20prediction%20of%20an%20input%20%24%5Cmathbf%7Bx%7D_0%24%20is%20the%20vector%20directly%20pointing%20toward%20the%20boundary%3A%20%24%5Cboldsymbol%7B%5Cdelta%7D%5E*%20%3D%20-%20%5Cfrac%7B%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D_0%20%2B%20b%7D%7B%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%5E2%7D%20%5Cmathbf%7Bw%7D%24%2C%20having%20length%20exactly%20equal%20to%20the%20point-to-plane%20distance%20%24d(%5Cmathbf%7Bx%7D_0%2C%20H)%24.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20---%0A%0A%20%20%20%20%23%23%20%5Bc%5D%20Code%20examples%0A%0A%20%20%20%20Below%20are%20two%20practical%20examples%3A%0A%20%20%20%201.%20**Numerical%20Verification**%3A%20Computing%20perpendicular%20distances%20from%20arbitrary%20points%20to%20a%20hyperplane%20and%20calculating%20the%20separation%20distance%20between%20parallel%20planes.%0A%20%20%20%202.%20**Interactive%203D%20Visualization**%3A%20Visualizing%20parallel%20hyperplanes%2C%20their%20shared%20normal%20vector%2C%20and%20the%20orthogonal%20separation%20distance%20with%20Plotly.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20%23%20Example%201%3A%20Analytical%20and%20numerical%20distance%20computation%20in%20R%5E3%0A%20%20%20%20%23%20Hyperplane%201%3A%202x%20%2B%203y%20%2B%204z%20%3D%200%20%20%20%3D%3E%20w%20%3D%20%5B2%2C%203%2C%204%5D%2C%20b1%20%3D%200%0A%20%20%20%20%23%20Hyperplane%202%3A%202x%20%2B%203y%20%2B%204z%20-%2010%20%3D%200%20%3D%3E%20w%20%3D%20%5B2%2C%203%2C%204%5D%2C%20b2%20%3D%20-10%0A%20%20%20%20w%20%3D%20np.array(%5B2.0%2C%203.0%2C%204.0%5D)%0A%20%20%20%20b1%20%3D%200.0%0A%20%20%20%20b2%20%3D%20-10.0%0A%0A%20%20%20%20w_norm%20%3D%20np.linalg.norm(w)%0A%20%20%20%20theoretical_distance%20%3D%20abs(b2%20-%20b1)%20%2F%20w_norm%0A%0A%20%20%20%20%23%20Test%20point%20on%20Plane%201%3A%20x1%20%3D%20%5B0%2C%200%2C%200%5D%20since%202(0)%20%2B%203(0)%20%2B%204(0)%20%2B%200%20%3D%200%0A%20%20%20%20x_on_p1%20%3D%20np.array(%5B0.0%2C%200.0%2C%200.0%5D)%0A%0A%20%20%20%20%23%20Calculate%20distance%20from%20point%20x_on_p1%20to%20Plane%202%0A%20%20%20%20point_distance%20%3D%20abs(np.dot(w%2C%20x_on_p1)%20%2B%20b2)%20%2F%20w_norm%0A%0A%20%20%20%20%23%20Orthogonal%20projection%20of%20x_on_p1%20onto%20Plane%202%0A%20%20%20%20x_proj_on_p2%20%3D%20x_on_p1%20-%20((np.dot(w%2C%20x_on_p1)%20%2B%20b2)%20%2F%20(w_norm**2))%20*%20w%0A%0A%20%20%20%20%23%20Verify%20projected%20point%20lies%20exactly%20on%20Plane%202%3A%20w%20.%20x_proj%20%2B%20b2%20%3D%3D%200%0A%20%20%20%20plane_2_residual%20%3D%20float(np.dot(w%2C%20x_proj_on_p2)%20%2B%20b2)%0A%20%20%20%20euclidean_displacement%20%3D%20float(np.linalg.norm(x_proj_on_p2%20-%20x_on_p1))%0A%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22normal_norm_sqrt29%22%3A%20float(w_norm)%2C%0A%20%20%20%20%20%20%20%20%22theoretical_distance%22%3A%20float(theoretical_distance)%2C%0A%20%20%20%20%20%20%20%20%22point_distance%22%3A%20float(point_distance)%2C%0A%20%20%20%20%20%20%20%20%22projected_point_on_p2%22%3A%20x_proj_on_p2.tolist()%2C%0A%20%20%20%20%20%20%20%20%22plane_2_residual%22%3A%20plane_2_residual%2C%0A%20%20%20%20%20%20%20%20%22euclidean_displacement%22%3A%20euclidean_displacement%0A%20%20%20%20%7D%0A%20%20%20%20return%20b1%2C%20b2%2C%20w%2C%20x_on_p1%2C%20x_proj_on_p2%0A%0A%0A%40app.cell%0Adef%20_(b1%2C%20b2%2C%20go%2C%20np%2C%20w%2C%20x_on_p1%2C%20x_proj_on_p2)%3A%0A%20%20%20%20%23%20Example%202%3A%20Interactive%203D%20Plotly%20Visualization%20of%20Parallel%20Hyperplanes%0A%20%20%20%20%23%20Solving%20for%20z%3A%20w%5B0%5D*x%20%2B%20w%5B1%5D*y%20%2B%20w%5B2%5D*z%20%2B%20b%20%3D%200%20%3D%3E%20z%20%3D%20-(w%5B0%5D*x%20%2B%20w%5B1%5D*y%20%2B%20b)%20%2F%20w%5B2%5D%0A%20%20%20%20x_grid%20%3D%20np.linspace(-4%2C%204%2C%2030)%0A%20%20%20%20y_grid%20%3D%20np.linspace(-4%2C%204%2C%2030)%0A%20%20%20%20X%2C%20Y%20%3D%20np.meshgrid(x_grid%2C%20y_grid)%0A%0A%20%20%20%20Z1%20%3D%20-(w%5B0%5D%20*%20X%20%2B%20w%5B1%5D%20*%20Y%20%2B%20b1)%20%2F%20w%5B2%5D%0A%20%20%20%20Z2%20%3D%20-(w%5B0%5D%20*%20X%20%2B%20w%5B1%5D%20*%20Y%20%2B%20b2)%20%2F%20w%5B2%5D%0A%0A%20%20%20%20fig%20%3D%20go.Figure()%0A%0A%20%20%20%20%23%20Plane%201%3A%202x%20%2B%203y%20%2B%204z%20%3D%200%0A%20%20%20%20fig.add_trace(go.Surface(%0A%20%20%20%20%20%20%20%20x%3DX%2C%0A%20%20%20%20%20%20%20%20y%3DY%2C%0A%20%20%20%20%20%20%20%20z%3DZ1%2C%0A%20%20%20%20%20%20%20%20colorscale%3D%5B%5B0%2C%20%22rgba(31%2C%20119%2C%20180%2C%200.5)%22%5D%2C%20%5B1%2C%20%22rgba(31%2C%20119%2C%20180%2C%200.5)%22%5D%5D%2C%0A%20%20%20%20%20%20%20%20showscale%3DFalse%2C%0A%20%20%20%20%20%20%20%20name%3D%22Plane%201%3A%202x%20%2B%203y%20%2B%204z%20%3D%200%22%0A%20%20%20%20))%0A%0A%20%20%20%20%23%20Plane%202%3A%202x%20%2B%203y%20%2B%204z%20-%2010%20%3D%200%0A%20%20%20%20fig.add_trace(go.Surface(%0A%20%20%20%20%20%20%20%20x%3DX%2C%0A%20%20%20%20%20%20%20%20y%3DY%2C%0A%20%20%20%20%20%20%20%20z%3DZ2%2C%0A%20%20%20%20%20%20%20%20colorscale%3D%5B%5B0%2C%20%22rgba(214%2C%2039%2C%2040%2C%200.5)%22%5D%2C%20%5B1%2C%20%22rgba(214%2C%2039%2C%2040%2C%200.5)%22%5D%5D%2C%0A%20%20%20%20%20%20%20%20showscale%3DFalse%2C%0A%20%20%20%20%20%20%20%20name%3D%22Plane%202%3A%202x%20%2B%203y%20%2B%204z%20%3D%2010%22%0A%20%20%20%20))%0A%0A%20%20%20%20%23%20Normal%20vector%20connecting%20the%20origin%20to%20normal%20direction%0A%20%20%20%20unit_w%20%3D%20w%20%2F%20np.linalg.norm(w)%0A%20%20%20%20fig.add_trace(go.Scatter3d(%0A%20%20%20%20%20%20%20%20x%3D%5Bx_on_p1%5B0%5D%2C%20x_proj_on_p2%5B0%5D%5D%2C%0A%20%20%20%20%20%20%20%20y%3D%5Bx_on_p1%5B1%5D%2C%20x_proj_on_p2%5B1%5D%5D%2C%0A%20%20%20%20%20%20%20%20z%3D%5Bx_on_p1%5B2%5D%2C%20x_proj_on_p2%5B2%5D%5D%2C%0A%20%20%20%20%20%20%20%20mode%3D%22lines%2Bmarkers%22%2C%0A%20%20%20%20%20%20%20%20name%3D%22Separation%20Segment%20(D%20%E2%89%88%201.86)%22%2C%0A%20%20%20%20%20%20%20%20line%3Ddict(color%3D%22%232ca02c%22%2C%20width%3D8)%2C%0A%20%20%20%20%20%20%20%20marker%3Ddict(size%3D5%2C%20color%3D%5B%22%231f77b4%22%2C%20%22%23d62728%22%5D)%0A%20%20%20%20))%0A%0A%20%20%20%20fig.update_layout(%0A%20%20%20%20%20%20%20%20title%3Ddict(%0A%20%20%20%20%20%20%20%20%20%20%20%20text%3D%22Parallel%20Hyperplanes%20in%20R%C2%B3%20and%20Orthogonal%20Separation%20Distance%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20font%3Ddict(size%3D15)%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20scene%3Ddict(%0A%20%20%20%20%20%20%20%20%20%20%20%20xaxis%3Ddict(title%3D%22X%E2%82%81%22%2C%20gridcolor%3D%22%23e5e5e5%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20yaxis%3Ddict(title%3D%22X%E2%82%82%22%2C%20gridcolor%3D%22%23e5e5e5%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20zaxis%3Ddict(title%3D%22X%E2%82%83%22%2C%20gridcolor%3D%22%23e5e5e5%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20camera%3Ddict(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20eye%3Ddict(x%3D1.6%2C%20y%3D1.6%2C%20z%3D1.2)%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20template%3D%22plotly_white%22%2C%0A%20%20%20%20%20%20%20%20width%3D780%2C%0A%20%20%20%20%20%20%20%20height%3D580%2C%0A%20%20%20%20%20%20%20%20margin%3Ddict(l%3D20%2C%20r%3D20%2C%20t%3D50%2C%20b%3D20)%0A%20%20%20%20)%0A%0A%20%20%20%20fig%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20---%0A%0A%20%20%20%20%23%23%20%5Bd%5D%20Takeaway%0A%0A%20%20%20%20*%20**Affine%20Structure**%3A%20A%20hyperplane%20%24%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D%20%2B%20b%20%3D%200%24%20splits%20feature%20space%20into%20two%20half-spaces.%20The%20vector%20%24%5Cmathbf%7Bw%7D%24%20is%20strictly%20perpendicular%20to%20every%20displacement%20within%20the%20plane.%0A%20%20%20%20*%20**Distance%20Formula**%3A%20The%20geometric%20distance%20from%20any%20point%20%24%5Cmathbf%7Bx%7D_0%24%20to%20a%20hyperplane%20is%20%24%5Cfrac%7B%7C%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D_0%20%2B%20b%7C%7D%7B%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%7D%24.%20Dividing%20by%20the%20norm%20ensures%20metric%20invariance%20under%20arbitrary%20scalar%20rescalings%20of%20%24%5Cmathbf%7Bw%7D%24%20and%20%24b%24.%0A%20%20%20%20*%20**Parallel%20Separation**%3A%20The%20distance%20between%20parallel%20hyperplanes%20%24%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D%20%2B%20b_1%20%3D%200%24%20and%20%24%5Cmathbf%7Bw%7D%5ET%20%5Cmathbf%7Bx%7D%20%2B%20b_2%20%3D%200%24%20is%20%24D%20%3D%20%5Cfrac%7B%7Cb_1%20-%20b_2%7C%7D%7B%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%7D%24.%0A%20%20%20%20*%20**SVM%20Margin%20Maximization**%3A%20In%20support%20vector%20machines%2C%20setting%20canonical%20hyperplanes%20at%20%24%5Cpm%201%24%20produces%20a%20margin%20of%20%24%5Cfrac%7B2%7D%7B%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%7D%24%2C%20proving%20why%20maximizing%20geometric%20separation%20is%20equivalent%20to%20minimizing%20the%20%24L_2%24%20weight%20norm%20%24%5C%7C%5Cmathbf%7Bw%7D%5C%7C_2%24.%0A%0A%20%20%20%20---%0A%0A%20%20%20%20%26larr%3B%20Previous%20Note%3A%20%5B02%20Norm%20and%20Metric%5D(02_norm_and_metric.py)%20%7C%20Next%20Note%3A%20%5B04%20Rank-One%20Matrices%5D(04_rank_one_matrices.py)%20%26rarr%3B%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
7d4726ccf920904e0edf215c877f49c3