Automatic Differentiation, Gradient Optimization, Regularization, and Maximum Likelihood Classification
Automatic Differentiation and Computational Graphs
All numerical evaluations executed within computational learning systems decompose into sequential elementary operations, such as addition, multiplication, exponentiation, and nonlinear activations. Because the analytical derivatives of each elementary operation are known, automatic differentiation (AD) systematically computes the exact total derivatives of arbitrary composite functions by chaining local gradients. Unlike finite-difference approximations, automatic differentiation introduces zero numerical truncation errors, and unlike symbolic differentiation, it evaluates derivatives directly without generating unwieldy, algebraically expanded symbolic expressions.
Mathematical models in automatic differentiation are formalized as directed acyclic computational graphs. Consider the nonlinear multivariable function y = F(x_1, x_2) = \rexp(x_1 x_2) + \rlog(x_2), defined on the domain . This evaluation breaks down into an ordered series of intermediate variables: , , , v_4 = \rlog(v_2), v_5 = \rexp(v_3), , and finally . Within the computational graph, each node stores its evaluated intermediate scalar value, and directed edges indicate variable dependencies.

Forward-mode automatic differentiation propagates tangent derivatives forward from the primary input nodes toward the terminal output node simultaneously with the evaluation of intermediate functions. To evaluate the partial derivative of the scalar output with respect to an input , each node defines a forward derivative \rdot{v}_i = \frac{\rpartial v_i}{\rpartial x_1}. Seeding the input nodes with respect to gives \rdot{v}_1 = 1 and \rdot{v}_2 = 0. Applying local chain rules sequentially through the graph yields:
v_3 = v_1 v_2 \implies \rdot{v}_3 = v_2 \rdot{v}_1 + v_1 \rdot{v}_2 = x_2(1) + x_1(0) = x_2
v_4 = \rlog(v_2) \implies \rdot{v}_4 = \frac{\rdot{v}_2}{v_2} = \frac{0}{x_2} = 0
v_5 = \rexp(v_3) \implies \rdot{v}_5 = \rexp(v_3) \rdot{v}_3 = x_2 \rexp(x_1 x_2)
v_6 = v_5 + v_4 \implies \rdot{v}_6 = \rdot{v}_5 + \rdot{v}_4 = x_2 \rexp(x_1 x_2)
This yields the derivative \frac{\rpartial y}{\rpartial x_1} = x_2 \rexp(x_1 x_2). Differentiating with respect to requires setting seeds \rdot{v}_1 = 0 and \rdot{v}_2 = 1, which results in \frac{\rpartial y}{\rpartial x_2} = x_1 \rexp(x_1 x_2) + \frac{1}{x_2}. Because each forward sweep isolates one directional derivative, calculating the gradient for input parameters requires independent forward evaluations.
Reverse-mode automatic differentiation reverses the propagation direction, computing adjoint derivatives from the terminal output back toward input variables. The forward evaluation is executed first to compute and store intermediate states through . For every node, its adjoint variable is defined as \rbar{v}_i = \frac{\rpartial y}{\rpartial v_i}, measuring the sensitivity of the final output to perturbations in . The reverse sweep initializes at the final output node with adjoint \rbar{v}_6 = \frac{\rpartial y}{\rpartial v_6} = 1.
Adjoint values propagate backward through intermediate dependencies according to local derivatives:
\rbar{v}_5 = \rbar{v}_6 \frac{\rpartial v_6}{\rpartial v_5} = 1(1) = 1
\rbar{v}_4 = \rbar{v}_6 \frac{\rpartial v_6}{\rpartial v_4} = 1(1) = 1
\rbar{v}_3 = \rbar{v}_5 \frac{\rpartial v_5}{\rpartial v_3} = 1 \times \rexp(v_3) = \rexp(v_3)
Because input variable influences solely through , its adjoint is:
\rbar{v}_1 = \rbar{v}_3 \frac{\rpartial v_3}{\rpartial v_1} = \rexp(v_3) v_2 = x_2 \rexp(x_1 x_2)
Variable branches toward two distinct operations, and . The multivariable chain rule accumulates all downstream contributions:
\rbar{v}_2 = \rbar{v}_3 \frac{\rpartial v_3}{\rpartial v_2} + \rbar{v}_4 \frac{\rpartial v_4}{\rpartial v_2} = v_1 \rexp(v_3) + 1 \times \frac{1}{v_2} = x_1 \rexp(x_1 x_2) + \frac{1}{x_2}
In general computation graphs where node is used by multiple subsequent nodes , its total adjoint is governed by:
\rbar{v}_i = \sum_{j: v_j \text{ uses } v_i} \rbar{v}_j \frac{\rpartial v_j}{\rpartial v_i}
Reverse-mode automatic differentiation calculates the exact gradients with respect to all primary input variables simultaneously in a single reverse sweep, making it the foundational engine for neural network backpropagation.
Gradient Descent Optimization Frameworks
Supervised regression models optimize trainable parameter vectors over a training dataset . For a model prediction , the empirical training objective is defined as the mean squared error loss function:
The true gradient of the training objective across the entire dataset is:
Optimization algorithms differ based on the sample size used to estimate this gradient at each iteration step.
In batch gradient descent (full-batch gradient descent), every parameter update incorporates all training examples. At iteration step , the gradient of the entire empirical loss is calculated at the current parameter position , and parameters update via:
where denotes the learning rate. Batch gradient descent evaluates every training instance using identical parameters , resulting in stable, smooth trajectories across elliptical error contours directly toward local or global minima.
Stochastic gradient descent (SGD) calculates parameter updates using only a single training instance per step (). At iteration , an individual index is sampled uniformly from the index set . The local gradient vector is evaluated as:
Parameters update along this single-sample gradient using learning rate :
Because individual sample loss surfaces differ significantly from the global loss, SGD generates high variance, noisy, erratic parameter trajectories that fluctuate around optimal basins.
Mini-batch gradient descent provides a balanced compromise between batch stability and stochastic efficiency. At step , a random subset containing unique examples is sampled, where . The mini-batch loss is formulated as:
The corresponding parameter update is given by:
All examples within mini-batch are evaluated simultaneously against , and parameters undergo a single update per batch.

