A simplified guide on how to prep up on Mathematics for Artificial Intelligence, Machine Learning and Data Science: Boolean Algebra (Important Pointers only)
Module VI : Boolean Algebra
I. Information Theory.
Information theory, a mathematical framework developed by Claude Shannon in the mid-20th century, quantifies information and provides tools for analyzing communication systems and processes.
It is at the intersection of electronic engineering, mathematics, statistics, computer science, neurobiology, physics, and electrical engineering.
Information:
- Information measures the reduction of uncertainty. When an event is uncertain, the receipt of a message about the event reduces this uncertainty.
- Information is quantified in terms of bits (binary digits).
Abstractly, information can be thought of as the resolution of uncertainty. Shannon's main result, the noisy-channel coding theorem, showed that, in the limit of many channel uses, the rate of information that is asymptotically achievable is equal to the channel capacity, a quantity dependent merely on the statistics of the channel over which the messages are sent.
A third class of information theory codes are cryptographic algorithms (both codes and ciphers). Concepts, methods and results from coding theory and information theory are widely used in cryptography and cryptanalysis, such as the unit ban.
A key measure in information theory is entropy which is a measure of the uncertainty or unpredictability of a random variable.
Joint Entropy:
- Joint entropy of two random variables and is the entropy of their combined system.
- It measures the total uncertainty of the pair .
Conditional Entropy:
- Conditional entropy is the amount of uncertainty remaining about given that is known.
- It is defined as:
Mutual Information:
- Mutual information quantifies the amount of information obtained about one random variable through another random variable.
Relative Entropy (Kullback-Leibler Divergence):
- Relative entropy measures the difference between two probability distributions and
Channel Capacity:
- Channel capacity is the maximum rate at which information can be reliably transmitted over a communication channel.
- It is determined by the channel's noise characteristics and is given by the Shannon-Hartley theorem for a continuous channel:
- Where is the bandwidth, is the signal power, and is the noise power.
Applications
- Data Compression
- Error Correction
- Cryptography
- Machine Learning and Statistics
- Network Information Theory
II. Entropy and Properties.
Entropy is a central concept in information theory that quantifies the amount of uncertainty or unpredictability in a random variable.
For a discrete random variable with possible outcomes and corresponding probabilities , the entropy is defined as:
Entropy is measured in bits when the logarithm is base 2.Properties of Entropy
Non-negativity:
Entropy is always non-negative:
if and only if is a certain event (i.e., one outcome has probability 1 and all others have probability 0).Symmetry:
Entropy is symmetric with respect to the probabilities of the outcomes. The order of outcomes does not affect the value of entropy.Maximum Entropy:
For a random variable with possible outcomes, entropy is maximized when all outcomes are equally likely, i.e., for all .
In this case, the maximum entropy is:Additivity (for Independent Variables):
For two independent random variables and , the joint entropy is the sum of the individual entropies:Subadditivity (for Dependent Variables):
For two random variables and the joint entropy is less than or equal to the sum of the individual entropies:Conditional Entropy:
The conditional entropy is the entropy of given that is known. It quantifies the remaining uncertainty about after knowing :- Conditional entropy is always non-negative: .
Chain Rule:
The entropy of a joint distribution can be decomposed using the chain rule:- This property helps in breaking down complex distributions into simpler parts.
Data Processing Inequality:
If forms a Markov chain, then the mutual information satisfies:- This implies that processing data cannot increase the amount of information.
Eg: Fair Die.
- For a fair six-sided die, the entropy is:
III. Information Gain.
Information gain is a metric used in information theory and machine learning to measure the reduction in entropy or uncertainty about a random variable given the knowledge of another variable .
Information gain is defined as the difference between the entropy of a variable before and after the observation of another variable. For a random variable and an attribute , the information gain is calculated as:
Where:
- is the entropy of .
- is the conditional entropy of given .
Steps to compute
Consider a dataset to predict a binary outcome (e.g., whether a customer will buy a product: Yes/No) based on several attributes (e.g., Age, Income, etc.).
- Calculate the entropy of the target variable :
- For each attribute , calculate the conditional entropy :
- Compute the information gain for each attribute:
- Choose the attribute with the highest information gain to split the dataset.
Eg: Consider the dataset with the following distribution for the target variable :
The entropy is:
If we consider an attribute with values and the conditional entropies are:
And probabilities:
Then the conditional entropy is:
The information gain is:
Repeat this process for other attributes to find the one with the highest information gain for splitting the data.
Properties of Information Gain
Non-negativity: Information gain is always non-negative since knowing more information never increases uncertainty.Applications
- Decision Trees: Information gain is used to select the best attribute to split the data at each node in the tree, such as in algorithms like ID3, C4.5, and CART.
- Feature Selection: In machine learning, information gain helps in selecting the most informative features for building models.
IV. Mutual Information.
Mutual information is a measure from information theory that quantifies the amount of information obtained about one random variable through another random variable. It is a symmetric measure and provides insights into the dependency between two variables.
For two discrete random variables and , the mutual information is defined as:
Where:
- is the joint probability distribution function of and .
- and are the marginal probability distribution functions of and , respectively.
Mutual information measures the reduction in uncertainty of one variable due to the knowledge of another. If and are independent, knowing does not provide any information about , and vice versa, so their mutual information is zero. Conversely, if and are strongly dependent, knowing reduces the uncertainty about , resulting in higher mutual information.
Relationship with Entropy
Mutual information can also be expressed in terms of entropy:
Where:
- is the entropy of .
- is the entropy of .
- is the joint entropy of and .
Another useful form is:
Where:
- is the conditional entropy of given .
- is the conditional entropy of given .
Example : Consider two binary random variables and with the following joint probability distribution:
0 | 0 | 0.1 |
0 | 1 | 0.4 |
1 | 0 | 0.2 |
1 | 1 | 0.3 |
The marginal probabilities are:
The mutual information can be calculated as:
So, the mutual information is approximately 0.018 bits, indicating a small amount of dependency between and .
Properties
- Non-negativity: Mutual information is always non-negative:
- Symmetry: .
- Zero Mutual Information: If and are independent, .
- Bounds: .
Applications
- Feature Selection: In machine learning, mutual information can be used to select features that have the most information about the target variable.
- Clustering: Mutual information is used to measure the similarity between clusters.
- Dependency Detection: It helps in detecting and quantifying dependencies between variables in statistical analysis.
V. Kullback-Leibler (KL) divergence.
The Kullback-Leibler (KL) divergence, also known as relative entropy, is a measure from information theory that quantifies how one probability distribution diverges from a second, reference probability distribution.
For two probability distributions and defined on the same probability space, the KL divergence from to is defined as:
In the continuous case, the KL divergence is defined as:
Where:
- and (or and in the continuous case) are the probability distributions.
- is the set of possible outcomes.
KL divergence measures the expected number of extra bits required to code samples from using a code optimized for rather than the true distribution . It can be interpreted as a measure of information loss when is used to approximate .
Example : Consider two discrete probability distributions and over a binary variable :
- ,
- ,
The KL divergence from to is:
So, the KL divergence is approximately 0.278 bits, indicating that there is an information loss when using to approximate .
Properties
- Non-negativity: KL divergence is always non-negative, i.e., , with equality if and only if almost everywhere.
- Asymmetry: . This means the divergence from to is not the same as from to .
- Not a True Metric: Since KL divergence is asymmetric and does not satisfy the triangle inequality, it is not a true metric.
Applications
- Machine Learning: KL divergence is used in various machine learning algorithms, including variational inference and training of generative models like variational autoencoders.
- Information Retrieval: It is used to compare the similarity between different probability distributions, such as in document classification and clustering.
- Signal Processing: KL divergence helps in measuring the difference between actual and predicted signal distributions.
- Statistics: It is used to measure the goodness of fit of a model and to perform hypothesis testing.
VI. Applications of KL Divergence in Feature Selection.
KL divergence is a versatile tool in feature selection, particularly effective in text classification, image processing, and biomedical data analysis.
By quantifying the divergence between probability distributions of features across different classes, it identifies the most informative features. For instance, in text classification, KL divergence helps select terms that distinguish between document classes, while in image processing, it aids in identifying features that differentiate textures or objects.
Methods Using KL Divergence for Feature Selection
Univariate Feature Selection:
For each feature, compute the KL divergence between the distributions of the feature values in different classes.
Rank the features based on their KL divergence scores and select the top features with the highest scores.Multivariate Feature Selection:
Compute the joint probability distributions of multiple features and use KL divergence to measure the divergence between these joint distributions across different classes.
Select combinations of features that collectively maximize the KL divergence, thus providing the most information about the class distinctions.Wrapper Methods:
Integrate KL divergence into wrapper methods, where a predictive model (e.g., a classifier) is trained iteratively with different subsets of features.
Use KL divergence to evaluate and rank the importance of features based on their impact on the model's performance.
Workflow Sample
Data Preprocessing:
Normalize or standardize the features to ensure they are on a comparable scale.
Discretize continuous features if necessary to estimate probability distributions.Probability Distribution Estimation:
Estimate the probability distributions of each feature for different classes. This can be done using histograms, kernel density estimation, or other methods.KL Divergence Calculation:
For each feature, compute the KL divergence between the distributions of the feature values in different classes.Feature Ranking and Selection:
Rank the features based on their KL divergence scores.
Select the top features with the highest KL divergence scores for use in the predictive model.
Sample Code : (using python)
import numpy as np
from sklearn.feature_selection import mutual_info_classif
# Sample data: 100 samples, 10 features
X = np.random.rand(100, 10)
y = np.random.randint(2, size=100)
# Calculate KL divergence (using mutual information as an approximation)
kl_scores = mutual_info_classif(X, y, discrete_features='auto')
# Select top features based on KL divergence scores
top_k = 5
top_features = np.argsort(kl_scores)[-top_k:]
print("Top features based on KL divergence:", top_features)
mutual_info_classif
from scikit-learn
is used to approximate KL divergence for feature selection.
VII. Shannon's Theorem.
Also known as the Shannon-Hartley theorem or Shannon's channel capacity theorem, is a fundamental principle in information theory. It provides a formula to determine the maximum rate at which information can be transmitted over a communication channel with a specified bandwidth in the presence of noise, without error.
The Shannon-Hartley theorem states that the channel capacity , in bits per second (bps), of a communication channel is given by:
Where:
- is the channel capacity in bits per second.
- is the bandwidth of the channel in hertz (Hz).
- is the average signal power.
- is the average noise power.
- is the signal-to-noise ratio (SNR).
Keywords:
Implications
- Maximum Data Rate: Shannon's theorem defines the theoretical upper limit on the data rate that can be achieved over a noisy channel. No matter how advanced the encoding or modulation techniques are, the data rate cannot exceed this limit.
- Error-Free Communication: The theorem assures that it is possible to transmit information over a noisy channel with an arbitrarily low error rate, as long as the transmission rate does not exceed the channel capacity.
- Impact of Bandwidth and SNR: Increasing the bandwidth or improving the signal-to-noise ratio will increase the channel capacity. This highlights the importance of both factors in designing communication systems.
Example : Consider a communication channel with a bandwidth of 3 kHz (3000 Hz) and a signal-to-noise ratio of 30 dB.
First, convert the SNR from decibels to a linear scale:
Then, apply the Shannon-Hartley theorem:
Using the approximation :
So, the maximum achievable data rate for this channel is approximately 29.91 kbps.
Shannon's theorem guides the design and evaluation of communication systems, ensuring efficient and reliable data transmission even in the presence of noise.
VIII. Coding Theory Basics .
Coding theory is a branch of mathematics and computer science that deals with the design of error-correcting codes for reliable data transmission and storage. The primary goal of coding theory is to detect and correct errors introduced during the transmission or storage of data
Key Concepts
Codes:
A code is a set of strings (called codewords) over an alphabet. The alphabet is typically binary (0, 1), but it can be any set of symbols.
A code can be used to represent data in a way that allows for error detection and correction.Encoding and Decoding:
Encoding: The process of converting data into a codeword using a specific algorithm.
Decoding: The process of interpreting a received codeword, possibly correcting any errors, to recover the original data.Error Detection and Correction:
Error Detection: Identifying whether an error has occurred during data transmission or storage.
Error Correction: Identifying and correcting errors to retrieve the original data.
Types of Codes
Block Codes:
Definition: A block code encodes a fixed number of information bits into a fixed number of code bits.
Examples: Hamming codes, Reed-Solomon codes, BCH codes.
Parameters: A block code is characterized by (n, k), where is the length of the codeword, and is the number of information bits.Convolutional Codes:
Definition: A convolutional code encodes data by applying a set of linear operations to a sequence of input bits, producing a sequence of output bits.
Usage: Commonly used in real-time communication systems.
Parameters: Defined by the code rate (k/n) and constraint length.Linear Codes:
Definition: A linear code is a block code where any linear combination of codewords is also a codeword.
Examples: Hamming codes, Cyclic codes.
Properties: Easy to encode and decode using linear algebra techniques.
Key Metrics
Hamming Distance:
The number of positions at which two codewords differ.
The minimum Hamming distance of a code determines its error-detecting and error-correcting capabilities.Code Rate:
The ratio of the number of information bits to the total number of bits in the codeword (k/n).
Higher code rates are more efficient but provide less error protection.Error Detection and Correction Capability:
Error Detection: A code can detect up to errors if the minimum Hamming distance is .
Error Correction: A code can correct up to errors.
Example: Hamming Code (7,4)
Consider a simple Hamming code with parameters (7, 4), which encodes 4 information bits into 7-bit codewords. The code can detect and correct single-bit errors.
- Encoding: Given a 4-bit message, the encoder adds 3 parity bits to form a 7-bit codeword.
- Decoding: The receiver checks the parity bits to detect and correct any single-bit errors in the received codeword.
Applications
- Digital Communication: Ensuring reliable data transmission over noisy channels (e.g., satellite communication, mobile networks).
- Data Storage: Protecting data on storage devices (e.g., hard drives, CDs, DVDs) from corruption.
- Cryptography: Enhancing security by detecting and correcting errors in cryptographic algorithms.
- Barcodes and QR Codes: Enabling error detection and correction in optical data storage and retrieval.