MIT 6.790 — Lecture 12
Neural Networks
§ Neurons
Recall from Lecture 11 that the hypothesis class specified by regression models does not contain a hypothesis that can correctly model two-variable XOR; the data pictured below is not linearly separable.

We need more general models than regression models. In come neural networks.
Definition. A single neuron is a function , made up of two parts:
The pre-activation of a neuron is ; that is, a weighted sum of inputs plus a bias .
The activation / output of a neuron is , where is an activation function.
Some common choices of activation functions include:
Remark. Note that , so the sigmoid and tanh activations are roughly the same.
§ Neural Networks: XOR Example
Note that a single neuron with sigmoid activation is identical to logistic regression. This means that a single neuron isn't enough to model two-variable XOR. One fix, however, is to use a linear classifier over a hardcoded feature space.

As shown above, the following feature map allows us to compute via a linear classifier.
In the diagram below, we represent the process of first converting our inputs into features , then using the features as inputs to the output neuron.

Each input is a node, each feature is a node, and the output is a node. Furthermore, an edge is drawn if is an input to the neuron whose output is .
Here's the important point: not only is the final output a neuron, but the intermediate feature nodes and are neurons too! Note that their activation function is .
The diagram above is an example of a neural network. Let's generalize this to a definition.
§ Neural Networks: Definition
Definition. A neural network consists of one input layer, some number of hidden layers, and one output layer.
The input layer just reads in the input vector . It's the identity map given by .
The hidden layer is the map , whose output is a neuron activation of the output of the layer.
Note that denotes the dimension of the output of . Equivalently, is the number of neurons in the layer.
By consequence, note that we must have .
The output layer is the map . It operates just like every hidden layer; its output is the final answer.
That's a whole bunch of jargon to explain the relatively simple idea of chaining layers of neurons together.

Here's how this looks in the example of the XOR neural network. Every single parameter in the neural network—that is, every value of and every entry of a matrix —is written in purple text.

The upshot of neural networks comes from their hidden layers. Previously, we would just have to have known, somehow, that would be a good set of features for encoding .
With neural networks, however, instead of hardcoding the best features (or, in the neural network analogy, the best ) to use, we can instead learn the best features by optimizing the parameters .
Hidden layers encode features. That raises the question: are hidden layers capable of encoding any feature?
§ Neural Network Universal Approximation
The answer is yes, mostly.
Theorem. (Universal Approximation) For every continuous and , there is a function that is a linear combination of ReLUs such that .
Furthermore, we can upper-bound the complexity of such a function , somewhat.
Theorem. (Universal Approximation Bound) Suppose is 1-Lipschitz continuous—that is, for all . Then for all , there is a function that is a linear combination of order ReLUs such that .
Interestingly, both of these theorems state that only one hidden layer is technically necessary—each ReLU is a single node in that layer, and the output layer is the linear combination of those nodes.
Still, though, as we'll see in future lectures, it is often useful to use more than one hidden layer, both from a computation perspective and a representation perspective.