Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Pattern recognition approaches

An organized survey of the main pattern-recognition approaches (statistical, template, structural/syntactic, neural and instance-based), their assumptions, decision rules (Bayes, likelihood-ratio, distance-based), pros/cons and guidance for selecting methods.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Pattern recognition approaches tell an engineer how to design a system that maps raw measurements (images, signals, sensor vectors) into labels or structured outputs. Choosing the right approach determines accuracy, training data needs, computational cost and robustness in applications like OCR, biometric recognition, fault detection and speech recognition.

Key ideas

Start with plain definitions (I will bold each term when defined):

  • Pattern recognition: the task of assigning a discrete label or structured description to an observed input x using a decision rule based on features or models. (Units: n/a.)
  • Supervised learning: learning a decision rule from labeled examples (x, y). Assumes training labels are correct. Use when labeled data is available.
  • Unsupervised learning: finding structure (clusters, density, low-dim embeddings) in unlabeled x. Assumes data arise from underlying groups or manifolds.
  • Semi-supervised learning: combining labeled and unlabeled data assuming unlabeled data help reveal structure.
  • Parametric method: assumes a fixed form with a finite set of parameters (e.g., Gaussian with mean and covariance). Accuracy depends on model correctness.
  • Non-parametric method: does not fix a small set of parameters; complexity grows with data (e.g., k-NN, Parzen windows/kernel density estimation). Better flexibility, more data needed.
  • Generative model: models class-conditional density p(x | y) and class prior p(y). Good for missing data and data synthesis.
  • Discriminative model: models posterior p(y | x) or decision boundary directly (e.g., logistic regression, SVM). Often better for classification accuracy given same model complexity.
  • Instance-based (memory-based) methods: store training instances and classify new points by comparing to stored instances (e.g., nearest neighbour).
  • Template matching: compare input to stored templates using a similarity or distance measure (e.g., cross-correlation as a similarity; sum of squared differences, SSD, as a dissimilarity where lower is better). Works when patterns are aligned and low intra-class variability.
  • Syntactic/structural methods: represent patterns as structured objects (strings, graphs, trees) and use grammars or graph matching. Useful when parts and relations matter (e.g., handwritten characters built from strokes).
  • Neural networks: parameterized function approximators (layers of neurons with activation functions) trained by optimization (backprop). They can be seen as discriminative or generative depending on architecture.

Core theorem and decision rule (assumptions stated):

  • Bayes optimal classifier (minimum error): If true class-conditional densities p(x | y) and priors p(y) are known, then the decision rule that minimizes the probability of classification error is to choose the class with the largest posterior p(y | x).

    • Assumptions: exact p(x | y) and p(y) known; 0-1 loss (error count) criterion.
    • Proof sketch (standard university derivation): For two-class problem y in {ω1, ω2}, probability of error at x if choose ω1 is p(ω2 | x). To minimize conditional error at x choose class with smaller p(other | x). This generalizes to multiple classes by picking arg max_y p(y | x).
  • Likelihood ratio test (binary, equal costs): For two classes ω1 and ω2, with known p(x|ω1) and p(x|ω2), the Bayes rule is equivalent to comparing the likelihood ratio Λ(x) = p(x|ω1) / p(x|ω2) against threshold η = p(ω2)/p(ω1) (if equal misclassification costs).

    • Assumptions: known class-conditionals and priors; equal misclassification cost unless cost factor included.

Approach taxonomy (what you pick and why):

  • Statistical/probabilistic (generative): estimate p(x|y) and p(y) then use Bayes decision. Good when good density models exist, allows uncertainty estimates and missing-data handling. Related topics: Bayesian decision theory, Maximum likelihood and Bayesian parameter estimation, Error estimation and ROC curves.
  • Discriminative (direct): model p(y|x) or decision boundary (logistic regression, SVM, neural nets). Good when classification accuracy is primary and modeling p(x) is hard.
  • Instance/template-based: k-NN, template matching (cross-correlation, SSD). Simple, few assumptions, good with lots of data or low variability. Related topics: Distance measures and distance-based classifiers, Template matching and dynamic programming.
  • Structural/syntactic: use grammars, graphs, or rules to capture parts and relations. Good when structure is key (e.g., shapes composed of strokes). Related topics: Syntactic pattern recognition with grammars, Graph-based structural representation.
  • Neural and deep learning: flexible function approximators that can learn features and classifiers jointly. Data hungry, computationally expensive, but state-of-the-art on many tasks. Related topics: Boltzmann learning, Pattern representation and feature extraction.
  • Hybrid approaches: combine e.g., generative + discriminative, or structural parsing followed by statistical classification.

