This page is not available in every language. Missing translations are disabled in the language selector.

Modern AI Core Algorithms Guide: From Mathematical Foundations to Engineering Trade-offs

A comprehensive breakdown of 27 essential algorithms in modern machine learning and LLM engineering: statistical baselines, gradient boosting trees, HNSW vector search, AdamW, self-supervised MAE, DPO/PPO alignment, and diffusion models with decision trees and tuning rules.

In enterprise AI and data science engineering, selecting the right algorithm determines model performance ceilings, training compute budgets, and end-to-end inference latency. While traditional methods (like early AdaBoost, introductory SARSA, or generic genetic algorithms) still hold pedagogical value, production AI systems have coalesced around a focused set of modern, highly scalable architectures.

The AI Algorithms Cheat Sheet catalogs a dense reference index of these techniques. This guide explores the mathematical mechanisms, practical trade-offs, and production engineering rules across 27 hardcore algorithms that drive modern industry deployments.


The 6 Pillars of Modern AI Algorithms

flowchart TD
    AI["Modern AI Core Algorithm Architecture (27 Hardcore Algorithms)"]

    AI --> C1["1. Supervised Baselines & Statistical Learning"]
    AI --> C2["2. Ensemble Methods & Tabular Boosting"]
    AI --> C3["3. Clustering, Dimensionality & Vector Search"]
    AI --> C4["4. Deep Architectures & Optimizers"]
    AI --> C5["5. Self-Supervised Learning & LLM Alignment"]
    AI --> C6["6. Reinforcement Learning & Generative Models"]

    C1 --> A1["01 Linear Regression"] & A2["02 Logistic Regression"] & A3["03 CART Decision Trees"] & A4["04 Support Vector Machines"] & A5["05 K-Nearest Neighbors"]
    C2 --> A6["06 Naive Bayes"] & A7["07 Random Forests"] & A8["08 Gradient Boosted Trees (XGB/LGBM)"]
    C3 --> A9["09 K-Means Clustering"] & A10["10 Hierarchical Clustering"] & A11["11 DBSCAN"] & A12["12 PCA"] & A13["13 t-SNE / UMAP"] & A14["14 HNSW / IVF-PQ Vector Search"]
    C4 --> A15["15 Gradient Optimizers (AdamW/SGD)"] & A16["16 Multi-Layer Perceptrons"] & A17["17 ResNet / CNNs"] & A18["18 LSTMs & GRUs"] & A19["19 Graph Neural Networks"] & A20["20 Transformers"]
    C5 --> A21["21 Masked Autoencoders (MAE)"] & A22["22 Deep Q-Networks (DQN)"] & A23["23 Proximal Policy Optimization (PPO)"] & A24["24 Direct Preference Optimization (DPO)"]
    C6 --> A25["25 Variational Autoencoders (VAE)"] & A26["26 Generative Adversarial Networks (GAN)"] & A27["27 Diffusion Models"]

Module 1: Supervised Baselines & Statistical Learning

Supervised algorithms map inputs to labeled targets: continuous predictions correspond to regression, while discrete category assignments correspond to classification.

01. Linear Regression

  • Mathematical Core: Assumes a linear relationship between features and targets, minimizing the residual sum of squares: $$\hat{y} = \mathbf{w}^T \mathbf{x} + b, \quad \mathcal{L}{\text{MSE}} = \frac{1}{2m} \sum{i=1}^m (y^{(i)} - \hat{y}^{(i)})^2$$
  • Solution Paths:
    • Closed-Form (Normal Equation): $\mathbf{w} = (\mathbf{X}^T \mathbf{X})^{-1} \mathbf{X}^T \mathbf{y}$, suited for low-dimensional, full-rank feature spaces.
    • Numerical (Gradient Descent): Iteratively updates parameters using batch or stochastic gradient descent for large datasets.
  • Trade-offs: Fast and transparent with clear weight interpretability; however, it cannot model non-linear interactions without manual feature engineering and is vulnerable to multicollinearity and extreme outliers.
  • Production Tip: Apply L1 regularization (Lasso) for automatic feature sparsity or L2 regularization (Ridge) under strong feature collinearity.

