v9.1.1
Menu

Single Perceptron

easyFREENeural NetworksMachine Learning 2

Implement a single perceptron forward pass.

Given an input vector xx, weight vector ww, and bias bb, compute:

z=w⋅x+bz = w \cdot x + b output={1if z≥00otherwise\text{output} = \begin{cases} 1 & \text{if } z \geq 0 \\ 0 & \text{otherwise} \end{cases}

Process multiple input samples and return a list of outputs.

Example

Input
X = [[1, 1], [0, 1], [1, 0], [0, 0]]
w = [1, 1]
b = -1.5
Output
[1, 0, 0, 0]
Reasoning
  • Inputs: X holds four 2-feature samples (rows), w = [1, 1] gives each feature equal weight, and b = -1.5 shifts the decision boundary.
  • Weighted sum: for each sample, z=w1x1+w2x2+bz = w_1 x_1 + w_2 x_2 + b. With both weights equal to 1, zz is just the number of active features minus 1.5:
    • [1,1][1, 1]: z=1+1−1.5=0.5z = 1 + 1 - 1.5 = 0.5
    • [0,1][0, 1] and [1,0][1, 0]: z=1−1.5=−0.5z = 1 - 1.5 = -0.5
    • [0,0][0, 0]: z=0−1.5=−1.5z = 0 - 1.5 = -1.5
  • Step activation: only z=0.5z = 0.5 satisfies z≥0z \geq 0, so it maps to 11; the three negative values map to 00, giving [1, 0, 0, 0].
  • Notice: this perceptron computes logical AND. Raising the bias to −0.5-0.5 lets a single active feature reach z=0.5z = 0.5, turning it into OR ([1, 1, 1, 0]). Also, zz exactly 00 counts as 11, since the threshold is inclusive.

Constraints

  • X: 2D list of input vectors
  • w: list of weights
  • b: scalar bias
  • Return list of 0 or 1 outputs

Learn this in

More from Machine Learning 2

solution.py

Test results

Sign in to run your code against the test cases.