Gaussian Distribution

Overview

A Gaussian distribution, also known as a normal distribution, is a fundamental concept in statistics and probability theory. It is characterized by its distinctive bell-shaped curve, where the central value, or mean (μ), has the highest probability. As we move away from the center, the probability decreases symmetrically. The spread or width of the bell is determined by the standard deviation (σ). The Gaussian distribution is widely used in various fields, including statistics, finance, and machine learning, due to its natural occurrence in many real-world phenomena.

In practical applications, such as predicting the height values of adult female residents of a hypothetical town called Statsville, the Gaussian distribution is often assumed. This assumption allows for the estimation of parameters like the mean and variance using techniques such as maximum likelihood estimation (MLE). Once these parameters are estimated, the Gaussian distribution can be used to predict the probabilities of certain events, such as the likelihood of a height falling within a specific range.

Maximum Likelihood Estimation (MLE)

The process of estimating the parameters of a Gaussian distribution using maximum likelihood estimation involves determining the mean (μ) and variance (σ) from a given set of training data. These parameters are crucial as they define the shape and position of the Gaussian curve. The MLE solutions for a Gaussian distribution coincide with the sample mean and variance, which are calculated directly from the data. This method provides a robust way to predict probabilities for specified ranges, making it a powerful tool in statistical analysis and machine learning.

Log Probability of a Univariate Normal Distribution

The following listing demonstrates how to compute the log probability of a univariate normal distribution using PyTorch, a popular machine learning library. This example illustrates the practical implementation of Gaussian distribution concepts in a programming environment.

Listing 5.3 Log probability of a univariate normal distribution

from torch.distributions import Normal        #1

mu = torch.tensor([0.0], dtype=torch.float)   #2
sigma = torch.tensor([5.0], dtype=torch.float)

uvn_dist = Normal(mu, sigma)                  #3

X = torch.tensor([0.0], dtype=torch.float)    #4

def raw_eval(X, mu, sigma):
    K = 1 / (math.sqrt(2 * math.pi) * sigma)
    E = math.exp( -1 * (X - mu) ** 2 * (1 / (2 * sigma ** 2)))
    return math.log(K * E)

log_prob = uvn_dist.log_prob(X)               #5
raw_eval_log_prob = raw_eval(X, mu, sigma)    #6
assert log_prob == raw_eval_log_prob          #7
#1 Imports a PyTorch univariate normal distribution
#2 Sets the distribution params
#3 Instantiates a univariate normal distribution object
#4 Instantiates a single-point test dataset
#5 Evaluates the probability using PyTorch
#6 Evaluates the probability using the formula
#7 Asserts that the probabilities match

In this code, a univariate normal distribution is created with a mean (μ) of 0.0 and a standard deviation (σ) of 5.0. The log probability of a test point (X) is calculated using both PyTorch's built-in functions and a manual computation, ensuring that the results match. This example highlights the ease of working with Gaussian distributions in modern computational frameworks.