Mathematics for ML: Overview

Mathematics for ML: Overview

Introduction

Mathematics is extensively used in machine learning and deep learning. One could even say that you might not be able to create a new algorithm if you don't have enough mathematical knowledge. But we don't need to know everything in mathematics to be able to write new algorithm or understand already existing one, we just need to know few topics in great detail. So, let's discuss these topics and their use cases in ML

Linear Algebra

  • Data Representation: Vectors and matrices are used to represent data. Understanding operations like matrix multiplication, transposition, and inversion is crucial for working with datasets.

  • Model Computation: Many ML algorithms, especially those involving deep learning, rely on linear algebra for computations. For example, neural networks involve operations like dot products and matrix multiplications.

  • Image Processing:

    • Affine Transformations: Linear transformations like translation, rotation, scaling, and shearing are represented by affine transformation matrices. These transformations are fundamental in image manipulation, alignment, and augmentation.

    • Homographies: For perspective transformations, homography matrices are used to map points from one plane to another, which is essential in tasks like image stitching and rectification.

    • Feature Matching: Techniques like SIFT and SURF for feature detection and matching use linear algebra for computing descriptors and matching points across images.

    • Projection: Projecting 3D points onto a 2D image plane involves matrix multiplications. Understanding projection matrices is essential for tasks like 3D reconstruction and camera calibration.

    • Camera Models: Camera transformations, including intrinsic and extrinsic parameters, are described using matrices. Linear algebra helps in modeling and understanding the geometry of image formation.

  • Feature Extraction:

    • Eigenvalues and Eigenvectors: Techniques like Principal Component Analysis (PCA) use eigenvalues and eigenvectors to reduce the dimensionality of image data, preserving the most important features while discarding noise.

    • Singular Value Decomposition (SVD): SVD is used for tasks such as image compression, noise reduction, and in algorithms like Latent Semantic Analysis for object recognition.

  • Optimization:

    • Least Squares: Many problems in computer vision, such as finding the best fit line or plane, are solved using least squares optimization, which involves solving linear systems.

    • Energy Minimization: Techniques like Markov Random Fields (MRFs) and Graph Cuts, used for image segmentation and denoising, involve solving optimization problems that are grounded in linear algebra.

Calculus

  • Optimization: Gradient descent, a popular optimization algorithm, uses calculus to minimize the loss function. Calculus helps in understanding how changing the parameters of a model will affect the output.

  • Backpropagation: In neural networks, backpropagation uses derivatives to propagate errors and update weights, which is essential for learning.

  • Understanding Model Behavior:

    • Convexity and Concavity: These properties of functions are important in optimization. A convex loss function ensures that any local minimum is also a global minimum, making optimization more straightforward.

    • Hessian Matrix: The second-order derivatives (Hessian matrix) provide information about the curvature of the loss function, which can help in understanding the nature of the optimization problem (e.g., determining if a critical point is a local minimum, maximum, or saddle point).

  • L1 and L2 Regularization: These techniques add a penalty term to the loss function to prevent overfitting. L1 regularization (lasso) adds the absolute value of the coefficients, while L2 regularization (ridge) adds the squared value. The derivatives of these penalty terms are used to adjust the learning process.

  • Probability Distributions:

    • Probability Density Functions (PDFs): Calculus is used to derive and work with PDFs, which are integral to many probabilistic models in ML.

    • Expectation and Variance: These are key concepts in statistics and ML that involve integration to compute the expected value and variance of random variables.

  • Continuous Optimization Problems:

    • Lagrange Multipliers: This technique is used to find the local maxima and minima of a function subject to equality constraints, which is useful in constrained optimization problems in ML.
  • Support Vector Machines (SVMs):

    • Maximizing the Margin: The optimization problem in SVMs involves maximizing the margin between classes, which requires calculus to solve the dual form of the optimization problem.
  • Gaussian Processes:

    • Covariance Functions: Calculus is used to manipulate covariance functions in Gaussian processes, which are used for regression and classification tasks.
  • Reinforcement Learning:

    • Policy Gradients: These methods involve optimizing the expected reward by taking the gradient of the expected return with respect to the policy parameters.

Probability

Probability is fundamental to machine learning (ML) because it provides a framework for modeling uncertainty, making predictions, and designing algorithms. Many ML models are probabilistic (e.g., Naive Bayes, Hidden Markov Models). Probability theory helps in modeling uncertainty and making predictions.

