Stacked layers of neurons with non-linear activations learn curved functions a single line never could.
A multilayer perceptron (MLP) is the simplest deep network: a stack of layers, each a row of neurons. Every neuron multiplies its inputs by learned weights, adds a bias, and passes that sum through a non-linear activation. Feed numbers in one end, read the answer off the other — that's a forward pass. The layers in the middle, the *hidden* layers, are what let the network invent its own features and bend its decision surface into almost any shape.
A single neuron is just a weighted sum followed by a bend: a = activation(w·x + b). The weights w say how much each input matters; the bias b shifts the threshold. On its own that's a linear classifier — a straight cut. The power comes from stacking many of them and bending each layer's output.
function layer(x, W, b, act) {
// x: input vector, W: weight matrix, b: bias vector
return W.map((row, j) => {
let sum = b[j];
for (let i = 0; i < x.length; i++) sum += row[i] * x[i];
return act(sum); // the non-linear bend
});
}
// forward pass = run layer after layer
const h = layer(x, W1, b1, relu);
const y = layer(h, W2, b2, softmax);W2(W1 x) = (W2 W1) x, a single linear layer. The non-linear activation between layers is the only reason depth buys you anything — remove it and a 10-layer net is no stronger than one line.