What to draw in an exam when asked to illustrate approaches:

  • Draw a box labelled “Input x” → branch to 5 boxes: “Template matching”, “Statistical models”, “Syntactic/structural”, “Instance-based (k-NN)”, “Neural/deep networks”. For each box list 2 assumptions (e.g., templates: alignment; statistical: parametric form).
  • For Bayes decision draw two curves proportional to the posteriors, e.g., p(x|ω1) p(ω1) and p(x|ω2) p(ω2), on the x-axis; mark where they cross (posteriors equal) and draw the vertical decision boundary at that x. If priors are equal, this reduces to the crossing of p(x|ω1) and p(x|ω2).

Formulas

p(y | x) = p(x | y) · p(y) / p(x) — p(y | x): posterior probability of class y given x (unitless). p(x | y): class-conditional probability mass (discrete x, unitless) or probability density (continuous x, units inverse to x). p(y): prior probability (unitless). p(x): evidence (probability mass or density with the same units as p(x | y)). Applies when using Bayes rule for classification.

y_hat(x) = arg max_y p(y | x) — y_hat(x): Bayes classifier decision (unitless). Use when minimizing 0-1 classification error and posteriors known.

Λ(x) = p(x | ω1) / p(x | ω2) — Λ(x): likelihood ratio (unitless). Use in two-class likelihood ratio test.

Λ(x) ⋚ η where η = [(λ(1|2) - λ(2|2)) / (λ(2|1) - λ(1|1))] · [p(ω2) / p(ω1)] — general threshold with misclassification costs λ(i|j) = cost of deciding i when the true class is j (unitless). Decide ω1 if Λ(x) > η, else ω2. Use when costs and/or priors are unequal.

d_E(x, m) = sqrt(Σ_i (x_i - m_i)^2) — Euclidean distance between vector x and model m (same units as components of x). Use in nearest-neighbour and prototype classifiers. Also, Mahalanobis distance: d_M^2(x, m) = (x - m)^T Σ^{-1} (x - m) — unitless and appropriate when feature correlations/variances matter; use in Gaussian classifiers and LDA.

C(x, t) = Σ_i x_i t_i — dot-product correlation between normalized vectors x and template t (unitless if normalized). Use in template matching (equivalent to cosine similarity if normalized).

R(δ) = E[L(y, δ(x))] = ∫ Σ_y L(y, δ(x)) p(x, y) dx — expected risk of decision rule δ under loss L. Units: expected loss units. Use in Bayes decision theory (minimize R).