02. Logistic Regression

  • Mathematical Core: Maps linear log-odds into probabilities bounded in $[0, 1]$ via the Sigmoid function: $$P(y=1|\mathbf{x}) = \sigma(\mathbf{w}^T \mathbf{x} + b) = \frac{1}{1 + e^{-(\mathbf{w}^T \mathbf{x} + b)}}$$ Parameters are estimated by maximizing the Bernoulli likelihood using binary cross-entropy loss: $$\mathcal{L} = -\frac{1}{m} \sum_{i=1}^m \left[ y^{(i)} \log \hat{y}^{(i)} + (1 - y^{(i)}) \log (1 - \hat{y}^{(i)}) \right]$$
  • Trade-offs: Naturally yields calibrated posterior probabilities. Supports billion-scale sparse features via online optimization (such as FTRL), achieving sub-millisecond serving latency. However, it requires extensive upfront feature binning and cross-feature engineering.

03. Decision Trees (CART)

  • Mathematical Core: Top-down greedy binary recursive splitting. Classification trees minimize Gini impurity, whereas regression trees minimize variance reduction: $$\text{Gini}(D) = 1 - \sum_{k=1}^K p_k^2, \quad \Delta \text{Gini} = \text{Gini}(D) - \frac{|D_L|}{|D|}\text{Gini}(D_L) - \frac{|D_R|}{|D|}\text{Gini}(D_R)$$
  • Trade-offs: Produces human-auditable If-Else decision rules critical for regulated domains (such as underwriting and medical audits). Naturally handles missing values and mixed feature types without normalization. Individual trees suffer from high variance and are prone to overfitting unless bounded by max_depth or cost-complexity pruning.

04. Support Vector Machines (SVM)

  • Mathematical Core: Solves for a maximum-margin separating hyperplane, formulated via Lagrange duality: $$\min_{\mathbf{w}, b} \frac{1}{2} |\mathbf{w}|^2 + C \sum_{i=1}^m \xi_i \quad \text{s.t.} \quad y^{(i)}(\mathbf{w}^T \phi(\mathbf{x}^{(i)}) + b) \ge 1 - \xi_i$$
  • Kernel Trick: Uses Mercer kernels (such as Gaussian RBF $K(\mathbf{x}_i, \mathbf{x}_j) = \exp(-\gamma |\mathbf{x}_i - \mathbf{x}_j|^2)$) to project points into infinite-dimensional spaces without explicit coordinate calculation.
  • Trade-offs: Strong mathematical generalization guarantees for small-sample, high-dimensional spaces. Training computational complexity scales at $O(N^2) \sim O(N^3)$, making un-approximated SVMs impractical for datasets exceeding 100,000 samples.

05. K-Nearest Neighbors (KNN)

  • Mathematical Core: A non-parametric lazy learner. Stores the training set and computes distance metrics (Euclidean, Manhattan, or Cosine) across the feature space during query time, taking a majority vote for classification or mean value for regression.
  • Trade-offs: Highly adaptive non-linear boundaries with zero training time. However, query evaluation is memory-intensive and computationally expensive ($O(N \cdot d)$ without indexing). Suffers severely from the curse of dimensionality.

Module 2: Ensemble Methods & Tabular Boosting

Ensemble architectures combine multiple weak learners to suppress variance (Bagging) or bias (Boosting).

06. Naive Bayes

  • Core Assumption: Assumes conditional independence between feature dimensions given target class $y$: $$P(y|\mathbf{x}) = \frac{P(y) P(\mathbf{x}|y)}{P(\mathbf{x})} \propto P(y) \prod_{j=1}^d P(x_j|y)$$
  • Trade-offs: Extreme training efficiency requiring only frequency counts and probability tables. Highly effective baseline for high-dimensional sparse text classification. When strong feature correlations exist, posterior probability estimates become skewed.

07. Random Forests

  • Mechanism: Implements Bootstrap Aggregation (Bagging) across hundreds of unpruned decision trees:
    1. Sample Diversity: Draws bootstrap subsamples with replacement for each individual tree.
    2. Feature Diversity: Selects a random subset of features ($\sqrt{d}$) at every node split.
    3. Parallel Voting: Aggregates independent tree predictions via averaging or majority vote.
  • Trade-offs: Greatly suppresses variance without increasing individual tree bias. Highly resilient to noise, handles high-dimensional inputs effortlessly, and yields native feature importance rankings.

08. Gradient Boosted Decision Trees (GBDT / XGBoost / LightGBM)

  • Mechanism: Additive model where each successive tree fits the negative gradient (pseudo-residuals) of the cumulative ensemble loss.
  • Engineering Milestones:
    • Second-Order Taylor Approximation (XGBoost): Leverages both first-order gradients and second-order Hessians for precise step sizing.
    • Histogram Binning & EFB (LightGBM): Groups continuous values into discrete bins, combining Gradient-based One-Side Sampling (GOSS) and Exclusive Feature Bundling (EFB) to cut training time and RAM consumption by 5x.
  • Industry Position: Consistently outperforms deep neural networks across structured tabular business datasets in Kaggle competitions and production recommendation pipelines.

