AI Wiki中文/EN

Contractive autoencoders: penalize local sensitivity

收缩自编码器

Derive the sigmoid encoder Jacobian, train tied weights and distinguish local robustness from global contraction.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Start with the problem

If a tiny input perturbation causes a large code change, the representation may be fragile. A contractive autoencoder directly penalizes how sensitive its encoder is near training examples, while reconstruction discourages throwing away everything.

Rifai and colleagues formulate this as a squared Jacobian-norm penalty. Denoising autoencoders pursue robustness through corrupted inputs instead. This chapter computes the derivative penalty itself, including the parameter-gradient terms that are easy to miss.

Definitions and derivation

Use a sigmoid encoder with d inputs and k hidden units, and a linear decoder tied to the same matrix W:

h=σ(W⊤x+b),x^=Wh+c,∂hj∂xi=hj(1−hj)Wij,∥Jh(x)∥F2=∑j[hj(1−hj)]2∥W:j∥2.h=\sigma(W^\top x+b),\quad \widehat x=Wh+c,\qquad \frac{\partial h_j}{\partial x_i}=h_j(1-h_j)W_{ij},\quad \|J_h(x)\|_F^2=\sum_j[h_j(1-h_j)]^2\|W_{:j}\|^2.

The Jacobian has k rows and d columns. Its Frobenius norm sums every squared partial derivative. A small norm makes first-order code changes small near that input: for a small perturbation δ, the leading change is Jδ, bounded by the Frobenius norm times ∥δ∥. This is a local, first-order statement; finite perturbations also involve curvature.

Average the penalty over the training table and add reconstruction:

L=12n∑s∥x^s−xs∥2+λΩ,Ω=1n∑s∥Jh(xs)∥F2.L=\frac1{2n}\sum_s\|\widehat x_s-x_s\|^2+\lambda\Omega, \qquad \Omega=\frac1n\sum_s\|J_h(x_s)\|_F^2.

A small average does not bound the Jacobian at every possible input, so it does not establish a global Lipschitz constant below one. The word contractive here names a training preference, not a proved global contraction mapping.

For a linear encoder, the input Jacobian is simply its weight matrix, so the penalty reduces to squared weight norm. For sigmoid, small derivatives can also arise from saturation even when weights are not small. Thus the penalty depends on both parameters and training inputs. Differentiating it requires two terms:

∂Ω∂Wij=2Wijn∑srsj2+2∥W:j∥2n∑sxsirsj2(1−2hsj),rsj=hsj(1−hsj).\frac{\partial\Omega}{\partial W_{ij}}= \frac{2W_{ij}}n\sum_s r_{sj}^2+ \frac{2\|W_{:j}\|^2}n\sum_s x_{si}r_{sj}^2(1-2h_{sj}), \qquad r_{sj}=h_{sj}(1-h_{sj}).

The first comes directly from the column norm, the second from the activation slopes. Hidden biases receive the second pathway too. Omitting either pathway gives the wrong objective gradient. Reconstruction with tied weights also contributes through both the encoder use of W and the decoder use of W. The implementation accumulates all these contributions before a simultaneous update.

Our four input corners are centered, the hidden code has three units, and there are eleven parameters: six tied weights, three hidden biases and two decoder biases. No noise is sampled. This separates contractive regularization from the stochastic corruption objective in the denoising chapter.

Run the calculation

Complete Python 3.12 / NumPy 1.26.4 program:

import numpy as np

X=np.array([[-1.,-1],[-1,1],[1,-1],[1,1]])


def initial():return np.r_[np.array([[.2,-.3,.1],[.4,.2,-.2]]).ravel(),np.zeros(3),np.zeros(2)]


def objective(theta,penalty=.1):
    t=np.asarray(theta,dtype=float)
    if t.shape!=(11,) or not np.isfinite(t).all() or not np.isfinite(penalty) or penalty<0:raise ValueError('Use 11 finite tied-weight parameters and a nonnegative penalty.')
    w=t[:6].reshape(2,3);b=t[6:9];c=t[9:11];h=np.exp(-np.logaddexp(0,-(X@w+b)));slope=h*(1-h);norm2=np.sum(w*w,axis=0);error=h@w.T+c-X
    reconstruction=.5*np.sum(error**2)/len(X);jacobian=np.mean(np.sum(slope**2*norm2,axis=1))
    gz=(error@w/len(X))*slope+penalty*2*slope**2*(1-2*h)*norm2/len(X)
    gw=X.T@gz+error.T@h/len(X)+penalty*2*w*np.mean(slope**2,axis=0)
    return float(reconstruction+penalty*jacobian),np.r_[gw.ravel(),gz.sum(axis=0),error.mean(axis=0)],float(reconstruction),float(jacobian)


def encode(x,theta):
    w=theta[:6].reshape(2,3);return np.exp(-np.logaddexp(0,-(np.asarray(x)@w+theta[6:9])))


