Concepts / PCA as a Representation Method

PCA as a Representation Method

Dictionary learning creates a feature vocabulary for data that may not have an obvious vocabulary.

  • Programming

From Raw Values to Useful Features

An image may be presented to a learning algorithm as a long list of pixel values. Those values are the input, but they do not automatically form the most useful description for predicting a label. Dictionary learning addresses this gap by searching for reusable features, sometimes called words or atoms, and representing each instance through those learned features.

RepresentationWhat its coordinates describeHow the features are obtained
Raw inputOriginal input values, such as pixel valuesProvided directly with the instance
Learned dictionary representationReusable features that describe the instanceDiscovered by a learning algorithm

The idea is related to text processing. A document can be represented by coordinates indicating which dictionary words occur in it. Text already supplies the dictionary. Images and other complicated data do not come with an equally direct vocabulary, so dictionary learning tries to discover a useful collection of features instead.

used as inputused as inputRaw inputpixel valuesLearned featuresreusable atomsLabel predictionraw coordinatesLabel predictionfeature coordinates
How does describing an instance with learned features differ from listing its original input values?

Tracing an Auto-Encoder

An auto-encoder learns two functions. The encoder, written as ψ, maps an input from the original d-dimensional space into a k-dimensional representation. The decoder, written as φ, maps that representation back into the original space. The encoder therefore produces the code, while the decoder uses the code to reconstruct the input.

xψ(x)representationφ(ψ(x))Input xd-dimensionalEncoder ψmaps to k dimensionsCodedictionary coordinatesDecoder φmaps backReconstructionφ(ψ(x))
How does data move from the original input through a compact representation and back to a reconstruction?

Following One Input Through the Pair

Suppose an input image enters an auto-encoder. Trace the role of each stage without assuming that the image is reconstructed perfectly.

Encode: The encoder ψ receives the input in its original space and produces a representation in the learned k-dimensional space.

Represent: The resulting coordinates indicate how the input is described by the learned representation.

Decode: The decoder φ receives those coordinates and maps them back into the original input space.

Compare: Learning evaluates the difference between the original input and the decoder's reconstruction, using total squared reconstruction difference.

The encoder chooses a representation and the decoder tests whether that representation preserves enough information to rebuild the input.

For a collection of inputs, learning seeks encoder and decoder functions that make the total squared difference between each original input and its reconstruction small. This objective encourages the code to retain information that the decoder needs for rebuilding the input.

Why Reconstruction Needs Constraints

SetupReconstruction resultRepresentation result
Unconstrained functions with k equal to dCan be perfect if both functions return their inputsDoes not necessarily provide a meaningful restriction or transformation
Restricted encoder and decoderMust rebuild the input while obeying the restrictionIs encouraged to capture useful reusable structure

Reconstruction alone is not a sufficient definition of a useful representation. If k equals d and the encoder and decoder simply return their inputs, the reconstruction is perfect, but the representation has not provided a meaningful restriction or transformation. The functions must therefore be constrained in some way so that copying every input is not the easiest solution.

copyunchanged inputreconstructencoderestricted codereconstructInputInputIdentity encoderreturns inputRestricted encoderlearns a codeIdentity decoderreturns codeRestricted decoderrebuilds from codePerfect copyno useful restrictionUseful reconstructioncode preserves structure
What changes when an encoder–decoder pair can copy the input freely instead of being restricted?

Sparse Codes and Dictionary Atoms

A sparse representation has many zero entries and only a limited number of nonzero entries. In dictionary learning, sparsity means that an instance uses only a small number of dictionary elements to describe itself.

The encoder decides which dictionary coordinates are active. The decoder then combines the corresponding dictionary atoms using the values in those active coordinates. The resulting reconstruction is useful when a compact code preserves enough information about the input.

encodeactive coordinatesc1c20weighted contributionweighted contributionno active contributioncombineInput instancexAtom Acoefficient c1Encoderselects coordinatesAtom Bcoefficient c2Sparse codefew nonzero coefficientsAtom Czero coefficientDecodercombines active atomsReconstructionrebuilt input
How does one input become a weighted combination of learned dictionary atoms, and what do the coefficients mean?

A Small Sparse Representation

Imagine that an input is encoded with three dictionary coordinates. The first coordinate has coefficient c1, the second has coefficient c2, and the third is zero. Trace the reconstruction.

Select: The encoder marks the first two dictionary coordinates as active and leaves the third coordinate inactive.

Weight: The active coordinates carry coefficients c1 and c2. These coefficients specify the contributions used by the decoder.

Combine: The decoder combines the first atom weighted by c1 with the second atom weighted by c2. The third atom contributes nothing because its coefficient is zero.

Reconstruct: The combined result is the decoder's reconstruction of the input.

The input is represented through a small set of active atoms rather than through every available dictionary coordinate.

The K-Means Connection

A first dictionary-learning attempt is to cluster the training instances. Each cluster acts like a dictionary word, and an input receives an indicator for its assigned cluster. This representation is very sparse because only one coordinate is active.

In k-means, the encoder produces exactly one nonzero coordinate identifying the closest centroid. A natural extension permits at most s nonzero coordinates instead of exactly one. The decoder can then combine the corresponding dictionary atoms using their representation values.

Common Reasoning Mistakes

  • Treating the learned dictionary as if it were a vocabulary supplied in advance.

    Text supplies a natural dictionary, but images do not come with an equally direct vocabulary.

    Fix: Explain that dictionary learning searches for reusable features when meaningful entries are not obvious beforehand.

  • Assuming that every cluster member receives a different representation.

    A simple cluster representation gives every member of one cluster the same dictionary representation.

    Fix: Recognize that this can force a linear predictor to assign the same target value to all instances in that cluster.

  • Concluding that perfect reconstruction automatically means useful learning.

    The pair can reconstruct perfectly without providing a meaningful restriction or transformation.

    Fix: Ask what restriction prevents the functions from copying every input.

  • Confusing sparsity with using every dictionary atom weakly.

    A sparse representation has many zero entries and only a limited number of nonzero entries.

    Fix: Focus on the small active set selected by the encoder.

  • Describing sparse coding as identical to k-means.

    K-means uses one active indicator, while the extended sparse construction permits at most s active coordinates.

    Fix: State whether the representation selects one centroid or a small set of dictionary atoms.

Practice and Summary

MEDIUM

An encoder produces a representation with many zero coordinates and a few nonzero coordinates. Explain what the nonzero coordinates mean, what the decoder does with them, and how this differs from the one-active-coordinate representation used by k-means.

Hints
  • Start with the role of the encoder.
  • Then describe how the decoder combines dictionary atoms.
  • Finally compare a small active set with a single active indicator.
  1. Dictionary learning creates a feature vocabulary for data that lacks an obvious vocabulary. An auto-encoder learns an encoder that produces a representation and a decoder that reconstructs the input from it. Reconstruction error encourages information preservation, but restrictions are necessary to prevent simple copying. Sparse codes use only a few active dictionary atoms, and k-means appears as the special case in which exactly one coordinate identifies the selected centroid.

Key Takeaways

  • Raw input coordinates are not always the most useful features for prediction.
  • Dictionary learning discovers reusable features, or atoms, and represents instances through them.
  • An encoder maps an input into a representation, while a decoder maps that representation back into the original space.
  • Reconstruction error must be combined with restrictions so the auto-encoder cannot simply copy its input.
  • Sparse coding generalizes k-means from one active centroid indicator to a small set of active dictionary atoms.