Unsupervised techniques uncover hidden geometric clusters, compress manifold representations, and power vector retrieval for Large Language Model RAG pipelines.

09. K-Means Clustering

  • Optimization Objective: Minimizes intra-cluster variance (inertia): $$J = \sum_{k=1}^K \sum_{\mathbf{x} \in C_k} |\mathbf{x} - \boldsymbol{\mu}_k|^2$$
  • Production Rules: Requires predefined cluster count $K$ (selected via elbow curve or silhouette analysis). Use K-Means++ initialization to prevent local optima traps, and MiniBatchKMeans for multi-million row datasets.

10. Hierarchical Clustering

  • Mechanism: Builds nested agglomerative tree hierarchies (dendrograms) by iteratively pairing closest clusters under Single, Complete, or Average linkage distance criteria.
  • Trade-offs: Eliminates the need to guess cluster count in advance. Yields clear visual interpretability at the expense of $O(N^2)$ memory and $O(N^3)$ computational overhead.

11. DBSCAN (Density-Based Spatial Clustering)

  • Mechanism: Expands clusters along density-reachable chains from core points (having at least $\text{MinPts}$ neighbors within radius $\epsilon$). Points outside density boundaries are tagged as noise ($-1$).
  • Trade-offs: Discovers arbitrary, non-convex shapes (such as concentric rings or crescent distributions) and automatically identifies outliers. Struggles when data exhibits widely differing density thresholds across regions.

12. Principal Component Analysis (PCA)

  • Mathematical Core: Computes eigenvalues of the empirical covariance matrix or uses Singular Value Decomposition (SVD) to project high-dimensional data onto orthogonal axes that maximize variance.
  • Trade-offs: Optimal linear transformation for compression, decorrelation, and noise reduction. Incapable of unfolding non-linear manifolds.

13. t-SNE & UMAP

  • Manifold Comparison:
    • t-SNE: Models pairwise similarities as Gaussian distributions in high dimensions and Student-t distributions in low dimensions, minimizing KL divergence via gradient descent.
    • UMAP: Grounds dimensionality reduction in Riemannian geometry and fuzzy simplicial sets. Runs 10x faster than t-SNE while better preserving both local and global topology.
  • Use Case: Dimensionality reduction strictly for 2D/3D exploratory cluster visualization.

14. HNSW & IVF-PQ (Approximate Nearest Neighbors - ANN)

  • The Engine of Modern RAG: In 1536-dimensional embedding spaces, exhaustive linear scan ($O(N)$) fails under high concurrency.
  • Architectures:
    • HNSW (Hierarchical Navigable Small World): Inspired by skip-lists, builds multi-layer proximity graphs. Top layers have long-range edges for coarse hopping; bottom layers perform dense local exploration, achieving $O(\log N)$ logarithmic retrieval speed.
    • IVF-PQ (Inverted File with Product Quantization): Partitions high-dimensional vectors into segmented sub-vectors, quantizing them to cluster centroids to compress memory by 90% and support billion-scale vector indices.

Module 4: Deep Architectures & Optimizers

15. Optimizers: SGD with Momentum & AdamW

  • Evolution:
    • Momentum SGD: Accumulates exponentially decaying historical gradients, dampening oscillations along high-curvature ravines: $$\mathbf{v}t = \gamma \mathbf{v}{t-1} + \eta \nabla_\theta \mathcal{L}(\theta)$$
    • AdamW (Decoupled Weight Decay): The standard optimizer for LLMs and Transformers. Decouples $L_2$ weight decay regularization directly from gradient momentum updates, avoiding distortion caused by adaptive gradient scaling.

16. Multi-Layer Perceptrons (MLP)

  • Structure: Fully connected layers with non-linear activation functions (ReLU, GELU, SwiGLU).
  • Core Engine: The Backpropagation algorithm, evaluating chain-rule derivatives of loss functions to update weight matrices $\mathbf{W}$.

17. Convolutional Networks & ResNet

  • Key Inventions:
    1. Local Receptive Fields: Focuses feature extraction on spatial neighborhoods.
    2. Weight Sharing: Enforces translation equivariance while slashing parameter counts.
    3. Residual Shortcuts (ResNet): Introduces identity mappings $F(x) + x$, solving vanishing gradients in deep networks exceeding 100 layers.

