AI Research Library
Autoencoders and the Bottleneck Bargain
Rajesh Ranjan Mahapatra
An autoencoder preserves the variation that reduces its declared reconstruction loss, so useful compression requires an explicit contract for capacity, distortion, data, information paths and downstream decisions.
© 2026 Rajesh Ranjan Mahapatra. 32 min read
Autoencoders and the Bottleneck Bargain
An autoencoder preserves the variation that reduces its declared reconstruction loss, so useful compression requires an explicit contract for capacity, distortion, data, information paths and downstream decisions.
TLDR
- A bottleneck is a budget, not a judge. It does not know which distinctions matter; it keeps those that most reduce reconstruction error under the training distribution.
- Capacity, example frequency, distortion weights, decoder strength and side channels jointly determine what enters the latent code. Changing any one can change the bargain.
- A low average reconstruction loss can coexist with the loss of a rare, low-amplitude and decision-critical signal. Evaluate protected distinctions directly, not through visual fidelity alone.
- Reconstruction can still learn excellent features when corruption, masking, architecture and evaluation make the intended invariances explicit. The boundary is alignment, not a verdict against autoencoders.
- Before reusing a latent, write a bottleneck contract and run a fixed-capacity loss-swap test. Release only when reconstruction, rate and downstream consequence all pass.
The alarm that reconstructed away
A monitoring team compresses fourteen telemetry channels into two latent coordinates. Twelve channels describe ordinary load and operating regime. Their values move widely and dominate the variance. The final two channels carry a faint binary alarm precursor. Its amplitude is small, but it is the only early distinction between a routine operating cycle and a condition that requires inspection.
The autoencoder looks successful. On held-out synthetic data, a rank-two model trained with ordinary mean squared error reaches an overall MSE of 0.01191. It reconstructs the large signals almost perfectly. Its latent predicts load with an R² of 1.000 and regime with 0.996. A dashboard of aggregate errors would be reassuring.
Yet the alarm is absent. A linear probe on the latent identifies its two states with 50.0% accuracy, exactly chance. Nothing mysterious happened. The alarm occupied two low-amplitude channels, so losing it was cheap under an average squared-error objective. The two available latent directions were spent on the factors that bought the largest reduction in the declared loss.
Now hold the data, model family, optimisation method and two-dimensional capacity fixed. Change only the reconstruction metric by multiplying error on the two alarm channels by fifty. Alarm accuracy rises to 100.0%. The model pays for that success by dropping regime information, whose probe R² falls to 0.002. Widen the bottleneck to three coordinates and all three factors survive. Give it fourteen coordinates and reconstruction becomes an identity control rather than meaningful compression.
This is a synthetic experiment, not a deployment report. It isolates the causal point: under constrained capacity, an autoencoder preserves whatever variation is expensive to reconstruct badly. “Expensive” is set by frequency, scale, loss, architecture and available information paths. It is not supplied by the word important, by the visual neatness of a latent plot or by the eventual consequence of a downstream decision.
The broader essay Representation Before Intelligence asks which world relations any useful representation must preserve. The narrower question here is how an autoencoder makes that choice implicitly, and how to make the bargain testable before another system depends on its latent.
Part one
The bargain hidden in a mirror
An ordinary deterministic autoencoder has two learned maps. The encoder turns an observation x into a latent code z. The decoder turns that code into a reconstruction x̂. Training adjusts both maps so the reconstruction resembles the input.
fθ is the encoder, gφ is the decoder, p_train is the training distribution and d is the distortion measure. The expectation means that frequent examples and heavily weighted errors contribute more to the objective.
The equation is often described as “learning to copy through a bottleneck”. That phrase hides the consequential choice. Copying is impossible when the information path cannot carry everything. The optimiser must allocate error. The data distribution decides which cases vote often; the distortion measure decides how loudly each mismatch votes; the encoder and decoder decide which compromises are easy to implement.
The latent is therefore the record of a negotiated loss, not a neutral summary of the input. A squared-error image model pays strongly for broad intensity differences and repeated textures because many pixels contribute. A categorical feature can disappear if it changes only a few pixels. A time-series model can preserve seasonal amplitude while smoothing a short precursor. A tabular model can spend capacity on a high-variance continuous field and neglect a small binary flag.
The linear case makes the bargain visible
For a single undercomplete linear autoencoder trained with squared error under standard conditions, the optimal reconstruction spans the same principal subspace as principal component analysis. Classic analyses by Bourlard and Kamp, and by Baldi and Hornik, made this relationship precise.1 The model preserves directions that explain the most squared variation. Nonlinear encoders can bend the surface and represent more complicated manifolds, as the deep autoencoder experiments of Hinton and Salakhutdinov illustrated.2 Nonlinearity changes the shapes available to the model. It does not remove the need to specify which reconstruction errors matter.
The linear result is useful because it removes optimisation folklore. In the laboratory, singular value decomposition finds the exact rank-constrained solution. If the alarm vanishes, it is not because training became trapped, the seed was unlucky or the network needed another activation function. It vanishes because, under that loss and capacity, keeping two larger factors is the better bargain.
Thought experiment: the one-pixel warning
Imagine one thousand images of an instrument panel. Every image contains a richly textured background and a one-pixel warning light. The background changes across almost every pixel. The light is off in 995 images and on in five. The operational decision depends entirely on the light.
First, train a small autoencoder with unweighted pixel MSE. A reconstruction that smooths away the warning barely changes the average loss. Now repeat the experiment without changing the architecture, data count or optimisation. Increase only the weight of that pixel, or oversample the five warning cases. The warning becomes more expensive to miss and should consume more representational capacity.
The structural correspondence is exact: the background represents frequent, high-area variation; the warning represents a rare, low-area distinction; weighting changes its distortion cost. The analogy ends there. A real image has spatial dependencies, sensor noise and possible correlations that a capable model may exploit. The thought experiment establishes an incentive, not a universal training outcome.
This is an explanatory decomposition, not a universal optimisation identity. Correlation, architecture and gradient dynamics can change the realised allocation.
Reconstructing the input is already a value judgement
“Preserve the input” sounds neutral because the target equals the source. It is not neutral once loss is aggregated. Mean squared error values numerical closeness in the observed coordinates. Cross-entropy over discretised symbols values log probability of the exact target class. A perceptual loss values similarity in another network’s feature space. A spectral loss values discrepancies at selected frequencies. Each declares a different family of errors interchangeable.
Blau and Michaeli proved a perception-distortion trade-off for image restoration: driving expected distortion down can conflict with making outputs look like samples from the natural-image distribution.10 That result is not a general theorem about every autoencoder, but it punctures the idea that one scalar distortion metric can stand for every notion of quality. A sharper image can be farther away pixel by pixel; a lower-MSE image can look implausibly smooth.
Before training, complete the sentence: “Two reconstructions are equally acceptable when…”. The answer defines the distortion relation. If the team cannot finish that sentence for the intended use, reconstruction loss is functioning as an unexamined policy.
Part two
What the bottleneck actually is
A diagram often labels the narrowest hidden layer “the bottleneck”. That is only a shape. The operational bottleneck is the complete information path from input to reconstruction: latent dimensionality, numerical precision, stochastic noise, quantisation, entropy coding, decoder capacity, skip connections, metadata and any context available at decoding time.
Latent width is not the same thing as information rate. In ideal real-number arithmetic, one continuous coordinate can carry unbounded information through arbitrarily fine precision. A four-dimensional vector stored at 32 bits per value has a different physical budget from the same vector quantised to four levels. A stochastic code with noise has another effective capacity. A learned image codec couples quantisation with an entropy model because the number of coordinates alone does not say how many bits will be transmitted.
Rate-distortion gives the right question
Rate-distortion theory asks how much communication rate is required to keep expected distortion below a chosen level. It does not identify one universal distortion function. Shannon’s fidelity criterion made the dependence explicit, and the information bottleneck later framed compression around retaining information about a declared relevance variable.67
D is expected distortion, R is a rate or information cost and β sets their exchange rate. Increasing β makes information more expensive. The exact meanings of rate and distortion depend on the coding model and task.
For a practical compressor, rate may be the expected length of the entropy-coded bitstream. For a stochastic representation model, it may be bounded through mutual information or a divergence term. For a deterministic feature extractor with floating-point outputs, calling the number of coordinates “compression rate” is usually only a proxy. Amjad and Geiger show why information-bottleneck quantities can become ill-posed or geometry-blind for deterministic neural networks.8 Their result does not invalidate every bottleneck regulariser; it warns against treating one information quantity as a complete certificate of robustness or simplicity.
Four different constraints often share one name
A dimensional bottleneck limits the number of coordinates. It is useful for exposing rank and manifold assumptions, but it does not define the number of transmissible bits. A coding bottleneck quantises those coordinates and charges their codelength under an entropy model. This is the relevant object when storage or bandwidth is the claim.
A stochastic bottleneck adds noise or samples a latent distribution. Information that depends on distinctions smaller than the noise scale becomes unreliable, even when the coordinate count is unchanged. An operational bottleneck includes latency, memory movement, compute, privacy and which side information the decoder may lawfully access. A representation can be compact in coordinates and expensive in every operational sense.
These constraints can pull in different directions. A wide but heavily quantised code may use fewer bits than a narrow high-precision code. A high-dimensional sparse code may be cheap to entropy-code. A decoder with a large external context can reconstruct well from a tiny latent, yet the system as a whole may transmit more information and consume more compute. The claimed benefit determines which budget must be measured.
This distinction also prevents a common category error in representation learning. Reducing dimension may help a particular classifier, visualisation or nearest-neighbour index. That is an empirical property of the consumer and data. It should not be reported as information compression unless the representation’s precision and probability model make a rate measurable.
Dimension-only view
The label says “two”, but precision, noise and coding are unspecified.
Actual information path
Thought experiment: give the decoder a serial number
Train an autoencoder to reconstruct photographs of manufactured parts. In the first condition, the decoder receives only the latent. In the second, it also receives a serial number that uniquely identifies the part. Nothing about the encoder’s nominal width changes.
With the serial number, a sufficiently capable decoder can memorise or retrieve much of the part-specific appearance. The latent can then ignore identity and carry only residual details. Reconstruction may improve while the latent becomes worse for retrieval by part identity. Remove the serial-number path and the latent must carry more of that distinction.
Varying one causal feature, the side channel, changes what the bottleneck needs to preserve. Skip connections in denoising networks, autoregressive context in sequence decoders and hyperpriors in learned image compression create related effects. Ballé and colleagues used a hyperprior as side information to improve image-compression rate-distortion performance.9 The design is legitimate because the side information is encoded and charged. Trouble begins when a team interprets the primary latent as a complete semantic representation while ignoring the information supplied elsewhere.
Regularisation changes the question
Several autoencoder variants deliberately make copying harder or shape the local representation. Denoising autoencoders corrupt the input and ask the model to reconstruct the clean target. The useful distinction is no longer every observed fluctuation; it is whatever supports recovery across the chosen corruption process. Vincent and colleagues reported robust features and downstream classification gains in their original experiments.3
Contractive autoencoders penalise sensitivity of the encoder to small input changes, encouraging local contraction around the data.4 Under specific small-noise and regularisation conditions, analyses by Alain and Bengio connect the reconstruction field to the score of the data density.5 These mechanisms show that reconstruction can reveal local structure when the perturbation and regulariser supply an inductive bias. They also reinforce the central argument: what the model learns depends on the exact reconstruction game.
Part three
flowchart LR A["The alarm that reconstructed away"] --> B["The bargain hidden in a mirror"] B --> C["What the bottleneck actually is"] C --> D["Why reconstruction does not<br/>identify meaning"] D -. "re-test" .-> A classDef first fill:#0a1424,stroke:#007D68,stroke-width:2px,color:#e6f3ff classDef step fill:#0a1424,stroke:#3f7da0,stroke-width:1px,color:#e6f3ff class A first class B,C,D step
Why reconstruction does not identify meaning
Suppose an encoder and decoder reconstruct every input perfectly. It is tempting to infer that the latent has discovered the true factors of the data. Perfect reconstruction supports a narrower conclusion: together, the two functions preserve enough information to invert the training examples. It does not identify a unique coordinate system, neighbourhood relation or semantic decomposition.
The bijective shuffle
Take any successful latent code and apply an invertible transformation h. Replace the encoder with h ∘ f and the decoder with g ∘ h⁻¹. Every reconstruction remains unchanged. The new latent may be rotated, stretched, folded or assigned arbitrary identifiers. Reconstruction loss cannot prefer the original geometry when the decoder exactly undoes the transformation.
This is a serious negative control because it leaves the observed objective untouched. It separates three claims that visualisations often merge: information is present; a bounded consumer can access it easily; coordinates correspond to human-named factors. Only the first follows directly from invertibility.
The same non-identifiability constrains claims about disentanglement. Locatello and colleagues proved that unsupervised disentanglement cannot be identified without inductive biases on the model and data, then trained more than twelve thousand models and found that stronger disentanglement scores did not reliably imply lower downstream sample complexity.11 The practical lesson is not that structured latents are useless. It is that the supervision, symmetry, corruption, task or regulariser that selects a structure must be named.
A low reconstruction error is not a normality certificate
Autoencoder anomaly detection often assumes that a model trained on normal examples will reconstruct normal inputs well and anomalies badly. That can work empirically in a bounded domain, but it is not guaranteed by the objective. A linear autoencoder reconstructs every point in its learned subspace, including points far beyond the region occupied by training data. Nonlinear networks can also generalise or extrapolate in unexpected ways.
Bouman and Heskes construct cases in which out-of-distribution anomalies are reconstructed perfectly, and demonstrate the issue in linear, tabular and image settings.15 Their 2025 work is a preprint, so its broadest conclusions still warrant scrutiny. Its counterexample is already decisive against one logical implication: low reconstruction error does not entail membership in the normal data distribution.
An anomaly detector therefore needs evidence beyond one residual. Possibilities include explicit density or support estimation, latent-distance tests with calibrated tails, ensembles, conformal procedures under stated exchangeability assumptions, supervised fault examples, physical rules and downstream outcome evaluation. Which combination is justified depends on the failure consequence and the available labels.
The strongest counterexample: engineered reconstruction works
A simplistic reading of the thesis would say reconstruction cannot produce useful features. Evidence contradicts that. Denoising autoencoders can learn robustness to a chosen corruption. Masked autoencoders reconstruct withheld image patches using an asymmetric encoder-decoder design and high mask ratios; He and colleagues reported strong transfer performance from that self-supervised objective.12 Reconstruction can be an effective training signal when the missingness pattern forces the encoder to model reusable structure and downstream tests confirm the benefit.
This counterexample sharpens the claim. The lesson is not “attach labels to everything”. It is make the reconstruction problem structurally aligned with the invariances and relations you hope to reuse, then test that reuse directly. In masked vision, local pixels are hidden and a lightweight decoder limits easy copying. In denoising, the corruption defines which changes should be ignored. In a plain identity autoencoder with abundant capacity, the easiest solution may preserve nuisance detail or approximate an identity map.
Recent evidence: capacity, frequency and loss reshape latents
D’Amato, Lancia and Pezzulo varied capacity, data imbalance and auxiliary task objectives in beta-variational autoencoders on a controlled image environment. They reported different geometric distortions, including prototypisation, specialisation and orthogonalisation.13 The study uses a simple VAE and purpose-built data, so it does not establish a universal taxonomy for deterministic autoencoders. It supplies primary evidence that the three levers in the bargain can systematically alter latent geometry.
A 2026 preprint by Strano and colleagues studies VAEs trained with pointwise, perceptual and adversarial reconstruction terms. In their setting, neural loss terms changed both the amount of information in the latent and its geometry, effects that could be hard to infer from reconstructions alone.14 Again, this is VAE-specific and not yet a settled general result. It is a useful warning that apparently similar outputs can conceal different latent allocations.
The historical linear result is exact under its assumptions. Denoising, masking and recent VAE studies are empirical or conditional. The article’s broad causal claim follows from the objective structure; the particular geometry produced by a deep nonlinear model remains an experimental question.
Part four
The loss-swap experiment
The opening case is deliberately small enough to reproduce. Four thousand synthetic observations train a rank-constrained linear autoencoder; two thousand form the test set. Twelve observed channels are noisy linear mixtures of two independent factors: load, with standard deviation three, and regime, with standard deviation one. Two further channels carry a binary alarm at amplitudes +0.18 and −0.18, plus small noise.
The latent has two dimensions. Because the data contain three independent factors, it cannot preserve all three exactly. The experiment compares four interventions:
- plain MSE with two latent dimensions;
- the same model with alarm-channel errors weighted fifty times;
- plain MSE with a third latent dimension; and
- a fourteen-dimensional identity control.
Each latent is evaluated in two ways. Reconstruction metrics ask how accurately the observed channels return. Linear probes ask whether the latent supports recovery of the three hidden factors. The probe is not a claim that linear decodability equals causal use. Here it is appropriate because the source construction and the optimal model are linear, and we need a simple measure of which factor entered the subspace.
| Configuration | Overall MSE | Alarm MSE | Alarm accuracy | Load R² | Regime R² |
|---|---|---|---|---|---|
| Plain MSE, k=2 | 0.01191 | 0.03303 | 50.0% | 1.000 | 0.996 |
| Alarm-weighted MSE, k=2 | 0.18512 | 0.00046 | 100.0% | 1.000 | 0.002 |
| Plain MSE, k=3 | 0.00726 | 0.00045 | 100.0% | 1.000 | 0.996 |
| Identity control, k=14 | 0.00000 | 0.00000 | 100.0% | 1.000 | 0.996 |
The decisive observation is the factor swap at fixed capacity. The first row is the deceptive success. Aggregate error is small because twelve bulk channels dominate two alarm channels. The second row proves that the alarm was not inaccessible to the architecture. Once its error becomes expensive, it displaces regime at the same capacity. The third row identifies scarcity as the cause of that exchange. One extra dimension lets the model keep all three factors. The fourth row is a negative control: a full-rank identity map reconstructs everything but has made no selective bargain.
What the intervention establishes
The experiment supports a causal statement stronger than “this latent correlates with the alarm”. Capacity is held fixed while the metric changes. The protected distinction appears and a previously preserved factor disappears. Increasing capacity removes the exchange. These matched interventions identify the combination of scarcity and distortion cost as the mechanism in this construction.
The experiment does not establish that feature weighting is always the right remedy. A weight of fifty raises overall unweighted MSE by more than an order of magnitude and destroys regime information. In another workflow, regime may be consequential too. The appropriate response could be a wider code, separate task heads, a multi-objective Pareto analysis, event-aware sampling, a different corruption process or no autoencoder at all.
The mechanism ceases to be a practical problem when downstream relevance already aligns with the training distribution and distortion metric, or when effective capacity is sufficient to preserve every protected distinction. It also does not tell us how a non-convex deep model will allocate features without running the experiment.
Part five
From latent quality to a release decision
The following equipment-monitoring case is synthetic. It is designed to expose the operating decision and should not be read as evidence from a live fleet.
A production evaluation must follow the protected distinction through the complete information path. A manufacturer collects one-second windows from rotating equipment. Each window contains vibration spectra, temperature, load, speed and controller state. Healthy operation dominates the archive. A small precursor appears in a narrow frequency band before one expensive failure mode, but the precursor is weak and not present in every failure. The team wants a compact representation for storage, clustering, retrieval and anomaly triage.
A convolutional autoencoder reaches excellent average spectral MSE. Reconstructions preserve load-dependent harmonics and machine identity. A two-dimensional projection looks smooth. None of those results answers the operational question: does the code preserve the precursor under the load, speed and sensor shifts where a triage decision will depend on it?
The team should vary one causal feature at a time. Match windows on machine, load and speed; alter only precursor presence through controlled simulation, labelled history or signal injection. Measure latent separation and downstream detection at fixed false-alert cost. Reweight or resample the precursor cases while holding architecture fixed. Widen the code while holding the loss fixed. Remove decoder side channels. Evaluate on machines and time periods excluded from training.
The release evidence now distinguishes four possibilities. If the precursor is absent from every code, capacity or objective may be wrong. If it is decodable but the deployed detector ignores it, the consumer is wrong. If it survives in-sample and disappears across sensors, the representation may depend on a shortcut. If reconstruction error itself cannot distinguish injected faults from ordinary changes, it should not be used as the sole anomaly score.
Report the denominator that can hide the failure
Aggregate reconstruction metrics should be decomposed by feature family, event class and operating regime. A mean over all channels can hide a protected distinction exactly as overall accuracy can hide a rare class. Report the count of positive and negative cases, the prevalence used for evaluation, confidence intervals or repeated-run variation, and the threshold selected for action. Where costs are asymmetric, include false-negative and false-positive consequences rather than one undifferentiated error.
For a shared latent, the report should also separate information presence from consumer performance. A high-capacity probe asks whether the code contains recoverable evidence. The deployed restricted consumer asks whether that evidence is usable under its data, latency and complexity limits. Paired interventions ask whether the representation changes for the right reason. These tests answer different questions and should not be collapsed into a single “representation score”.
Finally, record expiry. The training distribution, decoder, quantisation and downstream use can all change after the latent is approved. A contract tied to one decoder version and one population does not silently authorise another. Revalidation should be triggered by material changes to the five fields, not only by a fall in average reconstruction quality.
The bottleneck contract
The article’s practical contribution is a five-field contract. It makes the implicit bargain reviewable before a latent becomes shared infrastructure.
A compact architecture decision record
| Intended use | What reconstruction can establish | Required additional evidence | Common stop condition |
|---|---|---|---|
| Lossy compression | Fidelity under the declared distortion metric | Actual bit rate, entropy model, perceptual and task-specific quality | Width is reported without quantisation or codelength |
| Denoising | Recovery from the sampled corruption process | Coverage of real corruptions, detail preservation and downstream utility | Training noise is unlike operational noise |
| Reusable representation | Information sufficient for the decoder | Matched probes, restricted consumers, shifts and causal interventions | Reconstruction is the only evaluation |
| Anomaly triage | Residual under known normal training data | Support tests, calibrated thresholds, fault injections and miss analysis | Low error is treated as proof of normality |
| Generative sampling | Only reconstruction for a deterministic AE | A probabilistic latent model, sampling tests and generator evaluation | An arbitrary latent prior is sampled without support |
The last row marks the boundary with the next topic. A deterministic autoencoder need not organise latent space so that samples from a simple prior decode into plausible observations. Variational autoencoders add a probabilistic model and a regularised latent objective, creating a different reconstruction and sampling bargain. That deserves its own analysis rather than being smuggled into the plain autoencoder.
Executable artefact
stateDiagram-v2 [*] --> Claim state "The linear case makes the<br/>bargain visible" as Claim state "Thought experiment, the<br/>one-pixel warning" as Test state "Reconstructing the input is<br/>already a value judgement" as Revision Claim --> Test: expose mechanism Test --> Decision: evidence survives Test --> Revision: rival survives Revision --> Claim: narrow or rebuild Decision --> [*]
The autoencoder bottleneck laboratory
The accompanying programme uses only NumPy. It generates public synthetic data, fits the exact rank-k linear solution by singular value decomposition, evaluates factor probes and asserts the positive and negative cases. It is deterministic under the supplied seed.
- Positive case: weighting the alarm preserves it at fixed capacity.
- Negative case: plain MSE looks good overall while alarm recovery remains at chance.
- Capacity control: a third dimension preserves all three source factors.
- Identity control: full rank reconstructs exactly and proves no selective compression.
python3 autoencoder_bottleneck_lab.py
Assumptions: Python 3.10 or later and NumPy. Expected final line: All causal checks passed.
View the complete runnable Python programme
#!/usr/bin/env python3
"""A deterministic bottleneck-allocation lab for Paper 50.
The experiment uses a rank-k linear autoencoder. With squared reconstruction
loss, its optimum is the same principal subspace found by PCA. Feature weights
change the distortion metric, so the weighted model is fitted by scaling each
feature before the singular-value decomposition.
Synthetic factors
-----------------
load : high variance, operationally relevant
regime : medium variance, benign in this worked experiment
alarm : low amplitude, decision-critical
A two-dimensional bottleneck cannot preserve all three independent factors.
The lab asks which factor the objective pays to keep.
Requirements: Python 3.10+ and NumPy.
Run: python3 autoencoder_bottleneck_lab.py
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Iterable
import numpy as np
@dataclass(frozen=True)
class Dataset:
x: np.ndarray
alarm: np.ndarray
load: np.ndarray
regime: np.ndarray
@dataclass(frozen=True)
class LinearAutoencoder:
mean: np.ndarray
scale: np.ndarray
basis: np.ndarray
def encode(self, x: np.ndarray) -> np.ndarray:
"""Map observations to the rank-k latent code."""
return ((x - self.mean) * self.scale) @ self.basis
def reconstruct(self, x: np.ndarray) -> np.ndarray:
"""Decode observations after passage through the latent code."""
z = self.encode(x)
return (z @ self.basis.T) / self.scale + self.mean
@dataclass(frozen=True)
class Metrics:
overall_mse: float
bulk_mse: float
alarm_mse: float
alarm_accuracy: float
load_r2: float
regime_r2: float
def make_dataset(n: int = 6_000, seed: int = 7) -> Dataset:
"""Create 14 observed features from three independent hidden factors."""
rng = np.random.default_rng(seed)
load = rng.normal(0.0, 3.0, size=n)
regime = rng.normal(0.0, 1.0, size=n)
alarm = rng.integers(0, 2, size=n) * 2 - 1
# Twelve high-variance channels carry mixtures of load and regime.
mixtures = (
(1.0, 0.2), (0.9, -0.3), (-0.8, 0.4), (0.7, 0.7),
(-0.6, -0.5), (0.5, -0.9), (1.1, 0.1), (-1.0, 0.2),
(0.8, -0.2), (-0.7, 0.3), (0.6, 0.5), (-0.5, -0.4),
)
columns = [
a * load + b * regime + rng.normal(0.0, 0.1, size=n)
for a, b in mixtures
]
# Two low-amplitude channels carry the decision-critical alarm bit.
columns.append(0.18 * alarm + rng.normal(0.0, 0.03, size=n))
columns.append(-0.18 * alarm + rng.normal(0.0, 0.03, size=n))
return Dataset(
x=np.stack(columns, axis=1),
alarm=alarm.astype(float),
load=load,
regime=regime,
)
def fit_autoencoder(
x_train: np.ndarray,
latent_dim: int,
feature_weights: np.ndarray | None = None,
) -> LinearAutoencoder:
"""Fit the exact rank-k linear autoencoder for a weighted MSE metric."""
if latent_dim < 1 or latent_dim > x_train.shape[1]:
raise ValueError("latent_dim must be between 1 and the input dimension")
weights = (
np.ones(x_train.shape[1], dtype=float)
if feature_weights is None
else np.asarray(feature_weights, dtype=float)
)
if weights.shape != (x_train.shape[1],) or np.any(weights <= 0):
raise ValueError("feature_weights must be one positive value per feature")
mean = x_train.mean(axis=0)
scale = np.sqrt(weights)
scaled = (x_train - mean) * scale
_, _, vt = np.linalg.svd(scaled, full_matrices=False)
basis = vt[:latent_dim].T
return LinearAutoencoder(mean=mean, scale=scale, basis=basis)
def fit_ridge(z: np.ndarray, y: np.ndarray, l2: float = 1e-8) -> np.ndarray:
"""Fit a tiny linear probe using closed-form ridge regression."""
design = np.column_stack((np.ones(len(z)), z))
penalty = l2 * np.eye(design.shape[1])
penalty[0, 0] = 0.0
return np.linalg.solve(design.T @ design + penalty, design.T @ y)
def predict_ridge(z: np.ndarray, coefficients: np.ndarray) -> np.ndarray:
design = np.column_stack((np.ones(len(z)), z))
return design @ coefficients
def r2_score(y: np.ndarray, prediction: np.ndarray) -> float:
residual = np.sum((y - prediction) ** 2)
total = np.sum((y - y.mean()) ** 2)
return 1.0 - residual / total
def evaluate(
model: LinearAutoencoder,
train: Dataset,
test: Dataset,
) -> Metrics:
reconstruction = model.reconstruct(test.x)
z_train = model.encode(train.x)
z_test = model.encode(test.x)
alarm_probe = fit_ridge(z_train, train.alarm)
alarm_prediction = np.where(
predict_ridge(z_test, alarm_probe) >= 0.0, 1.0, -1.0
)
load_probe = fit_ridge(z_train, train.load)
regime_probe = fit_ridge(z_train, train.regime)
return Metrics(
overall_mse=float(np.mean((reconstruction - test.x) ** 2)),
bulk_mse=float(np.mean((reconstruction[:, :12] - test.x[:, :12]) ** 2)),
alarm_mse=float(np.mean((reconstruction[:, 12:] - test.x[:, 12:]) ** 2)),
alarm_accuracy=float(np.mean(alarm_prediction == test.alarm)),
load_r2=r2_score(test.load, predict_ridge(z_test, load_probe)),
regime_r2=r2_score(test.regime, predict_ridge(z_test, regime_probe)),
)
def split(data: Dataset, n_train: int = 4_000) -> tuple[Dataset, Dataset]:
def take(rows: slice) -> Dataset:
return Dataset(
x=data.x[rows],
alarm=data.alarm[rows],
load=data.load[rows],
regime=data.regime[rows],
)
return take(slice(0, n_train)), take(slice(n_train, None))
def weighted_alarm_metric(weight: float, dimension: int = 14) -> np.ndarray:
weights = np.ones(dimension, dtype=float)
weights[-2:] = weight
return weights
def print_table(rows: Iterable[tuple[str, Metrics]]) -> None:
print(
"configuration overall MSE alarm MSE alarm acc "
"load R² regime R²"
)
print("-" * 86)
for name, m in rows:
print(
f"{name:29s} {m.overall_mse:11.5f} {m.alarm_mse:9.5f} "
f"{m.alarm_accuracy:8.1%} {m.load_r2:7.3f} {m.regime_r2:9.3f}"
)
def main() -> None:
data = make_dataset()
train, test = split(data)
configurations = {
"plain MSE, k=2": fit_autoencoder(train.x, latent_dim=2),
"alarm-weighted MSE, k=2": fit_autoencoder(
train.x,
latent_dim=2,
feature_weights=weighted_alarm_metric(50.0),
),
"plain MSE, k=3": fit_autoencoder(train.x, latent_dim=3),
"identity control, k=14": fit_autoencoder(train.x, latent_dim=14),
}
results = {name: evaluate(model, train, test) for name, model in configurations.items()}
print_table(results.items())
print("\nLoss-weight sweep at fixed k=2")
print("alarm weight alarm accuracy regime R²")
print("---------------------------------------")
for weight in (1, 10, 20, 30, 40, 50, 100):
model = fit_autoencoder(
train.x,
latent_dim=2,
feature_weights=weighted_alarm_metric(float(weight)),
)
metric = evaluate(model, train, test)
print(f"{weight:12d} {metric.alarm_accuracy:14.1%} {metric.regime_r2:9.3f}")
# Positive and negative cases make the intended causal claim executable.
plain = results["plain MSE, k=2"]
weighted = results["alarm-weighted MSE, k=2"]
wider = results["plain MSE, k=3"]
identity = results["identity control, k=14"]
assert plain.overall_mse < 0.02, "negative case should look good on average MSE"
assert plain.alarm_accuracy < 0.60, "plain loss should erase the low-amplitude alarm"
assert weighted.alarm_accuracy > 0.99, "weighted distortion should protect the alarm"
assert weighted.regime_r2 < 0.05, "fixed capacity must pay by dropping another factor"
assert wider.alarm_accuracy > 0.99 and wider.regime_r2 > 0.99, (
"a wider bottleneck should preserve all three factors"
)
assert identity.overall_mse < 1e-20, "full-rank control should reconstruct almost exactly"
print("\nAll causal checks passed.")
if __name__ == "__main__":
main()
View the expected console output
configuration overall MSE alarm MSE alarm acc load R² regime R²
--------------------------------------------------------------------------------------
plain MSE, k=2 0.01191 0.03303 50.0% 1.000 0.996
alarm-weighted MSE, k=2 0.18512 0.00046 100.0% 1.000 0.002
plain MSE, k=3 0.00726 0.00045 100.0% 1.000 0.996
identity control, k=14 0.00000 0.00000 100.0% 1.000 0.996
Loss-weight sweep at fixed k=2
alarm weight alarm accuracy regime R²
---------------------------------------
1 50.0% 0.996
10 50.2% 0.996
20 50.5% 0.996
30 51.3% 0.995
40 100.0% 0.008
50 100.0% 0.002
100 100.0% 0.001
All causal checks passed.How to extend the lab without weakening it
A nonlinear extension should preserve the causal controls. Use repeated seeds, but do not replace matched interventions with a seed average. Add a decoder-capacity sweep to detect bypass. Quantise the latent and measure actual codelength if compression is claimed. Replace linear probes with the restricted consumer intended for deployment, then include a higher-capacity probe as an information check. Create paired examples that differ only in a protected factor and test whether the representation response survives declared shifts.
For image or audio data, report distortion under several relevant metrics rather than selecting the one that flatters the model. For anomaly use, add out-of-support points specifically designed to fall inside the autoencoder’s reconstruction set. For a shared embedding, test every downstream use separately and record which contract version authorised each one.
Compact glossary
- Autoencoder
- An encoder-decoder pair trained to reconstruct a target, often the input itself or a clean version of a corrupted input.
- Latent code
- The intermediate representation produced by the encoder and consumed, directly or indirectly, by the decoder.
- Distortion
- The declared cost of a mismatch between source and reconstruction. Different metrics define different acceptable errors.
- Rate
- The information or coding budget. It may be bits, expected codelength or a principled proxy, but is not automatically latent width.
- Protected distinction
- A difference between inputs or world states that a declared downstream decision must still be able to recover.
- Side channel
- Information reaching the decoder outside the nominal latent, such as skips, metadata, autoregressive context or hyperpriors.
Choose the error you are willing to buy
An autoencoder is attractive because its target seems to arrive for free. The input supervises itself, the architecture has a tidy hourglass and the reconstruction offers something visible to inspect. The cost is that relevance becomes implicit. When capacity binds, the optimiser buys the largest reduction in the distortion it can see. It does not reserve space for a distinction because a future reviewer, controller or operator will care about the consequence.
The changed decision is simple: never approve a latent for reuse on reconstruction evidence alone. Record the training distribution, effective rate, distortion metric, decoder and side channels, then name the protected distinctions. Run a loss-swap experiment at fixed capacity. Run a capacity sweep at fixed loss. Use matched cases that vary one consequential feature. Evaluate the actual downstream consumer and a stronger probe. Inject shifts and out-of-support examples.
This discipline does not diminish autoencoders. It tells us where their power comes from. A plain linear autoencoder makes a variance bargain. A denoising autoencoder makes a corruption bargain. A masked autoencoder makes a context-prediction bargain. A learned codec makes an explicit rate-distortion bargain. Each can be excellent when the bargain matches the job and when the evidence is collected at the boundary where the representation will be used.
The failure is to treat compression as wisdom. Compression is selective forgetting under a cost function. A defensible design chooses that cost, measures what was forgotten and keeps the right to widen, reweight, reroute or reject the bottleneck when consequence says the bargain was wrong.
sequenceDiagram participant Q as Question participant M as Mechanism participant E as Evidence participant D as Decision Q->>M: The alarm that reconstructed away M->>E: The linear case makes the bargain visible E-->>M: compare rival explanations E->>D: Sources and evidence boundaries D-->>Q: revise scope or act
Sources and evidence boundaries
- H. Bourlard and Y. Kamp, “Auto-association by multilayer perceptrons and singular value decomposition”, Biological Cybernetics, 1988; and P. Baldi and K. Hornik, “Neural networks and principal component analysis”, 1989. Primary theoretical sources for the standard linear autoencoder relationship.
- G. E. Hinton and R. R. Salakhutdinov, “Reducing the Dimensionality of Data with Neural Networks”, Science, 2006. Primary empirical demonstration of deep nonlinear autoencoders on the reported datasets.
- P. Vincent et al., “Extracting and Composing Robust Features with Denoising Autoencoders”, ICML, 2008. Primary evidence for the denoising objective and reported downstream results.
- S. Rifai et al., “Learning invariant features through local space contraction”, ICML, 2011. Primary source for the contractive penalty.
- G. Alain and Y. Bengio, “What Regularized Auto-Encoders Learn from the Data-Generating Distribution”, JMLR, 2014. Conditional theoretical analysis of regularised reconstruction and the data-density score.
- C. E. Shannon, “Coding Theorems for a Discrete Source With a Fidelity Criterion”, 1959. Primary foundation for rate-distortion with a declared fidelity criterion.
- N. Tishby, F. C. Pereira and W. Bialek, “The Information Bottleneck Method”. Primary formulation of compression relative to a relevance variable.
- R. A. Amjad and B. C. Geiger, “Learning Representations for Neural Network-Based Classification Using the Information Bottleneck Principle”, IEEE TPAMI, 2020. Primary limitation result for deterministic networks and bijection-invariant objectives.
- J. Ballé et al., “Variational Image Compression with a Scale Hyperprior”, ICLR, 2018. Primary learned-compression result illustrating jointly modelled side information and rate-distortion.
- Y. Blau and T. Michaeli, “The Perception-Distortion Tradeoff”, CVPR, 2018. Primary theory and experiments for image restoration; not treated as a theorem about every latent representation.
- F. Locatello et al., “Challenging Common Assumptions in the Unsupervised Learning of Disentangled Representations”, ICML, 2019. Primary impossibility and large-scale empirical study.
- K. He et al., “Masked Autoencoders Are Scalable Vision Learners”, CVPR, 2022. Primary counterexample showing strong representations from a deliberately structured reconstruction task.
- L. D’Amato, G. L. Lancia and G. Pezzulo, “The geometry of efficient codes”, PLOS Computational Biology, 2025. Peer-reviewed VAE experiments on capacity, data frequency and task objectives in a controlled environment.
- G. Strano et al., “How Neural Losses Shape VAE Latents”, 2026. Recent preprint; used only for its reported VAE experiments and marked as provisional.
- R. Bouman and T. Heskes, “Autoencoders for Anomaly Detection are Unreliable”, 2025. Preprint supplying theoretical and empirical counterexamples to reconstruction-error normality assumptions.