An epoch represents one complete pass through the entire training dataset, whereas an update represents a single modification to the parameter vector. When partition size is , the total number of parameter updates per epoch is governed by the ceiling function:
For a representative dataset size of :
Batch gradient descent operates with batch size , yielding exactly update per epoch.
Mini-batch gradient descent configured with produces updates per epoch.
Stochastic gradient descent with produces parameter updates per epoch.
Comparing optimization algorithms purely after an equal number of parameter updates is fundamentally misleading, as the quantity of processed data instances differs by orders of magnitude. Rigorous convergence evaluations must be benchmarked against epochs or cumulative data points processed.
Sequential iterative optimization steps update parameters across iterations according to current model states:
Regularization Methods in Deep Learning
Deep neural networks possess high parametric capacity, predisposing them to overfitting where the model memorizes sample-specific noise rather than underlying data-generating distributions. Regularization techniques impose structural or procedural constraints to preserve out-of-sample generalization.
Norm-based regularization directly modifies the objective function by penalizing the magnitudes of the network weights. For a model with trainable weights , the objective incorporates an penalty:
Here, governs regularization strength. When , this penalty corresponds to regularization (weight decay), penalizing large weight vectors quadratically. When , it corresponds to regularization (Lasso), driving non-critical weights to zero. These norm penalties are applied exclusively to network weights and are never applied to network bias terms.
Early stopping regulates model complexity procedurally rather than altering the objective function. Available data is divided into disjoint training, validation, and test subsets. The training set calculates gradient updates, the validation set monitors generalization and parameter checkpoints, and the test set remains unobserved until final post-training evaluation.
During gradient descent optimization, training loss decreases monotonically across epochs. Validation loss decreases initially, attains a minimum, and subsequently climbs as parameter updates fit idiosyncratic training noise. Early stopping halts training before overfitting degrades generalization.
The early stopping protocol follows five sequential procedural steps:
Train the network for one epoch, corresponding to a single comprehensive pass across the training partition.
Evaluate loss on the validation dataset without updating network parameters.
Save the model parameter vector if the validation loss improves upon the previous best recorded loss.
Terminate optimization if validation loss fails to achieve an improvement for a predetermined window of consecutive epochs, defined as the patience.
Restore and output the parameter checkpoint corresponding to the absolute minimum validation loss recorded throughout optimization.
For parameter vectors monitored across epoch index , the selected optimal checkpoint satisfies:

Early stopping functions as an implicit regularizer by bounding the reachable volume of parameter space from initialization. The test set must never be used to guide early stopping decisions, as doing so introduces information leakage and compromises evaluation integrity.
Dropout provides stochastic regularizing effects during feedforward training iterations. Each neuron within a hidden layer is retained with a probability and set to zero with probability , termed the dropout rate. At each training step, neurons are dropped independently with probability , temporarily excising their forward activations and backward gradient contributions.

Dropping units at random prevents neurons from developing brittle co-adaptations where hidden features rely on the presence of specific counterpart units. Instead, each neuron learns robust features independently, mimicking the ensembling of exponentially many thinned neural sub-networks.
Model Complexity, Generalization, and Hyperparameter Optimization
The expected prediction error of statistical learning models breaks down into squared bias, variance, and irreducible error. Model complexity dictates the trade-off balance between bias and variance.

Underfitting occurs at low model complexity, where restricted functional capacity prevents the model from capturing true input-output relationships. This state displays high squared bias and low variance. Conversely, overfitting occurs at high model complexity, where excessive functional flexibility captures idiosyncratic dataset noise, yielding low bias but severe variance. The optimum model complexity lies at the trough of the total error curve, where the sum of squared bias and variance is minimized.

