Machine Learning - Mathematical Functions

In statistical learning and neural networks, mathematical transformation functions govern how linear combinations of inputs map to predictions, probabilities, and nonlinear feature representations.

Activation Functions vs. Link Functions

In Generalized Linear Models (GLMs), an input feature vector x=[x1,…,xD]T\mathbf{x} = [x_1, \dots, x_D]^T is combined with weight vector w\mathbf{w} and bias w0w_0 into a linear predictor:

η=wTx+w0\eta = \mathbf{w}^T \mathbf{x} + w_0

The mathematical relationship between the linear predictor η\eta and the conditional expectation of the target variable μ=E[Y∣x]\mu = \mathbb{E}[Y | \mathbf{x}] is defined through two inverse concepts:

  1. Link Function g(μ)g(\mu): Maps the expected value μ\mu into the unbounded linear predictor space: g(μ)=wTx+w0g(\mu) = \mathbf{w}^T \mathbf{x} + w_0
  2. Activation Function f(η)f(\eta): The inverse of the link function, f=g−1f = g^{-1}, mapping the unbounded linear combination back to the target scale: μ=f(η)=f(wTx+w0)\mu = f(\eta) = f(\mathbf{w}^T \mathbf{x} + w_0)
Model Target Distribution Link Function g(μ)g(\mu) Activation Function f(η)f(\eta)
Linear Regression Gaussian N(μ,σ2)\mathcal{N}(\mu, \sigma^2) Identity: g(μ)=μg(\mu) = \mu Identity: f(η)=ηf(\eta) = \eta
Logistic Regression Bernoulli Bern(p)\text{Bern}(p) Logit: g(μ)=ln⁡(μ1−μ)g(\mu) = \ln\left(\frac{\mu}{1 - \mu}\right) Logistic Sigmoid: f(η)=11+e−ηf(\eta) = \frac{1}{1 + e^{-\eta}}
Poisson Regression Poisson Pois(λ)\text{Pois}(\lambda) Log link: g(μ)=ln⁡(μ)g(\mu) = \ln(\mu) Exponential: f(η)=eηf(\eta) = e^\eta

Linear Decision Surfaces

Even when the activation function f(⋅)f(\cdot) is nonlinear (such as sigmoid or step functions), the resulting decision boundary remains a linear hyperplane in feature space:

wTx+w0=constant\mathbf{w}^T \mathbf{x} + w_0 = \text{constant}

Because ff is strictly monotonic, thresholding the probability P(Y=1∣x)≥0.5P(Y=1|\mathbf{x}) \ge 0.5 is equivalent to thresholding the linear argument wTx+w0≥0\mathbf{w}^T \mathbf{x} + w_0 \ge 0.

Logistic Sigmoid

The logistic sigmoid function maps the real line R→(0,1)\mathbb{R} \to (0, 1), interpreting outputs as probabilities:

σ(z)=11+e−z=ez1+ez\sigma(z) = \frac{1}{1 + e^{-z}} = \frac{e^z}{1 + e^z}

Mathematical Properties

  1. Symmetry: σ(−z)=1−σ(z)\sigma(-z) = 1 - \sigma(z)
  2. Derivative: dσ(z)dz=σ(z)(1−σ(z))\frac{d\sigma(z)}{dz} = \sigma(z)(1 - \sigma(z)) The maximum derivative occurs at z=0z = 0, where σ′(0)=0.25\sigma'(0) = 0.25.
  3. Inverse (Logit): σ−1(p)=logit(p)=ln⁡(p1−p)\sigma^{-1}(p) = \text{logit}(p) = \ln\left(\frac{p}{1 - p}\right)
  4. Vanishing Gradient: For ∣z∣≫0|z| \gg 0, σ′(z)→0\sigma'(z) \to 0, causing backpropagated gradients to diminish across deep layers.

Hyperbolic Tangent (tanh⁡\tanh)

The hyperbolic tangent function maps R→(−1,1)\mathbb{R} \to (-1, 1):

