#175Neuron — one unit, three activationsEasyNeural NetworksActivation Functions
Neuron — one unit, three activations
Background
The lesson's one-picture summary: features → linear score z → activation f(z) → output. Change only the activation and the same neuron becomes a different model:
| activation | model | |
|---|---|---|
| identity | linear regression | |
| sigmoid | logistic regression | |
| step | perceptron |
Problem statement
Implement neuron(x, w, b, activation) that computes and applies the named activation.
Input
x,w— array-like vectors of equal length.b—float.activation— one of"identity","sigmoid","step".
Output
Returns a Python float: .
Examples
Example 1
Input: x = [1, 1], w = [1, 2], b = -1, activation = "identity"
Output: 2.0
Explanation: ; identity returns .
Example 2
Input: x = [1, 1], w = [1, 2], b = -1, activation = "sigmoid"
Output: 0.8807970779...
Explanation: .
Constraints
- Compute
zonce, then branch onactivation. "step"returns1.0when else0.0.- Return a plain
float.
Notes
- This is the heart of the "neuron" abstraction: one linear core, a pluggable nonlinearity. Stacking many such units with smooth activations is what makes deep networks trainable.
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 identity
- •reference sigmoid
- •sample step at zero