#178Perceptron — the hard threshold unitEasyNeural Networks
Perceptron — the hard threshold unit
Background
Rosenblatt's perceptron (1958) is a binary linear classifier with a hard decision: it fires when the score is non-negative.
Unlike the smooth sigmoid, this step activation jumps from 0 to 1 at . Same linear boundary as logistic regression, but a discontinuous output.
Problem statement
Implement perceptron(x, w, b) that returns the perceptron's hard label: 1 when , else 0.
Input
x— array-like feature vector.w— array-like weight vector, same length.b—float, the bias.
Output
Returns an int, 0 or 1.
Examples
Example 1
Input: x = [2, 3], w = [2, 3], b = -5
Output: 1
Explanation: , so the unit fires.
Example 2 — on the threshold fires
Input: x = [2.5, 0], w = [2, 3], b = -5
Output: 1
Explanation: , and the rule is , so it still outputs 1.
Constraints
- Use (inclusive) for the threshold, matching .
- Return a Python
int(0/1).
Notes
- The step has zero gradient almost everywhere, which is exactly why modern neurons swap it for a differentiable activation so backpropagation can flow.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Example — positive score fires
- •Reference on the threshold fires
- •Sample negative score stays zero