This document is a theory-first companion to the NumPy Autoencoder project.
While the main README.md focuses on code and structure, this file explains:
- What an autoencoder is
- Why it works
- The mathematics behind it
- Reconstruction vs denoising
- Practical applications
This is written for learners encountering autoencoders for the first time, but who want more depth than surface-level explanations.
An autoencoder is a type of neural network that learns to reconstruct its input.
Instead of predicting labels, it tries to learn:
input ≈ output
At first glance, this may look pointless, but the key idea lies in the latent space.
An autoencoder is composed of three parts:
Input → Encoder → Latent Representation → Decoder → Reconstruction
- Compresses the input
- Maps high-dimensional data into a lower-dimensional space
- Compact representation of the data
- Forces the model to learn meaningful structures in the data
- Expands latent vectors back to the original input space
If the latent space is smaller than the input, the network cannot simply copy the input, it must learn patterns.
Let:
-
$( x \in \mathbb{R}^n )$ be the input -
$( z \in \mathbb{R}^k )$ be the latent vector, where$( k < n )$
[
Typically:
[
[
Typically:
[
The network is trained to minimize the reconstruction error:
[
(MSE loss)
Training is done using backpropagation just like any other neural network.
The bottleneck (latent space) forces the model to:
- Capture correlations
- Learn manifolds
- Discard noise and redundancy
In the case of images, this often means learning:
- Edges
- Strokes
- Shapes
Learn to reconstruct the same clean input:
x → Encoder → Decoder → x̂
- Input: 28×28 grayscale digit
- Flattened to 784 values
- Latent space: e.g. 16 dimensions
The model learns a compressed representation of handwritten digits.
- Digit structure
- Stroke thickness
- Common patterns (loops, lines)
Train the model to remove noise.
Instead of:
x → x̂
We train:
(x + noise) → x̂ ≈ x
The input is corrupted, but the target remains clean.
Let:
[
Loss:
[
The model learns to project noisy inputs back onto the data manifold.
For MNIST digits:
- Noise corrupts pixels randomly
- Digits still lie on a low-dimensional manifold
The autoencoder learns:
- Which pixels are important
- Which variations are noise
This makes denoising autoencoders useful as:
- Pretraining models
- Feature extractors
- Robust encoders
- Non-linear alternative to PCA
- Images
- Audio
- Sensor signals
- Train on normal data
- High reconstruction error ⇒ anomaly
- Pretraining for downstream tasks
- Variational Autoencoders (VAEs)
- β-VAEs
- Plain autoencoders are not truly generative
- Can learn identity mapping if not constrained
- Sensitive to architecture choices
This is why constraints like:
- Bottlenecks
- Noise
- Regularization
are important.
-
Hinton & Salakhutdinov (2006) Reducing the Dimensionality of Data with Neural Networks
-
Vincent et al. (2008) Extracting and Composing Robust Features with Denoising Autoencoders
-
Goodfellow, Bengio, Courville Deep Learning — Chapter 14
-
Stanford CS231n Notes Autoencoders & Representation Learning
-
encoderimplements$( f_\theta )$ -
decoderimplements$( g_\phi )$ -
latentcontrols constraints -
lossdefines reconstruction error
Understanding this document will make the code feel obvious, not magical.
Autoencoders are simple.
Their power comes from constraints, not complexity.
Once you truly understand them, many modern models start to make sense.