Worked examples

  1. Model answer: Compare statistical (generative) vs syntactic (structural) approaches and give when to use each. (Exam-style answer of ~250–300 words)
  • Start: Define both approaches clearly.
    • Statistical (generative): model p(x|y) and p(y). Often parametric (Gaussian) or non-parametric (Parzen). Assumes class variation can be captured by probability densities.
    • Syntactic (structural): represent patterns by discrete primitives and relations (graphs/strings), use grammars or graph matching.
  • Comparison points (each with 2–3 lines):
    • Data type: statistical works with fixed-length numeric feature vectors; syntactic works with variable-length, structured objects (stroke sequences, graphs).
    • Assumptions: statistical assumes randomness described by densities; syntactic assumes compositional rules and symbolic primitives.
    • Strengths: statistical gives probabilistic outputs and handles noise well; syntactic captures structural constraints and part relationships.
    • Weaknesses: statistical may fail when structure matters; syntactic struggles with noise and continuous variability.
  • When to choose: If input can be described by features and many labeled examples exist, use statistical/discriminative methods (see Bayesian decision theory, Maximum likelihood). If pattern is naturally described by parts and relations (e.g., chemical structures, handwritten characters with stroke order), use syntactic/graph-based methods and possibly combine with statistical scoring.
  • Conclude: often hybrid pipelines (structural parsing + statistical classification of parsed components) give best results.
  1. Model answer: Given small labelled dataset of 2D points from two classes with obvious clusters, choose and justify an approach (model-answer steps).
  • Step 1: Inspect data: if clusters are compact and separable, instance-based k-NN or prototype (mean) with Euclidean distance is suitable.
  • Step 2: If classes appear Gaussian-shaped, estimate mean μ_k and covariance Σ_k and use Gaussian generative classifier (compute p(x|ω_k) and apply Bayes). Write formula for multivariate Gaussian and plug estimates (MLE). For class k: p(x|ω_k) = (1 / [(2π)^{d/2} |Σ_k|^{1/2}]) · exp(−0.5 · (x − μ_k)^T Σ_k^{−1} (x − μ_k)); with MLE estimates μ_k = (1/n_k) Σ_{i:y_i=k} x_i and Σ_k = (1/n_k) Σ_{i:y_i=k} (x_i − μ_k)(x_i − μ_k)^T.
  • Step 3: If data are scarce and dimensionality low, prefer parametric Gaussian (lower variance of estimate). If many samples and irregular cluster shapes, prefer k-NN (non-parametric).
  • Final recommendation: For two small clusters and low noise, 1-NN or 3-NN with Euclidean distance; if Gaussian assumptions seem satisfied, use Fisher’s linear discriminant or Gaussian Bayes.
  1. Short derivation (exam question): Show that choosing class with maximum posterior minimizes 0-1 loss. (Model derivation)
  • For fixed x, expected conditional loss if choose y' is Σ_y L(y, y') p(y | x). For 0-1 loss L(y, y') = 0 if y=y' else 1, this becomes 1 - p(y' | x). Minimizing over y' is equivalent to maximizing p(y' | x). Hence pick arg max_y p(y | x). QED.

Common mistakes

  • Thinking discriminative models always need less data; they often need similar amounts but avoid modeling p(x).
  • Using template matching when large intra-class variability exists (templates must be aligned and invariant transformations handled).
  • Forgetting cost factors in Bayes decision rule — equal priors and equal costs are not automatic.
  • Calling a neural network generative when it is only discriminative (need explicit generative architecture).
  • Ignoring the curse of dimensionality: high-dimensional raw features can make distance-based and density-based methods fail unless you reduce dimension or regularize (e.g., PCA/LDA, metric learning).

For your exam

Kinds of questions:

  • Definitions and short notes: define supervised/unsupervised, parametric/non-parametric, generative/discriminative; include assumptions and examples.
  • Derivations: derive Bayes decision rule, likelihood ratio test, show posterior maximizes conditional accuracy, derive k-NN error bound sketch (e.g., asymptotically R_1NN ≤ 2 R*, where R* is Bayes error).
  • Numericals: compute MAP decision given two Gaussians and priors, compute Euclidean distances for k-NN, compute correlation for template matching.
  • Programs: small Python to implement k-NN or template matching (see related topic implementations in Distance measures and distance-based classifiers).
  • Diagrams: draw class-conditional densities and decision boundary; draw pipeline boxes for hybrid approach.

What a full-marks answer includes:

  • Clear definitions of all technical terms used (bold them if writing notes), explicit assumptions, step-by-step derivations with intermediate steps, units where relevant, one or two brief examples or sketches, and a short concluding recommendation where choice between approaches is required.

Quick check

  1. Give the Bayes decision rule for minimum error in one sentence.
  2. Name two advantages of discriminative models over generative models.
  3. When is template matching appropriate? Answers: 1) Choose the class y that maximizes p(y | x). 2) They often yield better classification accuracy for the same model complexity and they do not require modeling p(x). 3) When patterns are well aligned, low intra-class variability, and similarity measure is reliable (e.g., OCR of segmented characters).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?