Plotting error across training epochs reveals similar dynamics. Training error continuously declines toward zero. Validation error exhibits a characteristic U-shaped profile, decreasing initially during the high-bias underfitting regime, reaching an optimal minimum, and subsequently diverging upward as high variance drives overfitting.
Consider an empirical regression setting with input , eight hidden neurons ( through ), and an output neuron . The input layer connects to hidden neurons through the weight vector:
The hidden units connect to the output through the weight vector:

Fitting this architecture against noisy sinusoidal data samples produces a function fit score of . When model capacity is insufficient relative to training progress, the predicted curve flattens relative to true , capturing only coarse macroscopic trends before additional training epochs or hidden units lower the training loss.

Selecting optimal structural configurations—including layer dimensions, learning rates, regularizers, and batch sizes—requires systematic hyperparameter optimization. Standard search strategies include Grid Search, Random Grid Search, and Bayesian Optimization.

Grid search tests configurations across an evenly spaced, coordinate grid within hyperparameter space. While deterministic and simple, it scales exponentially with dimensionality, evaluating redundant points along uninfluential hyperparameter axes without adapting to the underlying loss landscape.
Random grid search samples coordinate evaluations uniformly at random across the bounded hyperparameter space. Given a fixed evaluation budget, random search evaluates far more unique coordinate values along critical hyperparameter dimensions than grid search, yielding superior optimization performance on high-dimensional surfaces with low effective dimensionality.
Bayesian optimization treats hyperparameter evaluation as a black-box global optimization problem. It fits a probabilistic surrogate model (such as a Gaussian process) over prior evaluation points and optimizes an acquisition function to determine subsequent evaluation coordinates. This balances exploration of uncertain regions with exploitation of known minima, converging on optimal hyperparameters with substantially fewer total model evaluations.
Maximum Likelihood Estimation and Classification Frameworks
Maximum likelihood estimation (MLE) is a foundational statistical approach for estimating distribution parameters from empirical data. Unlike forward probability, which computes the likelihood of sample outcomes from known distributions, MLE solves the inverse problem: given observed data samples, infer the unknown probability distribution parameters .
Given independent and identically distributed observations drawn from a density or mass function , the likelihood function is defined as the joint probability of the sample set:
Within this expression, observations are fixed, while parameters vary. Crucially, the likelihood function is not a probability distribution over parameter space; its integral or sum over does not equal unity. The maximum likelihood parameter estimate maximizes the likelihood:
Because the natural logarithm is strictly monotonically increasing, maximizing is equivalent to maximizing the log-likelihood function :
l(\boldsymbol{\theta}) = \rlog(L(\boldsymbol{\theta}; \mathcal{S})) = \sum_{i=1}^n \rlog(p(x_i; \boldsymbol{\theta}))
Taking logarithms converts products into sums, which prevents arithmetic underflow during numerical computation with small probabilities. In machine learning optimization, this is framed as minimizing the negative log-likelihood (NLL):
-l(\boldsymbol{\theta}) = -\sum_{i=1}^n \rlog(p(x_i; \boldsymbol{\theta}))
For binary classification with neural networks, target labels belong to binary classes . The network produces a single scalar logit output , which passes through the logistic sigmoid activation function:
p_i = \sigma(z_i) = \frac{1}{1 + \rexp(-z_i)}
The activated output represents class probabilities:
The conditional probability assigned to observed label is:
This is expressed compactly as a Bernoulli distribution:
The joint likelihood across dataset is:
Taking the negative logarithm yields the binary cross-entropy (BCE) loss:
-l(\boldsymbol{\theta}) = -\sum_{i=1}^n [y_i \rlog(p_i) + (1 - y_i) \rlog(1 - p_i)]
For every training example, only the log-probability of the observed target class contributes to the overall loss and subsequent gradient updates.
Multiclass classification extends this formulation to discrete classes, where target labels satisfy . Target classes are encoded as one-hot vectors , where:
For , one-hot encodings evaluate as:
The network terminal layer contains neurons outputting raw logits . Logits are mapped to normalized class probabilities using the softmax activation function:
p_{ik} = P(Y = k \mid \mathbf{x}_i; \boldsymbol{\theta}) = \frac{\rexp(z_{ik})}{\sum_{j=1}^K \rexp(z_{ij})}
The softmax output satisfies the probability axioms:
For observed class , the conditional probability is . If , the sample contribution is . The total likelihood is:
The corresponding negative log-likelihood is:
-l(\boldsymbol{\theta}) = -\sum_{i=1}^n \rlog(p_{i, y_i})
Using one-hot vector representations, the conditional probability per example is rewritten as:
Taking the negative logarithm over all training examples yields the categorical cross-entropy loss:
-l(\boldsymbol{\theta}) = -\sum_{i=1}^n \sum_{k=1}^K y_{ik} \rlog(p_{ik})
Minimizing categorical cross-entropy via gradient descent maximizes the joint likelihood that the network assigns to the observed multi-class training data.