Neural network architectures
Notes on neural network architectures: definitions, main types (feedforward, recurrent, convolutional, autoencoders, associative and energy-based networks), key theorems (universal approximation), formulas for parameter counts and convolution output sizes, worked examples, common exam mistakes and q
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Neural network architectures are the designs or blueprints that decide how artificial neurons connect and compute. An engineer uses architectures to choose a suitable structure for tasks such as classification, regression, pattern recognition or sequence prediction, balancing accuracy, speed and memory.
Key ideas
Start with simple definitions and build up.
Artificial neuron: a basic processing unit that takes real-valued inputs, computes a weighted sum plus a bias, and passes the result through an activation function (a fixed nonlinear function). Activation function — a function that maps a real number to a (not always bounded) real number and introduces nonlinearity (examples: sigmoid, tanh, ReLU).
Layer: a group of neurons that compute in parallel and share the same input vector. A layer receives inputs from previous layers (or from raw input) and sends outputs to next layers.
Feedforward network (also called multilayer perceptron or MLP): a network where signals travel only from inputs toward outputs; there are no cycles or feedback paths. A simple MLP has an input layer, one or more hidden layers, and an output layer. Each connection typically has a weight and each neuron a bias.
Fully connected (dense) layer: every neuron in the layer is connected to every neuron in the previous layer.
Recurrent neural network (RNN): an architecture where connections form cycles allowing the network to have memory of previous inputs. A basic RNN cell computes its new state from the current input and the previous state.
Convolutional neural network (CNN): a feedforward architecture designed for grid-structured data (images, signals). It uses convolutional layers that apply small learnable filters (kernels) across spatial dimensions, and pooling layers that reduce spatial size.
Autoencoder: a feedforward network trained to copy input to output via a central low-dimensional layer called the bottleneck; the network has two parts: encoder (maps input to code) and decoder (maps code to reconstruction). Used for dimensionality reduction and unsupervised feature learning.
Residual network (ResNet) and skip connections: architectures that add the input of a block to its output (identity shortcut) to allow training of very deep networks by easing gradient flow.
Hopfield network: a recurrent, symmetric-weight network used as an associative memory. It has an energy function; stable states (local minima of energy) correspond to stored patterns.
Boltzmann machine: a stochastic energy-based recurrent network with binary units and symmetric connections; learning uses likelihood gradients and sampling.
Self-organising map (SOM) (also called Kohonen map): a competitive network that maps high-dimensional inputs to a usually 2D grid preserving topology (useful for visualization and clustering).
Important theorem commonly asked in exams:
- Universal Approximation Theorem (exact statement): Let f be any continuous real-valued function defined on a compact subset K of R^n. Let σ be a nonpolynomial continuous activation function (for example, logistic sigmoid or hyperbolic tangent). Then for any ε > 0, there exists a feedforward network with one hidden layer containing a finite number of neurons with activation σ and a linear output layer such that the network's output g satisfies sup_{x in K} |f(x) - g(x)| < ε. Assumptions: K compact, σ continuous and nonpolynomial, approximation in uniform norm. Consequence: shallow networks can approximate continuous functions arbitrarily well given enough neurons; this does not say how many neurons are needed, nor about training.
Design trade-offs and assumptions:
Depth vs width: deeper networks can represent some functions with exponentially fewer neurons than shallow networks, but they may be harder to train without techniques such as skip connections or batch normalisation (these are engineering solutions; training theory is separate).
Parameter count and memory: fully connected layers have many parameters (weights and biases); convolutional layers reuse filters and therefore have far fewer parameters for data with approximately translation-equivariant structure (e.g., images), exploiting local connectivity and weight sharing.
How to draw architectures in an exam (diagrams to draw):
For a simple feedforward MLP with one hidden layer: draw three vertical columns of nodes (left = input features x1..xn, middle = hidden neurons h1..hm, right = outputs y1..yk). Draw arrows from every node in left to every node in middle, and from middle to right. Label weights w_{ji}, biases b_j on hidden neurons, activation φ, and show equations h_j = φ(sum_i w_{ji} x_i + b_j).
For a convolutional layer: draw an image patch and a small kernel matrix; show sliding of kernel across image with stride S and padding P; label input width W_in, kernel size K, padding P, stride S, output width W_out.
For an RNN cell unrolled in time: draw copies of the cell horizontally for times t=1..T, show recurrent connection from state s_{t-1} to s_t and input x_t to s_t and output y_t from s_t.
Formulas
Each formula on its own line, then description.
W_total = sum_{l=1..L} (n_l * (n_{l-1} + 1))
- W_total = total number of trainable parameters (weights + biases) in an L-layer fully connected network, where layer 0 is input with n_0 inputs and layer l has n_l neurons. No units (count). Applies when every neuron has one bias and full connectivity between successive layers.
h_j = φ(Σ_{i=1..n} w_{ji} x_i + b_j)
- h_j = output of neuron j in a layer; φ = activation function (unitless), w_{ji} = weight from input i to neuron j (unit depends on input), x_i = input i (same unit as data), b_j = bias (same unit as weighted sum). Applies to feedforward networks.
W_out = floor((W_in - K + 2P) / S) + 1
- Output spatial size (width or height) of a convolutional layer: W_in = input size (pixels), K = kernel size, P = padding (pixels), S = stride (pixels). Applies to 2D convolutions per dimension.
Parameters_conv = K_h * K_w * C_in * C_out + C_out
- Number of parameters in a convolutional layer: kernel height K_h, kernel width K_w, C_in input channels, C_out output channels, plus one bias per output channel. No units. Applies for standard convolution with per-filter bias.
s_t = f_w(x_t, s_{t-1}) and y_t = g_w(s_t)
- Recurrence in RNN: s_t = new state computed from current input x_t and previous state s_{t-1} using parameters w; y_t = output from state. f_w and g_w are parameterised functions (examples: linear + activation). Unit: depends on variables.
Worked examples
Example 1 — Parameter count (numerical) Question: For a fully connected feedforward network with input dimension 10, one hidden layer of 20 neurons, and an output layer of 5 neurons, how many parameters (weights + biases) are there? Show steps. Solution:
- Use formula
W_total = Σ n_l*(n_{l-1}+1). - Layers: layer0 n_0 = 10 (input), layer1 n_1 = 20 (hidden), layer2 n_2 = 5 (output).
- Parameters for layer1 = n_1*(n_0 + 1) = 20*(10+1) = 20*11 = 220.
- Parameters for layer2 = n_2*(n_1 + 1) = 5*(20+1) = 5*21 = 105.
- Total = 220 + 105 = 325. Answer: 325 parameters.
Example 2 — Convolution output size and parameters (numerical) Question: An input image is 32 × 32 with 3 channels. A convolutional layer uses 16 filters of size 5 × 5, stride 1, padding 0. Compute output spatial size and total parameters. Solution:
- Input width W_in = 32, kernel K = 5, padding P = 0, stride S = 1. Use
W_out = floor((W_in - K + 2P)/S) + 1. - W_out = floor((32 - 5 + 0)/1) + 1 = floor(27) + 1 = 27 + 1 = 28. So output is 28 × 28.
- Parameters_conv = K_hK_wC_inC_out + C_out = 55316 + 16 = 25*48 + 16 = 1200 + 16 = 1216. Answer: Output size 28×28×16, parameters = 1216.
Example 3 — Model answer (theory question) Question: Compare feedforward and recurrent architectures. Draw labelled diagrams and explain when to use each. Model answer (short):
- Define feedforward network (signals only forward) and recurrent network (cycles and memory). Draw an MLP diagram and an unrolled-in-time RNN diagram as described in Key ideas. Discuss: feedforward networks are suited to tasks where inputs are independent (image classification, regression); RNNs are suited to sequence tasks (language, time series) where past inputs influence current output. Give computational differences: feedforward computes in O(number of weights) per input, RNNs compute sequentially across time steps and may require backpropagation through time (BPTT) for training. Mention vanishing/exploding gradients as practical training issues for RNNs and solutions like gated units (LSTM, GRU) or attention (reference other topics by name, do not re-teach).
Common mistakes
- For convolution output size, forgetting to apply floor or to include padding and stride correctly.
- Drawing RNNs without showing time-unrolled version when explaining learning through time (students sometimes show only the cyclic diagram and do not show unrolled BPTT view).
- Confusing feature map depth (channels) with spatial dimensions.
For your exam
Types of questions you will see:
- Definitions and short notes: define feedforward, recurrent, convolutional, autoencoder, Hopfield, Boltzmann machine.
- Diagrams: draw and label MLP, convolutional layer sliding kernel, RNN unrolled in time.
- Derivation/numerical: compute parameter counts, convolution output sizes, or compute forward pass outputs for small networks.
- Long question: compare architectures, explain when to use which, give advantages/disadvantages and training considerations.
What a full-marks answer includes:
- Clear definitions with bolded keywords (as above).
- Correct labelled diagrams (showing number of nodes, connectivity, weights and biases where relevant).
- Step-by-step calculations using the formulas given, carrying through units or counts and final bolded answer.
- Mention of assumptions (e.g., universal approximation theorem assumptions) and limitations (trainability, data requirements).
Quick check
- What is a convolutional layer designed to exploit in image data?
- Write the formula for output width of a convolutional layer in one dimension.
- How many parameters in a dense layer that maps 50 inputs to 10 outputs (including biases)?
Answers: 1) Translation equivariance (with pooling/aggregation contributing some invariance) via local connectivity and weight sharing. 2)
W_out = floor((W_in - K + 2P)/S) + 1. 3)10*(50+1) = 510.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?