Here's how probability theory is specifically useful in ML, distinct from statistical methods:

  • Bayesian Inference:

    • Posterior Distribution: In Bayesian inference, probability is used to update beliefs about model parameters based on observed data. The posterior distribution combines the prior distribution and the likelihood of the observed data.

    • Bayes’ Theorem: This theorem provides a way to update the probability estimate for a hypothesis as additional evidence is acquired.

  • Probabilistic Models:

    • Naive Bayes Classifier: This simple yet effective classifier assumes independence between features and uses the joint probability distribution to make predictions.

    • Hidden Markov Models (HMMs): Used for sequence modeling (e.g., speech recognition, part-of-speech tagging), HMMs are based on the probability of hidden states generating observable sequences.

  • Expectation-Maximization (EM) Algorithm:

    • Latent Variables: The EM algorithm is used for models with latent variables. It iteratively finds the maximum likelihood estimates by alternating between estimating the missing data and optimizing the model parameters.
  • Generative Models:

    • Generative Adversarial Networks (GANs): These models involve two neural networks (generator and discriminator) that use probability distributions to generate new data samples that are similar to a given dataset.

    • Variational Autoencoders (VAEs): VAEs use probabilistic encoders and decoders to learn a latent space representation of the data, which is useful for generating new samples and performing unsupervised learning.

  • Markov Chains:

    • Transition Probabilities: Markov chains are used to model stochastic processes where the future state depends only on the current state. This is useful in text generation, weather modeling, and other sequential data tasks.
  • Monte Carlo Methods:

    • Sampling: Monte Carlo methods use random sampling to approximate complex probability distributions and integrals. This is useful for Bayesian inference, reinforcement learning, and uncertainty estimation.
  • Graphical Models:

    • Bayesian Networks: These are directed acyclic graphs that represent the conditional dependencies between random variables. They are used for reasoning under uncertainty and making predictions.

    • Markov Random Fields (MRFs): These are undirected graphical models used for modeling spatial dependencies, often applied in image processing and computer vision.

  • Information Theory:

    • Entropy: Measures the uncertainty or randomness in a random variable. It is used in decision trees (information gain) and to evaluate the efficiency of coding schemes.

    • Mutual Information: Measures the amount of information obtained about one random variable through another random variable. It is used for feature selection and dependency modeling.

  • Reinforcement Learning:

    • Policy and Value Functions: Probabilities are used to model the environment’s response to an agent’s actions and to estimate the expected rewards. Algorithms like Q-learning and policy gradients rely on probability to optimize decision-making.

    • Exploration vs. Exploitation: Probabilistic strategies are used to balance exploration (trying new actions) and exploitation (using known actions) to maximize cumulative rewards.

  • Uncertainty Quantification:

    • Predictive Uncertainty: Probabilistic models provide a measure of confidence in their predictions, which is crucial for applications like autonomous driving and medical diagnosis.

    • Bayesian Neural Networks: These networks incorporate uncertainty in the weights and provide probabilistic predictions, improving robustness and interpretability

Statistics

Statistics is fundamental to machine learning (ML) as it provides the tools and methodologies for analyzing data, making inferences, and validating models.

  • Data Analysis: Understanding the distribution of data, statistical tests, and confidence intervals is essential for analyzing and interpreting data.

    • Descriptive Statistics: Measures like mean, median, mode, variance, and standard deviation summarize data and provide insights into its distribution and variability.

    • Data Visualization: Techniques like histograms, box plots, scatter plots, and correlation matrices help visualize data patterns, relationships, and outliers.

  • Hypothesis Testing: It is one of the most important parts of research. Hypothesis testing in machine learning (ML) involves using statistical methods to determine whether there is enough evidence to support a specific claim or hypothesis about a dataset or model.

    • Statistical Tests: Tests such as t-tests, chi-square tests, ANOVA, and Mann-Whitney U tests help determine if observed differences or relationships in data are statistically significant.

    • P-values and Confidence Intervals: P-values indicate the probability of observing data under a null hypothesis, while confidence intervals provide a range of values within which a population parameter likely lies.

  • Validation and Evaluation: Statistical measures like precision, recall, F1-score, and ROC curves are used to evaluate the performance of models.

    • Cross-Validation: Techniques like k-fold cross-validation and leave-one-out cross-validation estimate the performance of ML models by partitioning data into training and testing sets multiple times.

    • Performance Metrics: Metrics such as accuracy, precision, recall, F1-score, ROC-AUC, and confusion matrices evaluate classification models, while metrics like RMSE, MAE, and R-squared assess regression models.

  • Regression Analysis:

    • Linear Regression: Models the relationship between a dependent variable and one or more independent variables. It helps in predicting outcomes and understanding the strength and nature of relationships.

    • Logistic Regression: Used for binary classification problems, logistic regression models the probability of a binary outcome based on one or more predictor variables.

  • Clustering and Segmentation:

    • K-means Clustering: Partitions data into k clusters based on feature similarity, useful for tasks like customer segmentation, image compression, and anomaly detection.

    • Hierarchical Clustering: Builds a hierarchy of clusters, providing a tree-like structure that shows the arrangement of the clusters at different levels of granularity.

  • Experimental Design:

    • Randomization and Control Groups: Ensures that experiments are designed in a way that minimizes bias and allows for causal inference. Randomization helps distribute confounding factors evenly across treatment groups.

    • A/B Testing: Compares two versions of a product or feature to determine which one performs better, commonly used in marketing, web design, and product development.

  • Resampling Methods:

    • Bootstrap: A method for estimating the distribution of a statistic by resampling with replacement from the data. It’s used to estimate confidence intervals and assess the stability of a model.

    • Jackknife: A resampling technique used to estimate the bias and variance of a statistic by systematically leaving out one observation at a time from the sample set.

  • Time Series Analysis:

    • Decomposition: Splits time series data into trend, seasonal, and residual components to better understand the underlying patterns.

    • Smoothing Techniques: Methods like moving averages and exponential smoothing are used to smooth out short-term fluctuations and highlight longer-term trends.

  • Survival Analysis:

    • Kaplan-Meier Estimator: Estimates the survival function from lifetime data, useful for medical research and reliability engineering.

    • Cox Proportional Hazards Model: A regression model that investigates the effect of several variables on the time a specified event takes to happen.

  • Correlation and Causation:

    • Correlation Analysis: Measures the strength and direction of the linear relationship between two variables using correlation coefficients like Pearson’s and Spearman’s.

    • Causal Inference: Techniques such as instrumental variables, propensity score matching, and regression discontinuity help in identifying causal relationships rather than mere correlations.

  • Handling Missing Data:

    • Imputation: Methods like mean imputation, regression imputation, and multiple imputation are used to handle missing data, which is crucial for maintaining the integrity of the dataset and the validity of the analysis.

    • Data Cleaning: Identifying and correcting errors or inconsistencies in the data to ensure high-quality datasets.

Did you find this article valuable?

Support JYOTI MAURYA TECH BLOG by becoming a sponsor. Any amount is appreciated!