The initial value of w_2 is fixed at 0.5. Data are generated by a fixed-seed LCG (seed = 42), so the same 20 points appear every time you redraw.
Blue dots = class +1 / red crosses = class -1 / green solid = learned boundary / gray dashed = true boundary x1 + x2 = 0
A single-layer perceptron is a 2-input linear threshold unit whose output is the sign of a weighted sum:
$$y = \operatorname{sign}(w_1 x_1 + w_2 x_2 + b)$$Update rule (Perceptron Learning Algorithm, PLA). $t \in \{+1,-1\}$ is the target and $y$ is the model output:
$$w_i \leftarrow w_i + \eta\,(t - y)\,x_i,\quad b \leftarrow b + \eta\,(t - y)$$The decision boundary is $w_1 x_1 + w_2 x_2 + b = 0$, or for plotting:
$$x_2 = -\frac{w_1 x_1 + b}{w_2}$$The margin, the signed distance from a point to the boundary, is normalized by the weight norm:
$$\gamma = \frac{w \cdot x_{\text{target}} + b}{\|w\|}$$If the data are linearly separable, the perceptron convergence theorem guarantees that a separating hyperplane is reached in a finite number of updates.