- Introduced by
- Hinton, G.E. & Salakhutdinov, R.R.
- Year
- 2006
- Type
- Neural network (encoder-decoder)
What does it do?
An autoencoder is a neural network with two parts: an encoder that compresses each input into a low-dimensional latent code, and a decoder that tries to rebuild the original input from that code.
Training minimises the squared reconstruction error, so the latent code is pushed to keep the information needed for reconstruction. The method is used for nonlinear dimensionality reduction and for anomaly detection based on reconstruction error.
The intuition behind the method
Imagine being asked to summarise a long document in a single sentence and then rewrite the full document from that sentence alone. To do this well you must keep only what matters most. An autoencoder learns exactly this discipline: it squeezes each observation through a narrow bottleneck and tries to rebuild the original from the squeezed code. Whatever survives the squeeze is the essence of the data, and inputs the network cannot reconstruct well stand out as anomalies.
History
The 2006 Science paper by Geoffrey Hinton and Ruslan Salakhutdinov is the work cited for this method. It reports that deep autoencoders with a small central layer can learn low-dimensional codes that work better than principal components analysis for reducing dimensionality. Its key contribution, according to the abstract, is a way of initialising the weights, since gradient fine-tuning alone works well only when the starting weights are already close to a good solution. The sources available here do not establish the earliest origin of the idea, so the 2006 paper should be read as the widely cited demonstration rather than as the first autoencoder.
When to use it
Choose an autoencoder when the data are continuous-valued, the relationships among variables are expected to be nonlinear, and there are enough observations to train the network. No validated minimum sample size exists; the number needed depends on the input dimension, the architecture and the noise level. It does not require normally distributed inputs. With limited data, compare against PCA, which has far fewer parameters and is usually the more reliable first step. It is also a poor fit when interpretable component loadings are required, because the latent dimensions do not correspond to named variables. For purely categorical data, the squared-error objective is a weak match and other methods should be considered.
Limitations and considerations
- Fitting the network's many weights requires a large enough sample; with few observations the latent space is poorly determined.
- The width of the bottleneck layer is a critical choice and directly controls how much information the code can retain.
- Latent dimensions are not named variables, so the results are harder to interpret than the loadings of PCA.
- The squared-error objective in the reconstruction step gives large-scale variables more weight unless the inputs are standardised.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Its hidden layers can learn nonlinear mappings, whereas PCA is restricted to linear projections.
- The same trained network yields a latent code for dimensionality reduction and reconstruction errors for anomaly detection.
- The training objective is only a reconstruction error on the inputs, so no distributional assumption such as normality appears in the formula.
- The latent code can be reused as a learned feature set for downstream models.
Applications
- Nonlinear dimensionality reduction of high-dimensional continuous data.
- Anomaly detection by flagging observations with large reconstruction error.
- Learning compact latent representations as features for downstream tasks.
- Exploratory analysis of complex data where linear reduction is insufficient.
How it works
How it works
The encoder maps the input through one or more hidden layers down to a low-dimensional latent code. The width of the bottleneck layer is the critical design choice: if it is too wide, the network tends toward an identity mapping unless it is regularised, and if it is too narrow, it loses meaningful structure. Choose the width using reconstruction error on held-out validation data, and compare the result with a PCA baseline of the same dimension.
Formula
z = f(Wx + b)
The decoder takes the latent code and expands it back through hidden layers toward the original dimensionality, producing a reconstruction of the input. Encoder and decoder are trained together as a single network.
Formula
\hat{x} = g(W'z + b')Training minimises the reconstruction error, the difference between the input and its rebuilt version, averaged over the training observations. Once trained, the latent code serves as a compressed representation for dimensionality reduction. Large reconstruction errors flag observations that do not fit the learned patterns, which supports anomaly detection. For this use, the model should be trained on data that are mostly normal, and the error threshold should be set on held-out normal data, for example as a high percentile of the reconstruction errors. Reconstruction error depends on the scale of the variables, so the threshold should be validated against known anomalies where they are available.
Formula
\min_{W,b,W',b'} \; \frac{1}{n}\sum_{i=1}^{n} \lVert x_i - \hat{x}_i \rVert^2Common pitfalls
- Applying it to a small sample where PCA would give a simpler and more stable result.
- Setting the bottleneck too wide without regularisation, so the network drifts toward an identity mapping and compresses little.
- Setting the bottleneck too narrow, so informative variation is discarded and reconstruction error is high even for ordinary observations.
- Feeding unscaled features, so that high-variance columns dominate both training and the reconstruction error.
- Flagging anomalies by reconstruction error while training on data that already contain the anomalies, which lets the network learn to reconstruct them.
- Choosing the anomaly threshold arbitrarily instead of calibrating it on held-out normal data.
Frequently asked questions
How is an autoencoder different from PCA?
PCA finds the best linear projection of the data, while an autoencoder can learn nonlinear representations through its hidden layers. When a linear summary suffices or data are limited, PCA is simpler and more reliable; autoencoders pay off when the data have nonlinear structure and the sample is large enough to fit the network.
How much data do I need?
There is no validated minimum. The required size depends on the input dimension, the network architecture and the noise in the data. With few observations there is little data to fit the network's weights, so compare against PCA or another simpler model and check reconstruction error on held-out data.
How do I detect anomalies with it?
Train on data that are mostly normal, then pass observations through the network and measure their reconstruction error. Set a threshold on held-out normal data, for example a high percentile of the errors, and flag points above it. Validate the threshold against known anomalies where available.
What is the most important setting to get right?
The size of the hidden (bottleneck) layer. If it is too wide, the network tends toward copying the input unless regularised; if it is too narrow, it discards meaningful structure. Select it using validation reconstruction error and a PCA comparison.
Related methods
Sources
Hinton, G.E. & Salakhutdinov, R.R. (2006). Reducing the Dimensionality of Data with Neural Networks. Science, 313(5786), 504–507.
Open DOI reference