18. LSTMs & GRUs

  • Mechanism: Maintains a persistent cell state $C_t$ controlled by input, forget, and output gates: $$C_t = f_t \odot C_{t-1} + i_t \odot \tilde{C}_t$$
  • Trade-offs: Converts multiplicative recurrence into additive updates, mitigating vanishing gradients over long sequences. Remains a high-throughput, resource-efficient option for time-series and financial ticker forecasting.

19. Graph Neural Networks (GCN / GAT)

  • Message Passing: Propagates and aggregates feature representations across non-Euclidean graph topologies (social networks, transaction anti-fraud graphs, molecular bonds). GAT incorporates self-attention weights to dynamically prioritize critical neighbor connections.

20. Transformers

  • Paradigm Shift: Eliminates recurrence and convolution entirely in favor of Scaled Dot-Product Attention: $$\text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V$$
  • Advantages: Complete parallelization across sequence lengths on modern GPU hardware, coupled with multi-head projections that attend to diverse semantic relationships simultaneously. Foundation of modern LLMs (GPT-4, Gemini, Claude) and Vision Transformers (ViT).

Module 5: Self-Supervised Learning & LLM Alignment

21. Masked Autoencoders (MAE) & Contrastive Learning

  • Self-Supervised Milestones: Extracts representations from raw unlabeled data.
    • MAE: Randomly masks out 75% of visual image patches, feeding only the 25% visible patches to an encoder and training a lightweight decoder to reconstruct missing pixels. Learns rich spatial priors with minimal compute.
    • SimCLR & InfoNCE: Maximizes mutual information between augmented views of identical samples while pushing negative samples apart.

22. Deep Q-Networks (DQN)

  • Reinforcement Learning Breakthrough: Replaces discrete tabular lookups with deep neural estimators $Q(s, a; \theta)$ for high-dimensional state spaces.
  • Stabilization Techniques:
    1. Experience Replay: Stores transitions in a rolling circular buffer, breaking temporal correlations via random mini-batch sampling.
    2. Target Networks: Maintains frozen copies of network weights to decouple temporal-difference target evaluation from active weight updates.

23. Proximal Policy Optimization (PPO)

  • Policy Gradient Benchmark: Regulates policy updates via an importance sampling ratio $r_t(\theta) = \frac{\pi_\theta(a_t|s_t)}{\pi_{\theta_{\text{old}}}(a_t|s_t)}$ bounded by a clipping function $\text{clip}(r_t(\theta), 1-\epsilon, 1+\epsilon)$. Prevents destructive policy divergence during Reinforcement Learning from Human Feedback (RLHF).

24. Direct Preference Optimization (DPO)

  • The Modern Standard for LLM Alignment:
    • Traditional RLHF requires training an independent Reward Model, followed by unstable PPO Actor-Critic loops requiring four concurrent models in GPU memory.
    • The DPO Insight: Mathematically proves that the optimal reward function can be expressed implicitly via closed-form policy probabilities. DPO skips the reward model entirely, optimizing directly on pairwise preference completions $(y_w, y_l)$ using binary cross-entropy: $$\mathcal{L}{\text{DPO}}(\theta; \pi{\text{ref}}) = -\mathbb{E}{(x, y_w, y_l)} \left[ \log \sigma \left( \beta \log \frac{\pi\theta(y_w|x)}{\pi_{\text{ref}}(y_w|x)} - \beta \log \frac{\pi_\theta(y_l|x)}{\pi_{\text{ref}}(y_l|x)} \right) \right]$$
  • Impact: The primary alignment framework for open-source foundation models (such as LLaMA-3, Mistral, and Qwen).

Module 6: Generative Models

25. Variational Autoencoders (VAE)

  • Extends standard autoencoders into probabilistic generative models by mapping inputs to latent mean $\mu(\mathbf{x})$ and variance $\sigma(\mathbf{x})$ distributions. Employs the reparameterization trick ($\mathbf{z} = \mu + \sigma \odot \epsilon$) to allow gradient backpropagation through stochastic sampling.

26. Generative Adversarial Networks (GAN)

  • Formulates generative modeling as a minimax zero-sum game between a Generator $G$ synthesizing samples and a Discriminator $D$ distinguishing synthetic from authentic data: $$\min_G \max_D V(D, G) = \mathbb{E}{\mathbf{x}\sim p{\text{data}}}[\log D(\mathbf{x})] + \mathbb{E}_{\mathbf{z}\sim p_z}[\log(1 - D(G(\mathbf{z})))]$$
  • Exceptional for single-step, low-latency image super-resolution, face enhancement, and real-time stylization (StyleGAN).