tanh⁡(z)=ez−e−zez+e−z=sinh⁡(z)cosh⁡(z)\tanh(z) = \frac{e^z - e^{-z}}{e^z + e^{-z}} = \frac{\sinh(z)}{\cosh(z)}

Relation to Sigmoid & Advantages

tanh⁡(z)=2σ(2z)−1\tanh(z) = 2\sigma(2z) - 1
  • Zero-Centered Output: Outputs have mean close to zero. Unlike sigmoid (whose outputs are strictly positive in (0,1)(0, 1)), zero-centered activations prevent gradient vectors from always pointing in the same direction during backpropagation, improving convergence speed.
  • Derivative: dtanh⁡(z)dz=1−tanh⁡2(z)\frac{d\tanh(z)}{dz} = 1 - \tanh^2(z) Maximum derivative is 1.01.0 at z=0z = 0 (4x steeper than sigmoid).

Softmax Function

Softmax generalizes the binary logistic function to multi-class classification across K≥2K \ge 2 mutually exclusive classes:

Softmax(z)i=ezi∑j=1Kezjfor i=1,…,K\text{Softmax}(\mathbf{z})_i = \frac{e^{z_i}}{\sum_{j=1}^K e^{z_j}} \quad \text{for } i = 1, \dots, K

Properties & Numerical Stability

  1. Probability Distribution: ∑i=1KSoftmax(z)i=1andSoftmax(z)i∈(0,1)\sum_{i=1}^K \text{Softmax}(\mathbf{z})_i = 1 \quad \text{and} \quad \text{Softmax}(\mathbf{z})_i \in (0, 1)
  2. Shift Invariance: For any scalar constant c∈Rc \in \mathbb{R}: ezi−c∑jezj−c=e−cezie−c∑jezj=Softmax(z)i\frac{e^{z_i - c}}{\sum_j e^{z_j - c}} = \frac{e^{-c} e^{z_i}}{e^{-c} \sum_j e^{z_j}} = \text{Softmax}(\mathbf{z})_i In production implementations, setting c=max⁡j(zj)c = \max_j(z_j) prevents numerical overflow (NaN from large exponentials).
  3. Derivative: ∂Softmax(z)i∂zj=Softmax(z)i(δij−Softmax(z)j)\frac{\partial \text{Softmax}(\mathbf{z})_i}{\partial z_j} = \text{Softmax}(\mathbf{z})_i (\delta_{ij} - \text{Softmax}(\mathbf{z})_j) where δij\delta_{ij} is the Kronecker delta (1 if i=ji = j, else 0).

Rectified Linear Unit (ReLU) & Smooth Approximations

ReLU

ReLU(x)=max⁡(0,x)\text{ReLU}(x) = \max(0, x)
  • Computational Efficiency: Evaluated via a single conditional comparison; derivative is either 00 (for x<0x < 0) or 11 (for x>0x > 0).
  • No Saturation for x>0x > 0: Gradient does not vanish for positive inputs, enabling training of very deep architectures.
  • Dying ReLU: Neurons whose pre-activation stays negative across all training examples have zero gradient and permanently deactivate.

Softplus (Smooth ReLU)

Softplus(x)=ln⁡(1+ex)\text{Softplus}(x) = \ln(1 + e^x)

The first derivative of Softplus is analytically identical to the logistic sigmoid:

ddxSoftplus(x)=ex1+ex=σ(x)\frac{d}{dx} \text{Softplus}(x) = \frac{e^x}{1 + e^x} = \sigma(x)

Leaky ReLU & Parametric ReLU (PReLU)

f(x)=max⁡(αx,x)={xif x≥0αxif x<0f(x) = \max(\alpha x, x) = \begin{cases} x & \text{if } x \ge 0 \\ \alpha x & \text{if } x < 0 \end{cases}

Setting small slope α>0\alpha > 0 (typically α=0.01\alpha = 0.01) ensures non-zero gradient everywhere, eliminating the dead neuron issue.