def train(penalty):
    t=initial()
    for _ in range(2500):t-=.1*objective(t,penalty)[1]
    return t,objective(t,penalty)


if __name__=='__main__':
    for penalty in (0.,1.):
        t,(loss,g,reconstruction,jac)=train(penalty);print('penalty',penalty,'reconstruction',round(reconstruction,9),'mean encoder Jacobian squared norm',round(jac,9),'objective',round(loss,9))
    t=initial();eps=1e-5;x=X[0];numeric=np.column_stack([(encode(x+eps*np.eye(2)[k],t)-encode(x-eps*np.eye(2)[k],t))/(2*eps) for k in range(2)]);h=encode(x,t);exact=(h*(1-h))[:,None]*t[:6].reshape(2,3).T;print('input Jacobian finite-difference error',float(np.max(np.abs(exact-numeric))))

Actual output:

penalty 0.0 reconstruction 9.68e-07 mean encoder Jacobian squared norm 0.237417094 objective 9.68e-07
penalty 1.0 reconstruction 0.002130435 mean encoder Jacobian squared norm 0.062739363 objective 0.064869798
input Jacobian finite-difference error 4.140812692732254e-12

After 2,500 updates from the same initialization, λ=0 yields reconstruction loss about 9.68×10⁻⁷ and average squared encoder-Jacobian norm 0.237417094. At λ=1, the corresponding values are 0.002130435 and 0.062739363. The example trades some reconstruction accuracy for reduced measured sensitivity. The independent input finite-difference discrepancy is about 4.14×10⁻¹².

These numbers concern four training points and a fixed small model; they are not adversarial-robustness certificates. At all-zero weights and biases, the code is constant and the centered table has reconstruction loss one with zero Jacobian penalty. In this symmetric setup that is also a stationary point. Reconstruction makes it costly, but does not make every initialization escape it.

For a dense sigmoid encoder, the displayed Jacobian norm can be evaluated from activations and column norms in O(ndk) overall training work, without storing a full Jacobian for each example. General deep encoders may need more expensive exact derivatives or explicitly approximate estimators.

When the method fails

Sensitivity should be measured in meaningful input units. Rescaling a coordinate changes derivatives with respect to that coordinate, so preprocessing changes what the penalty means. Suppressing every direction may also remove distinctions needed by the task; useful robustness should preserve relevant variation.

A strongly saturating encoder can have a small local Jacobian while changing substantially elsewhere. Report reconstruction and sensitivity separately, test perturbations at relevant scales, and evaluate downstream utility. Compare against denoising and sparse alternatives under matched capacity and training budgets.

Exercises with answers

  1. What is penalized: the decoder Jacobian or the encoder Jacobian?

Answer 1: The encoder Jacobian with respect to its input in this objective.

  1. Why is this not just weight decay for sigmoid?

Answer 2: Activation slopes depend on inputs and saturation, so the Jacobian norm is data-dependent.

  1. Does a small training average prove global contraction?

Answer 3: No. It neither bounds all inputs nor controls finite nonlinear changes everywhere.

  1. What two uses of tied W contribute reconstruction gradients?

Answer 4: W appears in the encoder preactivation and again in the decoder, so both paths contribute.

Sources and next steps

Rifai et al. physical pages 2–3 define the Jacobian penalty, its local interpretation, the full objective and its relation to weight decay and denoising. Vincent et al. physical page 9 defines the corruption-based alternative. Our tied-weight gradient and zero-weight counterexample are independently derived. Continue with Jacobian matrices and sparse autoencoders.

Make a prediction, then check

What can a small training-set Jacobian penalty establish by itself?

Choose one answer

Learning objectives

  • Differentiate the explicit sigmoid Jacobian penalty.
  • Distinguish local average sensitivity from global robustness.

Prerequisites & connections

Explore related knowledge →

References

  1. Contractive Auto-Encoders: Explicit Invariance During Feature Extraction
    Salah Rifai; Pascal Vincent; Xavier Muller; Xavier Glorot; Yoshua Bengio · 2011
  2. Stacked Denoising Autoencoders: Learning Useful Representations in a Deep Network with a Local Denoising Criterion
    Pascal Vincent; Hugo Larochelle; Isabelle Lajoie; Yoshua Bengio; Pierre-Antoine Manzagol · 2010

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-07 · Codex single-AI-author technical check: primary-source scope, explicit assumptions, original calculations, independent mathematical references and bilingual tests; not independent human or second-agent review.

  • Single-AI-author technical check: bounded primary-source reading, explicit assumptions, original calculations, runnable examples and matching bilingual equations, code and exercises. Not an independent human or second-agent review.
  • Four focused CPython 3.12.4 checks passed per chapter: independent finite differences, exact covariance/binomial references, queue transitions, stopped versus full gradients, batch-normalization derivatives and collapse/rank counterexamples as applicable. All ten programs use NumPy 1.26.4. This scoped final record supersedes the generic carried-over checklist in the frozen metadata; original drafts are retained.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
  • Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.