27. Diffusion Models (DDPM / Latent Diffusion)

  • Two-Phase Architecture:
    • Forward Diffusion: Systematically degrades image signal over $T$ discrete timesteps by injecting Gaussian noise until data becomes pure isotropic noise.
    • Reverse Denoising: Trains a U-Net or Diffusion Transformer (DiT) to iteratively predict and subtract noise increments at each step.
  • Delivers far superior training stability compared to GANs, with massive sample diversity powering Midjourney, Stable Diffusion, and Sora.

Engineering Decision Tree

flowchart TD
    Start["Algorithm Selection"] --> D1{"Labeled Ground Truth Available?"}

    D1 -- "Unlabeled Data" --> D2{"Core Objective?"}
    D2 -- "Discover Clusters" --> Cluster{"Data Geometry & Volume?"}
    Cluster -- "Spherical / Known K" --> K1["09. K-Means"]
    Cluster -- "Arbitrary Shapes / Outliers" --> K2["11. DBSCAN"]
    Cluster -- "Hierarchical Taxonomy" --> K3["10. Hierarchical Clustering"]
    D2 -- "Dimensionality / Vector Search" --> Reduc{"Goal?"}
    Reduc -- "Linear Variance Compression" --> R1["12. PCA"]
    Reduc -- "2D/3D Exploratory Viz" --> R2["13. t-SNE / UMAP"]
    Reduc -- "Enterprise RAG Vector DB" --> R3["14. HNSW / IVF-PQ"]
    D2 -- "Representation & Generation" --> Gen{"Pretraining or Synthesis?"}
    Gen -- "Self-Supervised Pretraining" --> G1["21. Masked Autoencoders (MAE)"]
    Gen -- "High-Fidelity Image/Video" --> G2["27. Diffusion Models"]
    Gen -- "Low-Latency Real-time Editing" --> G3["26. GAN / 25. VAE"]

    D1 -- "Interactive Environment Decision" --> RL{"Task Type?"}
    RL -- "Discrete State Game Play" --> RL1["22. Deep Q-Networks (DQN)"]
    RL -- "LLM Human Preference Alignment" --> Align{"Infrastructure Capability?"}
    Align -- "Standard Production: Lightweight & Stable" --> AL1["24. Direct Preference Optimization (DPO)"]
    Align -- "Online Dynamic Rewards & Search" --> AL2["23. Proximal Policy Optimization (PPO)"]

    D1 -- "Supervised Target Available" --> D3{"Data Modality?"}
    D3 -- "Structured Tabular Data" --> Tabular{"Interpretability vs Precision?"}
    Tabular -- "Strict Compliance / Whitebox Audit" --> T1["01. Linear / 02. Logistic / 03. Decision Trees"]
    Tabular -- "Maximum Accuracy / Kaggle Grade" --> T2["08. Gradient Boosted Trees (XGB / LGBM)"]
    Tabular -- "Robust Baseline Out of the Box" --> T3["07. Random Forests"]

    D3 -- "Unstructured Multimodal" --> Deep{"Spatial & Temporal Structure?"}
    Deep -- "Visual Spatial Grids" --> DP1["17. ResNet / CNNs"]
    Deep -- "Graph Relational Networks" --> DP2["19. Graph Neural Networks (GCN)"]
    Deep -- "Sequences, Code, Long Text" --> DP3["20. Transformers (with 15. AdamW)"]

3 Production Golden Rules

  1. Tabular Wins with Boosting; Deep Learning Wins with AdamW:
    • For structured tabular data, XGBoost and LightGBM remain the undisputed enterprise baseline.
    • For Transformer and vision architectures, always pair model training with AdamW, using a linear learning rate warmup and cosine decay scheduler to avoid weight explosion.
  2. Anchor Enterprise RAG on HNSW:
    • Lexical keyword search (BM25) cannot resolve contextual semantics. Modern retrieval systems must layer dense vector search on HNSW graphs to guarantee sub-10ms response times at scale.
  3. Prefer DPO over PPO for Alignment:
    • Unless managing complex real-time environment feedback loops, DPO eliminates the fragile dual-model training cycle of traditional RLHF, drastically reducing VRAM overhead while stabilizing convergence.
← Back to Blog Browse Cheat Sheets →