Reinforcement Learning
Learn how to make a good sequence of decisions by interacting with the environment.
Characteristics of RL
Trial and Error : Based learning approach.
Optimization : Find good sequences of actions or decisions.
Delayed Consequences/Rewards : Takes time to relize the actions or decisions are good or bad.
Exploration : Learn by making decisions or forming actions or through experiences. Trying new actions to discover their effects.
Exploitation : Choosing actions with the highest expected reward, based on current knowledge.
Generalization : Use previous experiences or knowledge to new or unseen situations effectively.
Framwork of RL
OpenAI Gym
Torch RL
AWS DeepRacer
RL Math
Probability
Sample Space (Ω \Omega Ω ): The set of all possible outcomes of a random experiment.
Bonferroni's Inequality
P ( A ∩ B ) ≥ P ( A ) + P ( B ) − 1 P(A \cap B) \geq P(A) + P(B) - 1 P ( A ∩ B ) ≥ P ( A ) + P ( B ) − 1
P ( ∩ i = 1 n A i ) ≥ ∑ i = 1 n P ( A i ) − ( n − 1 ) P(\cap^{n}_{i=1} A_i) \geq \sum_{i=1}^{n} P(A_i) - (n-1) P ( ∩ i = 1 n A i ) ≥ ∑ i = 1 n P ( A i ) − ( n − 1 )
Gives a lower bound on the intersection probability which is useful when this probability is difficult to compute directly.
It is useful when the probabilities of individual events are sufficiently large.
Boole's Inequality
P ( ∪ i = 1 n A i ) ≤ ∑ i = 1 n P ( A i ) P(\cup^{n}_{i=1} A_i) \leq \sum_{i=1}^{n} P(A_i) P ( ∪ i = 1 n A i ) ≤ ∑ i = 1 n P ( A i )
for any sets A 1 , A 2 , . . . , A n A_1, A_2, ..., A_n A 1 , A 2 , ... , A n .
It is useful when finding an upper bound for the probabilities of the union of events.
Bayes' Rule
P ( A ∣ B ) = P ( A ∩ B ) P ( B ) P(A|B) = \frac{P(A \cap B)}{P(B)} P ( A ∣ B ) = P ( B ) P ( A ∩ B )
P ( A ∩ B ) = P ( B ∣ A ) P ( A ) = P ( A ∣ B ) P ( B ) P(A\cap B) = P(B|A) P(A) = P(A|B) P(B) P ( A ∩ B ) = P ( B ∣ A ) P ( A ) = P ( A ∣ B ) P ( B )
P ( A ∣ B ) P ( B ) = P ( B ∣ A ) P ( A ) P(A|B)P(B) = P(B|A)P(A) P ( A ∣ B ) P ( B ) = P ( B ∣ A ) P ( A )
P ( A ∣ B ) = P ( B ∣ A ) P ( A ) P ( B ) P(A|B) = \frac{P(B|A) P(A)}{P(B)} P ( A ∣ B ) = P ( B ) P ( B ∣ A ) P ( A )
It allows us to compute the conditional probability P ( A ∣ B ) P(A|B) P ( A ∣ B ) from the inverse conditional probability P ( B ∣ A ) P(B|A) P ( B ∣ A ) .
Let A 1 , A 2 , . . . , A n A_1, A_2, ..., A_n A 1 , A 2 , ... , A n be a partition of the sample space S S S . Then let B B B be any subset of S S S we have:
P ( A i ∣ B ) = P ( B ∣ A i ) P ( A i ) ∑ j = 1 ∞ P ( B ∣ A j ) P ( A j ) P(A_i|B) = \frac{P(B|A_i) P(A_i)}{\sum_{j=1}^{\infty} P(B|A_j) P(A_j)} P ( A i ∣ B ) = ∑ j = 1 ∞ P ( B ∣ A j ) P ( A j ) P ( B ∣ A i ) P ( A i )
Independent Events
P ( A ∩ B ) = P ( A ) P ( B ) P(A \cap B) = P(A) P(B) P ( A ∩ B ) = P ( A ) P ( B )
A family A i : i ∈ I A_i :i \in I A i : i ∈ I of events is independent if for every finite subset J ⊆ I J \subseteq I J ⊆ I we have:
P ( ⋂ i ∈ J A i ) = ∏ i ∈ J P ( A i ) P\left(\bigcap_{i \in J} A_i\right) = \prod_{i \in J} P(A_i) P ( ⋂ i ∈ J A i ) = ∏ i ∈ J P ( A i )
The pair-wise independence of events does not imply their mutual independence.
Conditional Independence
P ( A ∩ B ∣ C ) = P ( A ∣ C ) P ( B ∣ C ) P(A \cap B|C) = P(A|C) P(B|C) P ( A ∩ B ∣ C ) = P ( A ∣ C ) P ( B ∣ C )
where P ( C ) > 0 P(C) > 0 P ( C ) > 0 .
or equivalently, P ( A ∣ B ∩ C ) = P ( A ∣ C ) P(A|B \cap C) = P(A|C) P ( A ∣ B ∩ C ) = P ( A ∣ C ) and P ( B ∣ A ∩ C ) = P ( B ∣ C ) P(B|A \cap C) = P(B|C) P ( B ∣ A ∩ C ) = P ( B ∣ C ) .
Induced Probability Function
P X ( x i ) = P ( { w j ∈ Ω : X ( w j ) = x i } ) P_X(x_i) = P\big(\{w_j \in \Omega : X(w_j) = x_i\}\big) P X ( x i ) = P ( { w j ∈ Ω : X ( w j ) = x i } )
Ω = { w 1 , w 2 , . . . , w m } \Omega = \{w_1, w_2, ..., w_m\} Ω = { w 1 , w 2 , ... , w m } is the sample space.
X X X is a random variable with range X = { x 1 , x 2 , . . . , x n } X = \{x_1, x_2, ..., x_n\} X = { x 1 , x 2 , ... , x n } .
The result set { w j ∈ Ω : X ( w j ) = x i } \{w_j \in \Omega : X(w_j) = x_i\} { w j ∈ Ω : X ( w j ) = x i } is the set of all outcomes in the sample space that map to the value x i x_i x i under the random variable X X X .
Cumulative Distribution Function (CDF)
F X ( x ) = P X ( X ≤ x ) ∀ x ∈ R F_X(x) = P_X(X \leq x) \quad \forall x \in \mathbb{R} F X ( x ) = P X ( X ≤ x ) ∀ x ∈ R
F X ( x ) F_X(x) F X ( x ) is a cdf ⟺ \iff ⟺ the following conditions hold:
Monotonicity : F X ( x ) F_X(x) F X ( x ) is non-decreasing.
Limiting values : lim x → − ∞ F X ( x ) = 0 \lim_{x \to -\infty} F_X(x) = 0 lim x → − ∞ F X ( x ) = 0 and lim x → ∞ F X ( x ) = 1 \lim_{x \to \infty} F_X(x) = 1 lim x → ∞ F X ( x ) = 1 .
Right-Continuity : lim y ↓ x F X ( y ) = F X ( x ) ∀ x ∈ R \lim_{y \downarrow x} F_X(y) = F_X(x) \quad \forall x \in \mathbb{R} lim y ↓ x F X ( y ) = F X ( x ) ∀ x ∈ R .
F_X(t)
1.0 | ●────────────
| ↑ ↑ ↑
| 3.001 3.01 3.1
0.7 | ●─────────○
| ↑ ↑ ↑
| 2.001 2.01 2.1
0.3 | ●────────○
| ↑ ↑ ↑
| 1.001 1.01 1.1
0.0 |─────○
+-------------------------------------- t
1 2 3
x x x
Continuous & Discrete Random Variables
if X X X is continuous , then F X ( x ) F_X(x) F X ( x ) is continuous and differentiable almost everywhere. The probability density function (pdf) is defined as:
f X ( x ) = d d x F X ( x ) f_X(x) = \frac{d}{dx} F_X(x) f X ( x ) = d x d F X ( x )
if X X X is discrete , then F X ( x ) F_X(x) F X ( x ) is a step function and the probability mass function (pmf) is defined as:
p X ( x i ) = P ( X = x i ) p_X(x_i) = P(X = x_i) p X ( x i ) = P ( X = x i )
1 ────────────────────────━━━━━━━━
╱
╱
╱
╱
0 ━━━━━━━━━━━━━━━───────────────── x
1 ─────────────────────────●━━━━━━
│
0.7 ─────────────●━━━━━━━━━○
│
0.3 ─────●━━━━━━━○
│
0 ━━━━━━━○──────────────────────── x
1 2 3
1 ──────────────────────────━━━━━━
╱
╱
0.7 ───────────●━━━━━━━
│
0.5 ───────────○
╱
╱
0 ━━━━━━━━──────────────────────── x
a
Probability Mass Function (PMF)
f X ( x ) = { ( 1 − p ) x − 1 p , x = 1 , 2 , 3 , … 0 , otherwise f_X(x)= \begin{cases} (1-p)^{x-1}p, & x=1,2,3,\ldots \\ 0, & \text{otherwise} \end{cases} f X ( x ) = { ( 1 − p ) x − 1 p , 0 , x = 1 , 2 , 3 , … otherwise
A discrete random variable X X X is given by f X ( x ) = P ( X = x ) f_X(x) = P(X=x) f X ( x ) = P ( X = x ) for x ∈ R x \in \mathbb{R} x ∈ R .
It represents the probability that the first success occurs exactly on the x x x -th trial in a sequence of independent trials.
Probability Density Function (PDF)
F X ( x ) = ∫ − ∞ x f X ( t ) d t ∀ x ∈ R F_X(x) = \int_{-\infty}^{x} f_X(t) dt \quad \forall x \in \mathbb{R} F X ( x ) = ∫ − ∞ x f X ( t ) d t ∀ x ∈ R
A continuous random variable X X X is given by f X ( x ) f_X(x) f X ( x ) for x ∈ R x \in \mathbb{R} x ∈ R .
The probability is calculated as the area under the probability density function over a specific interval.
Expectation
E [ X ] = ∑ x P ( X = x ) if X is discrete E[X] = \sum x P(X=x) \quad \text{if } X \text{ is discrete} E [ X ] = ∑ x P ( X = x ) if X is discrete
E [ X ] = ∫ − ∞ ∞ x f X ( x ) d x if X is continuous E[X] = \int_{-\infty}^{\infty} x f_X(x) dx \quad \text{if } X \text{ is continuous} E [ X ] = ∫ − ∞ ∞ x f X ( x ) d x if X is continuous
Linearity : E [ a X + b Y + c ] = a E [ X ] + b E [ Y ] + c E[aX + bY + c] = aE[X] + bE[Y] + c E [ a X + bY + c ] = a E [ X ] + b E [ Y ] + c for any constants a a a , b b b , and c c c .
Non-negativity : If X ≥ 0 X \geq 0 X ≥ 0 then E [ X ] ≥ 0 E[X] \geq 0 E [ X ] ≥ 0 because it is a weighted average of non-negative values.
Monotonicity : If X ≥ Y X \geq Y X ≥ Y then E [ X ] ≥ E [ Y ] E[X] \geq E[Y] E [ X ] ≥ E [ Y ] because it is a weighted average of values that are greater than or equal to the corresponding values of Y Y Y .
Boundedness : If a ≤ X ≤ b a \leq X \leq b a ≤ X ≤ b then a ≤ E [ X ] ≤ b a \leq E[X] \leq b a ≤ E [ X ] ≤ b because it is a weighted average of values that are bounded by a a a and b b b .
a ●──────────────●──────────────● b
가능한 값들 평균
E[X]
Moments
μ n ′ = E [ X n ] ∀ n ∈ N \mu'_n = E[X^n] \quad \forall n \in \mathbb{N} μ n ′ = E [ X n ] ∀ n ∈ N
The n t h n^{th} n t h central moment of X X X is:
μ n = E [ ( X − E [ X ] ) n ] = E ( X − μ ) n \mu_n = E[(X - E[X])^n] = E(X - \mu)^n μ n = E [( X − E [ X ] ) n ] = E ( X − μ ) n
1th central moment is the mean, μ 1 = E [ X ] \mu_1 = E[X] μ 1 = E [ X ] .
2th central moment is the variance, μ 2 = E [ ( X − E [ X ] ) 2 ] = Var ( X ) \mu_2 = E[(X - E[X])^2] = \text{Var}(X) μ 2 = E [( X − E [ X ] ) 2 ] = Var ( X ) .
It emphasizes the variability of the distribution.
Var ( a X + b ) = a 2 Var ( X ) \text{Var}(aX + b) = a^2 \text{Var}(X) Var ( a X + b ) = a 2 Var ( X ) for any constants a a a and b b b .
3th central moment is the skewness, μ 3 = E [ ( X − E [ X ] ) 3 ] \mu_3 = E[(X - E[X])^3] μ 3 = E [( X − E [ X ] ) 3 ] .
It emphasizes the skewness of the distribution.
4th central moment is the kurtosis, μ 4 = E [ ( X − E [ X ] ) 4 ] \mu_4 = E[(X - E[X])^4] μ 4 = E [( X − E [ X ] ) 4 ] .
It emphasizes the tail behavior and extreme values of the distribution.
Covariance
cov(X, Y) = E [ ( X − E [ X ] ) ( Y − E [ Y ] ) ] \text{cov(X, Y)} = E[(X - E[X])(Y - E[Y])] cov(X, Y) = E [( X − E [ X ]) ( Y − E [ Y ])]
It measures how muc htwo random variables change together.
Negative Covariance
Near Zero Covariance
Positive Covariance
Y: 시험 점수
높음 | ●
| ● ●
| ●
| ●
낮음 | ●
+-------------------- X: 공부 시간
적음 많음
Cov(X,Y) > 0
Correlation
p ( X , Y ) = cov(X, Y) Var ( X ) Var ( Y ) p(X, Y) = \frac{\text{cov(X, Y)}}{\sqrt{\text{Var}(X)\text{Var}(Y)}} p ( X , Y ) = Var ( X ) Var ( Y ) cov(X, Y)
Individual variances must be non-zero.
p ( X , Y ) p(X, Y) p ( X , Y ) lies in the range [ − 1 , 1 ] [-1, 1] [ − 1 , 1 ] .
Joint Distributions
f X , Y : R 2 → [ 0 , 1 ] , f X , Y ( x , y ) = P ( X = x , Y = y ) if X , Y are discrete f_{X,Y}:\mathbb{R}^2\to[0,1], \\ f_{X,Y}(x,y) = P(X=x, Y=y) \quad \text{if } X, Y \text{ are discrete} f X , Y : R 2 → [ 0 , 1 ] , f X , Y ( x , y ) = P ( X = x , Y = y ) if X , Y are discrete
Joint Probability Mass Function (PMF) for discrete random variables X X X and Y Y Y .
Y
1 ┤ ● 1/4 ● 1/4
│ (0,1) (1,1)
0 ┤ ● 1/4 ● 1/4
│ (0,0) (1,0)
└──────────────────── X
0 1
Marginal Distributions
f X ( x ) = ∑ y f X , Y ( x , y ) f Y ( y ) = ∑ x f X , Y ( x , y ) f_X(x) = \sum_{y} f_{X,Y}(x,y) \\ f_Y(y) = \sum_{x} f_{X,Y}(x,y) f X ( x ) = ∑ y f X , Y ( x , y ) f Y ( y ) = ∑ x f X , Y ( x , y )
Fixing one variable and summing over the other variable gives the marginal distribution of the fixed variable.
Y=0 Y=1 행의 합
X=0 0.10 0.20 0.30
X=1 0.30 0.40 0.70
─────────────────────────
열의 합 0.40 0.60 1.00
f X ( 0 ) = 0.10 + 0.20 = 0.30 f_X(0) = 0.10 + 0.20 = 0.30 f X ( 0 ) = 0.10 + 0.20 = 0.30 : sum of the first row.
f X ( 1 ) = 0.30 + 0.40 = 0.70 f_X(1) = 0.30 + 0.40 = 0.70 f X ( 1 ) = 0.30 + 0.40 = 0.70 : sum of the second row.
f Y ( 0 ) = 0.10 + 0.30 = 0.40 f_Y(0) = 0.10 + 0.30 = 0.40 f Y ( 0 ) = 0.10 + 0.30 = 0.40 : sum of the first column.
f Y ( 1 ) = 0.20 + 0.40 = 0.60 f_Y(1) = 0.20 + 0.40 = 0.60 f Y ( 1 ) = 0.20 + 0.40 = 0.60 : sum of the second column.
Marginalization : It sums or integrates over all possible values of an unwanted variable to obtain the distribution of the variable of interest.
Conditional Distributions
f X ∣ Y ( x ∣ y ) = P ( X = x ∣ Y = y ) = f X , Y ( x , y ) f Y ( y ) if f Y ( y ) > 0 f_{X|Y}(x|y) = P(X = x | Y = y) = \frac{f_{X,Y}(x,y)}{f_Y(y)} \quad \text{if } f_Y(y) > 0 f X ∣ Y ( x ∣ y ) = P ( X = x ∣ Y = y ) = f Y ( y ) f X , Y ( x , y ) if f Y ( y ) > 0
It represents the probability distribution of X X X given that Y Y Y has a specific value.
If f Y ( y ) = 0 f_Y(y) = 0 f Y ( y ) = 0 , then f X ∣ Y ( x ∣ y ) f_{X|Y}(x|y) f X ∣ Y ( x ∣ y ) is undefined.
Bernoulli Distribution
X = { 1 , with probability p 0 , with probability 1 − p X = \begin{cases} 1, & \text{with probability } p \\ 0, & \text{with probability } 1-p \end{cases} X = { 1 , 0 , with probability p with probability 1 − p
E [ X ] = p E[X] = p E [ X ] = p
Var ( X ) = p ( 1 − p ) \text{Var}(X) = p(1-p) Var ( X ) = p ( 1 − p )
The outcome of a Bernoulli trial is either a success (1) or a failure (0) .
Binomial Distribution
probability of success in a single trial: p p p
probability of failure in a single trial: q = 1 − p q = 1 - p q = 1 − p
P ( X = x ∣ n , p ) = ( n x ) p x q n − x where ( n x ) = n ! x ! ( n − x ) ! , 0 ≤ x ≤ n P(X = x|n, p) = \binom{n}{x} p^x q^{n-x} \\ \text{where} \binom{n}{x} = \frac{n!}{x!(n-x)!}, \quad 0 \leq x \leq n P ( X = x ∣ n , p ) = ( x n ) p x q n − x where ( x n ) = x ! ( n − x )! n ! , 0 ≤ x ≤ n
E [ X ] = n p E[X] = np E [ X ] = n p
Var ( X ) = n p q = n p ( 1 − p ) \text{Var}(X) = npq = np(1-p) Var ( X ) = n pq = n p ( 1 − p )
The binomial distribution describes the number of successes in a fixed number of independent Bernoulli trials .
X ∼ Binomial ( 10 , 0.7 ) X \sim \text{Binomial}(10, 0.7) X ∼ Binomial ( 10 , 0.7 )
P ( X = 7 ) = ( 10 7 ) ( 0.7 ) 7 ( 0.3 ) 3 ≈ 0.2668 P(X = 7) = \binom{10}{7} (0.7)^7 (0.3)^3 \approx 0.2668 P ( X = 7 ) = ( 7 10 ) ( 0.7 ) 7 ( 0.3 ) 3 ≈ 0.2668
Geometric Distribution
probability of success in a single trial: p p p
probability of failure in a single trial: q = 1 − p q = 1 - p q = 1 − p
P ( X = x ∣ p ) = ( q x − 1 ) p where x = 1 , 2 , 3 , . . . P(X = x|p) = (q^{x-1}) p \\ \text{where } x = 1, 2, 3, ... P ( X = x ∣ p ) = ( q x − 1 ) p where x = 1 , 2 , 3 , ...
E [ X ] = 1 p E[X] = \frac{1}{p} E [ X ] = p 1
Var ( X ) = q p 2 \text{Var}(X) = \frac{q}{p^2} Var ( X ) = p 2 q
The geometric distribution describes the number of trials before the first success in a sequence of independent Bernoulli trials.
X ∼ Geometric ( 0.7 ) X \sim \text{Geometric}(0.7) X ∼ Geometric ( 0.7 )
P ( X = 3 ) = ( 0.3 ) 2 ( 0.7 ) ≈ 0.063 P(X = 3) = (0.3)^2 (0.7) \approx 0.063 P ( X = 3 ) = ( 0.3 ) 2 ( 0.7 ) ≈ 0.063
f X ( x ∣ a , b ) = { 1 b − a , a ≤ x ≤ b 0 , otherwise f_X(x|a,b) = \begin{cases} \frac{1}{b-a}, & a \leq x \leq b \\ 0, & \text{otherwise} \end{cases} f X ( x ∣ a , b ) = { b − a 1 , 0 , a ≤ x ≤ b otherwise
E [ X ] = a + b 2 E[X] = \frac{a+b}{2} E [ X ] = 2 a + b
Var ( X ) = ( b − a ) 2 12 \text{Var}(X) = \frac{(b-a)^2}{12} Var ( X ) = 12 ( b − a ) 2
The uniform distribution describes a continuous random variable that has an equal probability of taking any value within a specified range .
The probability depends on the length of the interval, not its location.
Normal Distribution
f X ( x ) = 1 2 π σ 2 e − ( x − μ ) 2 2 σ 2 , − ∞ < x < ∞ f_X(x) = \frac{1}{\sqrt{2\pi\sigma^2}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}, \quad -\infty < x < \infty f X ( x ) = 2 π σ 2 1 e − 2 σ 2 ( x − μ ) 2 , − ∞ < x < ∞
X ∼ N ( μ , σ 2 ) X \sim N(\mu, \sigma^2) X ∼ N ( μ , σ 2 )
Central Limit Theorem : the distribution of the sum (or average) of a large number of independent, identically distributed variables will be approximately normal, regardless of the underlying distribution.
X ˉ = 1 n ∑ i = 1 n X i ≈ N ( μ , σ 2 n ) \bar{X} = \frac{1}{n} \sum_{i=1}^{n} X_i \approx N\left(\mu, \frac{\sigma^2}{n}\right) X ˉ = n 1 ∑ i = 1 n X i ≈ N ( μ , n σ 2 )
Multivariate Normal Distribution
N ( x ∣ μ , Σ ) = 1 ( 2 π ) D ∣ Σ ∣ e − 1 2 ( x − μ ) T Σ − 1 ( x − μ ) N(x|\mu, \Sigma) = \frac{1}{\sqrt{(2\pi)^D |\Sigma|}} e^{-\frac{1}{2} (x-\mu)^T \Sigma^{-1} (x-\mu)} N ( x ∣ μ , Σ ) = ( 2 π ) D ∣Σ∣ 1 e − 2 1 ( x − μ ) T Σ − 1 ( x − μ )
μ \mu μ is the D D D -dimensional mean vector.
Σ \Sigma Σ is the D × D D \times D D × D covariance matrix.
∣ Σ ∣ |\Sigma| ∣Σ∣ is the determinant of the covariance matrix.
Beta Distribution
f ( x ∣ α , β ) = Γ ( α + β ) Γ ( α ) Γ ( β ) x α − 1 ( 1 − x ) β − 1 , 0 < x < 1 f(x|\alpha, \beta) = \frac{\Gamma(\alpha + \beta)}{\Gamma(\alpha)\Gamma(\beta)} x^{\alpha - 1} (1 - x)^{\beta - 1}, \quad 0 < x < 1 f ( x ∣ α , β ) = Γ ( α ) Γ ( β ) Γ ( α + β ) x α − 1 ( 1 − x ) β − 1 , 0 < x < 1
Γ ( n ) = ( n − 1 ) ! \Gamma(n) = (n-1)! Γ ( n ) = ( n − 1 )! is the gamma function.
E [ X ] = α α + β E[X] = \frac{\alpha}{\alpha + \beta} E [ X ] = α + β α
Var ( X ) = α β ( α + β ) 2 ( α + β + 1 ) \text{Var}(X) = \frac{\alpha \beta}{(\alpha +
\beta)^2 (\alpha + \beta + 1)} Var ( X ) = ( α + β ) 2 ( α + β + 1 ) α β
α < β α = β α > β
높이 높이 높이
│╲ │ ╭──╮ │ ╱
│ ╲___ │ ╭─╯ ╰─╮ │ ___╱
└──────── x └────────── x └──────── x
0 1 0 1 0 1
0 쪽 강조 가운데 강조 1 쪽 강조
Beta(8,2) Beta(80,20)
╭────╮ /\
╭─╯ ╰─╮ / \
─────╯ ╰─── ─────/────\─────
0.8 0.8
불확실성 큼 불확실성 작음
p ∣ data ∼ Beta ( α + s , β + f ) p | \text{data} \sim \text{Beta}(\alpha + s, \beta + f) p ∣ data ∼ Beta ( α + s , β + f )
where new observations are s s s successes and f f f failures.
The Beta distribution is a distribution of success probabilities for a Bernoulli or Binomial distribution.
Application
Measuring uncertainty in the probability of success for a Bernoulli or Binomial distribution.
Conversion rate or click-through rate (CTR) in online advertising.
Defect rate in manufacturing.
Linear Algebra
Axioms of Vector Spaces
Commutative Law : u + v = v + u , ∀ u , v ∈ V u + v = v + u, \quad \forall u, v \in V u + v = v + u , ∀ u , v ∈ V
Associative Law : ( u + v ) + w = u + ( v + w ) , ∀ u , v , w ∈ V (u + v) + w = u + (v + w), \quad \forall u, v, w \in V ( u + v ) + w = u + ( v + w ) , ∀ u , v , w ∈ V
Additive Identity : ∃ 0 ∈ V \exists 0 \in V ∃0 ∈ V such that v + 0 = v , ∀ v ∈ V v + 0 = v, \quad \forall v \in V v + 0 = v , ∀ v ∈ V
Additive Inverse : ∀ v ∈ V , ∃ − v ∈ V \forall v \in V, \exists -v \in V ∀ v ∈ V , ∃ − v ∈ V such that v + ( − v ) = 0 v + (-v) = 0 v + ( − v ) = 0
Distributive Law :
a ( u + v ) = a u + a v , ∀ a ∈ F , u , v ∈ V a(u + v) = au + av, \quad \forall a \in F, u, v \in V a ( u + v ) = a u + a v , ∀ a ∈ F , u , v ∈ V
( a + b ) v = a v + b v , ∀ a , b ∈ F , v ∈ V (a + b)v = av + bv, \quad \forall a, b \in F, v \in V ( a + b ) v = a v + b v , ∀ a , b ∈ F , v ∈ V
Associative Law : ( a b ) v = a ( b v ) , ∀ a , b ∈ F , v ∈ V (ab)v = a(bv), \quad \forall a, b \in F, v \in V ( ab ) v = a ( b v ) , ∀ a , b ∈ F , v ∈ V
Unitary Law : 1 v = v , ∀ v ∈ V 1v = v, \quad \forall v \in V 1 v = v , ∀ v ∈ V
Subspace
x + α y ∈ W , ∀ x , y ∈ W , ∀ α ∈ R x + \alpha y \in W, \quad \forall x, y \in W, \forall \alpha \in \mathbb{R} x + α y ∈ W , ∀ x , y ∈ W , ∀ α ∈ R
Norm
f : R n → R f: \mathbb{R}^n \to \mathbb{R} f : R n → R
It outputs a real number that represents the length or size of a vector in a vector space.
x = ( x 1 , x 2 , … , x n ) ↦ f ( x ) = ∥ x ∥ x=(x_1,x_2,\ldots,x_n) \mapsto f(x)=\lVert x\rVert x = ( x 1 , x 2 , … , x n ) ↦ f ( x ) = ∥ x ∥
Non-negativity : ∀ x ∈ R n , ∥ x ∥ ≥ 0 \forall x \in \mathbb{R}^n, \quad \lVert x\rVert \geq 0 ∀ x ∈ R n , ∥ x ∥ ≥ 0
Definiteness : f ( x ) = 0 ⟺ x = 0 f(x) = 0 \iff x = 0 f ( x ) = 0 ⟺ x = 0
Homogeneity : ∀ x ∈ R n , ∀ t ∈ R , f ( t x ) = ∣ t ∣ f ( x ) \forall x \in \mathbb{R}^n, \quad \forall t \in \mathbb{R}, f(tx) = |t| f(x) ∀ x ∈ R n , ∀ t ∈ R , f ( t x ) = ∣ t ∣ f ( x )
Triangle inequality : ∀ x , y ∈ R n , f ( x + y ) ≤ f ( x ) + f ( y ) \forall x,y \in \mathbb{R}^n, \quad f(x+y) \leq f(x) + f(y) ∀ x , y ∈ R n , f ( x + y ) ≤ f ( x ) + f ( y )
∥ x + y ∥ ≤ ∥ x ∥ + ∥ y ∥ \lVert x + y \rVert \leq \lVert x \rVert + \lVert y \rVert ∥ x + y ∥ ≤ ∥ x ∥ + ∥ y ∥
A norm is non-negative, only the zero vector has a norm of zero, scaling a vector by two doubles its norm, and the direct distance cannot be greater than the detoured distance.
∥ x ∥ p = ( ∑ i = 1 n ∣ x i ∣ p ) 1 p , p ≥ 1 \lVert x \rVert_p = (\sum_{i=1}^{n} |x_i|^p)^{\frac{1}{p}}, \quad p \geq 1 ∥ x ∥ p = ( ∑ i = 1 n ∣ x i ∣ p ) p 1 , p ≥ 1
L1 norm : ∥ x ∥ 1 = ∑ i = 1 n ∣ x i ∣ \lVert x \rVert_1 = \sum_{i=1}^{n} |x_i| ∥ x ∥ 1 = ∑ i = 1 n ∣ x i ∣
L2 norm : ∥ x ∥ 2 = ∑ i = 1 n ∣ x i ∣ 2 \lVert x \rVert_2 = \sqrt{\sum_{i=1}^{n} |x_i|^2} ∥ x ∥ 2 = ∑ i = 1 n ∣ x i ∣ 2
L-infinity norm : ∥ x ∥ ∞ = max i ∣ x i ∣ \lVert x \rVert_\infty = \max_i|x_i| ∥ x ∥ ∞ = max i ∣ x i ∣
∥ ( 3 , 4 ) ∥ ∞ = max { 3 , 4 } = 4 \lVert (3, 4) \rVert_\infty = \max\{3, 4\} = 4 ∥( 3 , 4 ) ∥ ∞ = max { 3 , 4 } = 4
∥ A ∥ F = ∑ i = 1 m ∑ j = 1 n ∣ a i j ∣ 2 = tr ( A T A ) \lVert A \rVert_F = \sqrt{\sum_{i=1}^{m} \sum_{j=1}^{n} |a_{ij}|^2} = \sqrt{\text{tr}(A^T A)} ∥ A ∥ F = ∑ i = 1 m ∑ j = 1 n ∣ a ij ∣ 2 = tr ( A T A )
Frobenius norm : A = [ 1 2 3 4 ] A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} A = [ 1 3 2 4 ]
∥ A ∥ F = 1 2 + 2 2 + 3 2 + 4 2 = 30 \lVert A \rVert_F = \sqrt{1^2 + 2^2 + 3^2 + 4^2} = \sqrt{30} ∥ A ∥ F = 1 2 + 2 2 + 3 2 + 4 2 = 30
It is the square root of the sum of the absolute squares of its elements.
Span
s p a n { x 1 , x 2 , . . . , x n } = { α 1 x 1 + α 2 x 2 + . . . + α n x n : α n ∈ R } span\{x_1, x_2, ..., x_n\} = \{ \alpha_1 x_1 + \alpha_2 x_2 + ... + \alpha_n x_n : \alpha_n \in \mathbb{R}\} s p an { x 1 , x 2 , ... , x n } = { α 1 x 1 + α 2 x 2 + ... + α n x n : α n ∈ R }
A set of vertors X = { x 1 , x 2 , . . . , x n } X = \{x_1, x_2, ..., x_n\} X = { x 1 , x 2 , ... , x n } in a vector space V V V is said to span V V V if every vector in V V V can be expressed as a linear combination of the vectors in X X X .
Span is the entire region that can be reached by scaling and adding the given vectors .
Range
R ( A ) = { α 1 a 1 + α 2 a 2 + . . . + α n a n : α n ∈ R } R(A) = \{\alpha_1 a_1 + \alpha_2 a_2 + ... + \alpha_n a_n : \alpha_n \in \mathbb{R}\} R ( A ) = { α 1 a 1 + α 2 a 2 + ... + α n a n : α n ∈ R }
The range of a matrix A A A is the set of all possible linear combinations of its column vectors.
Same as the columnspace of the matrix A A A .
Nullspace
N ( A ) = { x ∈ R n : A x = 0 } N(A) = \{x \in \mathbb{R}^n : Ax = 0\} N ( A ) = { x ∈ R n : A x = 0 }
A set of all vectors that equal 0 when multiplied by the matrix A A A .
The dimensionality of the nullspace is called the nullity of the matrix A A A .
Linear Independence
A set of vectors { v 1 , v 2 , . . . , v n } \{v_1, v_2, ..., v_n\} { v 1 , v 2 , ... , v n } is said to be linearly independent if the only solution to the equation α 1 v 1 + α 2 v 2 + . . . + α n v n = 0 \alpha_1 v_1 + \alpha_2 v_2 + ... + \alpha_n v_n = 0 α 1 v 1 + α 2 v 2 + ... + α n v n = 0 is α 1 = α 2 = . . . = α n = 0 \alpha_1 = \alpha_2 = ... = \alpha_n = 0 α 1 = α 2 = ... = α n = 0 .
Column rank : The maximum number of linearly independent column vectors in a matrix.
Row rank : The maximum number of linearly independent row vectors in a matrix.
If one row vector is a combination of other row vectors, then it is linearly dependent .
The number of rows that are removed due to redundancy is the Rank of the matrix.
Due to the redundancy, the number of directions which is vanishing is the Nullity of the matrix.
Rank
R a n k ( A ) = dim ( R ( A ) ) , A ∈ R m × n Rank(A) = \text{dim}(R(A)), \quad A \in \mathbb{R}^{m \times n} R ank ( A ) = dim ( R ( A )) , A ∈ R m × n
r a n k ( A ) ≤ min ( m , n ) , A ∈ R m × n rank(A) \leq \min(m, n), \quad A \in \mathbb{R}^{m \times n} r ank ( A ) ≤ min ( m , n ) , A ∈ R m × n
if r a n k ( A ) = m i n ( m , n ) rank(A) = min(m, n) r ank ( A ) = min ( m , n ) , then A A A is said to be full rank .
Rank cannot exceed the number of rows or columns in the matrix.
r a n k ( A ) = r a n k ( A T ) , A ∈ R m × n rank(A) = rank(A^T), \quad A \in \mathbb{R}^{m \times n} r ank ( A ) = r ank ( A T ) , A ∈ R m × n
The rank of a matrix is equal to the rank of its transpose.
The amount of independent information in the rows is equal to the amount of independent information in the columns.
r a n k ( A B ) ≤ min ( r a n k ( A ) , r a n k ( B ) ) , A ∈ R m × n , B ∈ R n × p rank(AB) \leq \min(rank(A), rank(B)), \quad A \in \mathbb{R}^{m \times n}, B \in \mathbb{R}^{n \times p} r ank ( A B ) ≤ min ( r ank ( A ) , r ank ( B )) , A ∈ R m × n , B ∈ R n × p
The information content of the product of two matrices cannot exceed the information content of either matrix.
r a n k ( A + B ) ≤ r a n k ( A ) + r a n k ( B ) , A , B ∈ R m × n rank(A + B) \leq rank(A) + rank(B), \quad A, B \in \mathbb{R}^{m \times n} r ank ( A + B ) ≤ r ank ( A ) + r ank ( B ) , A , B ∈ R m × n
The information content of the sum of two matrices cannot exceed the sum of the information content of each matrix.
Orthogonal Matrices
U ∈ R n × n is orthogonal ⟺ v i T v j = { 1 if i = j 0 if i ≠ j U \in \mathbb{R}^{n \times n} \text{ is orthogonal } \iff v_i^T v_j = \begin{cases} 1 & \text{if } i = j \\ 0 & \text{if } i \neq j \end{cases} U ∈ R n × n is orthogonal ⟺ v i T v j = { 1 0 if i = j if i = j
U U T = U T U = I n UU^T = U^TU = I_n U U T = U T U = I n
∥ U x ∥ 2 = ∥ x ∥ 2 , ∀ x ∈ R n \lVert Ux \rVert_2 = \lVert x \rVert_2, \quad \forall x \in \mathbb{R}^n ∥ Ux ∥ 2 = ∥ x ∥ 2 , ∀ x ∈ R n
Orthonormal : A set of vectors is orthonormal if they are all unit vectors and orthogonal to each other.
Rotation : R ( θ ) = [ cos θ − sin θ sin θ cos θ ] R(\theta) = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix} R ( θ ) = [ cos θ sin θ − sin θ cos θ ]
Reflection : R = [ 1 0 0 − 1 ] R = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} R = [ 1 0 0 − 1 ]
Q ( x ) = x T A x , A ∈ R n × n Q(x) = x^T A x, \quad A \in \mathbb{R}^{n \times n} Q ( x ) = x T A x , A ∈ R n × n
The quadratic form x T A x x^TAx x T A x gives a scalar value that measures the cost, energy, or weighted magnitude of the vextor x x x , according to the quadratic surface defined by the matrix A A A .
Positive definite: Q ( x ) > 0 , ∀ x ≠ 0 Q(x) > 0, \quad \forall x \neq 0 Q ( x ) > 0 , ∀ x = 0
Positive semi-definite: Q ( x ) ≥ 0 , ∀ x ≠ 0 Q(x) \geq 0, \quad \forall x \neq 0 Q ( x ) ≥ 0 , ∀ x = 0
Negative definite: Q ( x ) < 0 , ∀ x ≠ 0 Q(x) < 0, \quad \forall x \neq 0 Q ( x ) < 0 , ∀ x = 0
Negative semi-definite: Q ( x ) ≤ 0 , ∀ x ≠ 0 Q(x) \leq 0, \quad \forall x \neq 0 Q ( x ) ≤ 0 , ∀ x = 0
Indefinite: Q ( x ) Q(x) Q ( x ) can be positive or negative for different x ≠ 0 x \neq 0 x = 0
행렬의 정부호성(양의 정부호, 양의 준정부호, 음의 정부호, 음의 준정부호, 부정정부호)
A T A = A T A ⟹ Q ( x ) = x T A T A x = ( A x ) T ( A x ) = ∥ A x ∥ 2 ≥ 0 A^TA = A^TA \implies Q(x) = x^T A^T A x = (Ax)^T (Ax) = \lVert Ax \rVert^2 \geq 0 A T A = A T A ⟹ Q ( x ) = x T A T A x = ( A x ) T ( A x ) = ∥ A x ∥ 2 ≥ 0
Always positive semi-definite because it is the square of the norm of the vector A x Ax A x .
Eigenvalues & Eigenvectors
λ ∈ R is an eigenvalue of A ∈ R n × n ⟺ A x ⃗ = λ x ⃗ , x ⃗ ∈ R n , x ⃗ ≠ 0 \lambda \in \mathbb{R} \text{ is an eigenvalue of } A \in \mathbb{R}^{n \times n} \iff A\vec{x} = \lambda \vec{x} , \quad \vec{x} \in \mathbb{R}^n, \vec{x} \neq 0 λ ∈ R is an eigenvalue of A ∈ R n × n ⟺ A x = λ x , x ∈ R n , x = 0
An eigenvector is a nonzero vector that remains on the same line when transformed by a matrix.
Its eigenvalue tells us how much the vector is scaled and whether its direction is reversed.
det ( A − λ I ) = 0 \text{det}(A - \lambda I) = 0 det ( A − λ I ) = 0
A = [ 4 1 2 3 ] A = \begin{bmatrix} 4 & 1 \\ 2 & 3 \end{bmatrix} A = [ 4 2 1 3 ]
A − λ I = [ 4 − λ 1 2 3 − λ ] A - \lambda I = \begin{bmatrix} 4 - \lambda & 1 \\ 2 & 3 - \lambda \end{bmatrix} A − λ I = [ 4 − λ 2 1 3 − λ ]
det ( A − λ I ) = ( 4 − λ ) ( 3 − λ ) − 2 = λ 2 − 7 λ + 10 = ( λ − 5 ) ( λ − 2 ) = 0 \text{det}(A - \lambda I) = (4 - \lambda)(3 - \lambda) - 2 = \lambda^2 - 7\lambda + 10 = (\lambda - 5)(\lambda - 2) = 0 det ( A − λ I ) = ( 4 − λ ) ( 3 − λ ) − 2 = λ 2 − 7 λ + 10 = ( λ − 5 ) ( λ − 2 ) = 0
λ 1 = 5 , λ 2 = 2 \lambda_1 = 5, \quad \lambda_2 = 2 λ 1 = 5 , λ 2 = 2
tr ( A ) = ∑ i = 1 n λ i \text{tr}(A) = \sum_{i=1}^{n} \lambda_i tr ( A ) = ∑ i = 1 n λ i
The trace is the sum of the scaling factors along all eigenvector directions.
det ( A ) = ∏ i = 1 n λ i \text{det}(A) = \prod_{i=1}^{n} \lambda_i det ( A ) = ∏ i = 1 n λ i
The determinant is the product of the eigenvalues, representing the overall signed scaling factor for area or volume.
r a n k ( A ) = number of non-zero eigenvalues of A rank(A) = \text{number of non-zero eigenvalues of } A r ank ( A ) = number of non-zero eigenvalues of A
For a diagonalizable matrix, the rank equals the number of nonzero eigenvalues, counted with multiplicity.
λ i ( A − 1 ) = 1 λ i ( A ) \lambda_i (A^{-1}) = \frac{1}{\lambda_i(A)} λ i ( A − 1 ) = λ i ( A ) 1
The eigenvalues of the inverse of a matrix are the reciprocals of the eigenvalues of the original matrix.
A x ⃗ = λ x ⃗ ⟹ A − 1 A x ⃗ = A − 1 λ x ⃗ ⟹ x ⃗ = λ A − 1 x ⃗ ⟹ A − 1 x ⃗ = 1 λ x ⃗ A \vec{x} = \lambda \vec{x} \\ \implies A^{-1} A \vec{x} = A^{-1} \lambda \vec{x} \\ \implies \vec{x} = \lambda A^{-1} \vec{x} \\ \implies A^{-1} \vec{x} = \frac{1}{\lambda} \vec{x} A x = λ x ⟹ A − 1 A x = A − 1 λ x ⟹ x = λ A − 1 x ⟹ A − 1 x = λ 1 x
Diagonalization
S = [ ⋮ ⋮ ⋯ ⋮ v 1 ⃗ v 2 ⃗ ⋯ v n ⃗ ⋮ ⋮ ⋯ ⋮ ] S = \begin{bmatrix} \vdots & \vdots & \cdots & \vdots \\ \vec{v_1} & \vec{v_2} & \cdots & \vec{v_n} \\ \vdots & \vdots & \cdots & \vdots \end{bmatrix} S = ⋮ v 1 ⋮ ⋮ v 2 ⋮ ⋯ ⋯ ⋯ ⋮ v n ⋮
A S = [ ⋮ ⋮ ⋯ ⋮ λ 1 v 1 ⃗ λ 2 v 2 ⃗ ⋯ λ n v n ⃗ ⋮ ⋮ ⋯ ⋮ ] = [ ⋮ ⋮ ⋯ ⋮ v 1 ⃗ v 2 ⃗ ⋯ v n ⃗ ⋮ ⋮ ⋯ ⋮ ] [ λ 1 0 ⋯ 0 0 λ 2 ⋯ 0 ⋮ ⋮ ⋱ ⋮ 0 0 ⋯ λ n ] = S Λ AS = \begin{bmatrix} \vdots & \vdots & \cdots & \vdots \\ \lambda_1\vec{v_1} & \lambda_2\vec{v_2} & \cdots & \lambda_n\vec{v_n} \\ \vdots & \vdots & \cdots & \vdots \end{bmatrix} \\ = \begin{bmatrix} \vdots & \vdots & \cdots & \vdots \\ \vec{v_1} & \vec{v_2} & \cdots & \vec{v_n} \\ \vdots & \vdots & \cdots & \vdots \end{bmatrix} \begin{bmatrix} \lambda_1 & 0 & \cdots & 0 \\ 0 & \lambda_2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \lambda_n \end{bmatrix} \\ = S\Lambda A S = ⋮ λ 1 v 1 ⋮ ⋮ λ 2 v 2 ⋮ ⋯ ⋯ ⋯ ⋮ λ n v n ⋮ = ⋮ v 1 ⋮ ⋮ v 2 ⋮ ⋯ ⋯ ⋯ ⋮ v n ⋮ λ 1 0 ⋮ 0 0 λ 2 ⋮ 0 ⋯ ⋯ ⋱ ⋯ 0 0 ⋮ λ n = S Λ
S − 1 A S = Λ S^{-1}AS = \Lambda S − 1 A S = Λ
A S = S Λ AS = S\Lambda A S = S Λ
S − 1 A S = S − 1 S Λ = I Λ = Λ S^{-1}AS = S^{-1}S\Lambda = \mathbb{I}\Lambda = \Lambda S − 1 A S = S − 1 S Λ = I Λ = Λ
A matrix A A A that appears complicated in the original coordinate system becomes the diagonal matrix Λ \Lambda Λ when expressed in the eigenvector coordinate system.
A = S Λ S − 1 A = S\Lambda S^{-1} A = S Λ S − 1
In the eigenvector basis, the matrix A A A becomes the diagonal matrix Λ \Lambda Λ .
Symmetric Matrices
A real symmetric matrix satisfies A = A T A=A^T A = A T .
All eigenvalues of a real symmetric matrix are real.
A real symmetric matrix has a complete set of orthonormal eigenvectors.
Therefore, the eigenvector matrix S S S is orthogonal.
S T S = I ⟹ S − 1 = S T S^TS=\mathbb{I}
\quad\Longrightarrow\quad
S^{-1}=S^T S T S = I ⟹ S − 1 = S T
The diagonalization of a symmetric matrix is
A = S Λ S T A=S\Lambda S^T A = S Λ S T
S S S contains the orthonormal eigenvectors of A A A .
Λ \Lambda Λ contains the corresponding eigenvalues.
S T S^T S T converts x x x into the eigenvector basis.
Λ \Lambda Λ scales each eigenvector direction by its corresponding eigenvalue.
S S S converts the result back to the original basis.
Definiteness of Symmetric Matrices
Using A = S Λ S T A=S\Lambda S^T A = S Λ S T and y = S T x y=S^Tx y = S T x ,
x T A x = x T S Λ S T x = y T Λ y = ∑ i = 1 n λ i y i 2 x^TAx
=
x^TS\Lambda S^Tx
=
y^T\Lambda y
=
\sum_{i=1}^{n}\lambda_i y_i^2 x T A x = x T S Λ S T x = y T Λ y = i = 1 ∑ n λ i y i 2
y i y_i y i is the component of x x x along the i i i -th eigenvector.
Since y i 2 ≥ 0 y_i^2\geq0 y i 2 ≥ 0 , the sign of x T A x x^TAx x T A x depends entirely on the signs of the eigenvalues.
If all eigenvalues are positive, A A A is positive definite .
λ i > 0 for all i ⟹ x T A x > 0 for all x ≠ 0 \lambda_i>0\text{ for all }i
\quad\Longrightarrow\quad
x^TAx>0\text{ for all }x\neq0 λ i > 0 for all i ⟹ x T A x > 0 for all x = 0
If all eigenvalues are non-negative, A A A is positive semidefinite (PSD) .
λ i ≥ 0 for all i ⟹ x T A x ≥ 0 \lambda_i\geq0\text{ for all }i
\quad\Longrightarrow\quad
x^TAx\geq0 λ i ≥ 0 for all i ⟹ x T A x ≥ 0
If all eigenvalues are negative, A A A is negative definite .
λ i < 0 for all i ⟹ x T A x < 0 for all x ≠ 0 \lambda_i<0\text{ for all }i
\quad\Longrightarrow\quad
x^TAx<0\text{ for all }x\neq0 λ i < 0 for all i ⟹ x T A x < 0 for all x = 0
If all eigenvalues are non-positive, A A A is negative semidefinite (NSD) .
λ i ≤ 0 for all i ⟹ x T A x ≤ 0 \lambda_i\leq0\text{ for all }i
\quad\Longrightarrow\quad
x^TAx\leq0 λ i ≤ 0 for all i ⟹ x T A x ≤ 0
If A A A has both positive and negative eigenvalues, A A A is indefinite .
The eigenvectors determine the principal directions of the quadratic surface.
The eigenvalues determine the curvature and sign along those directions.
The definiteness of a symmetric matrix is determined entirely by the signs of its eigenvalues.
Eigenvalues of a Positive Semidefinite Matrix
If A A A is positive semidefinite, then
x T A x ≥ 0 x^TAx\geq0 x T A x ≥ 0
For an eigenvector x ⃗ ≠ 0 ⃗ \vec{x}\neq\vec{0} x = 0 with eigenvalue λ \lambda λ ,
A x ⃗ = λ x ⃗ A\vec{x}=\lambda\vec{x} A x = λ x
x ⃗ T A x ⃗ = x ⃗ T ( λ x ⃗ ) = λ x ⃗ T x ⃗ = λ ∥ x ⃗ ∥ 2 ≥ 0 \vec{x}^{\,T}A\vec{x}
=
\vec{x}^{\,T}(\lambda\vec{x})
=
\lambda\vec{x}^{\,T}\vec{x}
=
\lambda\lVert\vec{x}\rVert^2
\geq0 x T A x = x T ( λ x ) = λ x T x = λ ∥ x ∥ 2 ≥ 0
Since x ⃗ ≠ 0 ⃗ \vec{x}\neq\vec{0} x = 0 ,
∥ x ⃗ ∥ 2 > 0 \lVert\vec{x}\rVert^2>0 ∥ x ∥ 2 > 0
λ ≥ 0 \lambda\geq0 λ ≥ 0
Hence, all eigenvalues of a positive semidefinite matrix are non-negative.
A zero eigenvalue means that the corresponding eigenvector direction is collapsed to the zero vector.
Singular Value Decomposition
Diagonalization is generally defined for square matrices, while singular value decomposition can be applied to any rectangular or square matrix.
A = U Σ V T A=U\Sigma V^T A = U Σ V T
For A ∈ R m × n A\in\mathbb{R}^{m\times n} A ∈ R m × n ,
U ∈ R m × m , Σ ∈ R m × n , V ∈ R n × n U\in\mathbb{R}^{m\times m},
\qquad
\Sigma\in\mathbb{R}^{m\times n},
\qquad
V\in\mathbb{R}^{n\times n} U ∈ R m × m , Σ ∈ R m × n , V ∈ R n × n
The columns of V V V are the right singular vectors and represent orthonormal directions in the input space.
The columns of U U U are the left singular vectors and represent orthonormal directions in the output space.
The diagonal entries of Σ \Sigma Σ are the singular values.
σ 1 ≥ σ 2 ≥ ⋯ ≥ 0 \sigma_1\geq\sigma_2\geq\cdots\geq0 σ 1 ≥ σ 2 ≥ ⋯ ≥ 0
For each singular-vector pair,
A v i ⃗ = σ i u i ⃗ A\vec{v_i}=\sigma_i\vec{u_i} A v i = σ i u i
v i ⃗ \vec{v_i} v i is an input direction.
σ i \sigma_i σ i is the scaling factor.
u i ⃗ \vec{u_i} u i is the corresponding output direction.
The transformation A A A can be interpreted as three steps:
V T V^T V T expresses the input in the right singular-vector basis.
Σ \Sigma Σ scales each direction by its singular value.
U U U maps the scaled result into the output space.
U U U and V V V are orthogonal matrices.
U T U = I , V T V = I U^TU=\mathbb I,
\qquad
V^TV=\mathbb I U T U = I , V T V = I
The singular vectors and singular values are related to the eigenvectors and eigenvalues of A T A A^TA A T A and A A T AA^T A A T .
A T A v i ⃗ = σ i 2 v i ⃗ A^TA\vec{v_i}=\sigma_i^2\vec{v_i} A T A v i = σ i 2 v i
A A T u i ⃗ = σ i 2 u i ⃗ AA^T\vec{u_i}=\sigma_i^2\vec{u_i} A A T u i = σ i 2 u i
The rank of A A A equals the number of nonzero singular values.
SVD is commonly used for dimensionality reduction, data compression, noise reduction, pseudoinverses, and latent-factor analysis.
x ⏟ n × 1 → V T V T x ⏟ n × 1 → Σ Σ V T x ⏟ m × 1 → U U Σ V T x ⏟ m × 1 = A x ⏟ m × 1 \underbrace{x}_{n\times 1} \xrightarrow{V^T} \underbrace{V^Tx}_{n\times 1} \xrightarrow{\Sigma} \underbrace{\Sigma V^Tx}_{m\times 1} \xrightarrow{U} \underbrace{U\Sigma V^Tx}_{m\times 1} = \underbrace{Ax}_{m\times 1} n × 1 x V T n × 1 V T x Σ m × 1 Σ V T x U m × 1 U Σ V T x = m × 1 A x
U U U is such that the m m m columns of U U U are the eigenvectors of A A T AA^T A A T , known as the left singular vectors of A A A .
V V V is such that the n n n columns of V V V are the eigenvectors of A T A A^TA A T A , known as the right singular vectors of A A A .
Σ \Sigma Σ is a rectangular diagonal matrix with each element being the square root of an eigenvalue of A A T AA^T A A T or A T A A^TA A T A .
SVD allows us to construct a lower rank approximation of a rectangular matrix.
Choose only the top r r r singular values in Σ \Sigma Σ .
The corresponding columns in U U U and rows in V T V^T V T are also selected.
V V V represents the principal directions in the input space, U U U shows where those directions are mapped in the output space, and Σ \Sigma Σ shows how much each direction is scaled.
Gradient
∇ A f ( A ) = [ ∂ f ∂ A 11 ⋯ ∂ f ∂ A 1 n ⋮ ⋱ ⋮ ∂ f ∂ A m 1 ⋯ ∂ f ∂ A m n ] \nabla_A f(A) =
\begin{bmatrix}
\frac{\partial f}{\partial A_{11}} & \cdots & \frac{\partial f}{\partial A_{1n}}
\\
\vdots & \ddots & \vdots
\\
\frac{\partial f}{\partial A_{m1}} & \cdots & \frac{\partial f}{\partial A_{mn}}
\end{bmatrix} ∇ A f ( A ) = ∂ A 11 ∂ f ⋮ ∂ A m 1 ∂ f ⋯ ⋱ ⋯ ∂ A 1 n ∂ f ⋮ ∂ A mn ∂ f
The gradient with respect to A A A is a matrix that shows how the function f ( A ) f(A) f ( A ) changes with respect to each element of A A A .
( ∇ A f ( A ) ) i j = ∂ f ( A ) ∂ A i j \left(\nabla_A f(A)\right)_{ij} = \frac{\partial f(A)}{\partial A_{ij}} ( ∇ A f ( A ) ) ij = ∂ A ij ∂ f ( A )
Each element of the gradient measures how sensitive f ( A ) f(A) f ( A ) is to a small change in the corresponding element A i j A_{ij} A ij .
If f ( x 1 , x 2 ) = x 1 2 + 2 x 2 2 f(x_1,x_2)=x_1^2+2x_2^2 f ( x 1 , x 2 ) = x 1 2 + 2 x 2 2 then the gradient is
∇ f ( x ) = [ 2 x 1 4 x 2 ] . \nabla f(x) =
\begin{bmatrix}
2x_1
\\
4x_2
\end{bmatrix}. ∇ f ( x ) = [ 2 x 1 4 x 2 ] .
The gradient points in the direction of the steepest increase of the function.
∇ f ( x ) \nabla f(x) ∇ f ( x ) is a direction of steepest increase.
− ∇ f ( x ) -\nabla f(x) − ∇ f ( x ) is a direction of steepest decrease.
The magnitude of the gradient indicates how steeply the function increases.
To reduce the function value, optimization moves in the opposite direction of the gradient. This method is called gradient descent .
x n e w = x o l d − η ∇ f ( x o l d ) x_{\mathrm{new}} = x_{\mathrm{old}} - \eta\nabla f(x_{\mathrm{old}}) x new = x old − η ∇ f ( x old )
η \eta η is the learning rate, which controls the size of each update step.
Hessian
f : R n → R f:\mathbb{R}^n\to\mathbb{R} f : R n → R
H ( x ) = ∇ x 2 f ( x ) = [ ∂ 2 f ∂ x 1 2 ⋯ ∂ 2 f ∂ x 1 ∂ x n ⋮ ⋱ ⋮ ∂ 2 f ∂ x n ∂ x 1 ⋯ ∂ 2 f ∂ x n 2 ] H(x)
=
\nabla_x^2f(x)
=
\begin{bmatrix}
\frac{\partial^2f}{\partial x_1^2}
&
\cdots
&
\frac{\partial^2f}{\partial x_1\partial x_n}
\\
\vdots
&
\ddots
&
\vdots
\\
\frac{\partial^2f}{\partial x_n\partial x_1}
&
\cdots
&
\frac{\partial^2f}{\partial x_n^2}
\end{bmatrix} H ( x ) = ∇ x 2 f ( x ) = ∂ x 1 2 ∂ 2 f ⋮ ∂ x n ∂ x 1 ∂ 2 f ⋯ ⋱ ⋯ ∂ x 1 ∂ x n ∂ 2 f ⋮ ∂ x n 2 ∂ 2 f
A Hessian matrix is a square matrix containing all second-order partial derivatives of a scalar-valued function.
It describes the local curvature of the function.
If the second-order partial derivatives are continuous, then the Hessian is symmetric.
If
f ( x 1 , x 2 ) = x 1 2 + 2 x 2 2 , f(x_1,x_2)=x_1^2+2x_2^2, f ( x 1 , x 2 ) = x 1 2 + 2 x 2 2 ,
then the gradient is
∇ f ( x ) = [ ∂ f ∂ x 1 ∂ f ∂ x 2 ] = [ 2 x 1 4 x 2 ] . \nabla f(x)
=
\begin{bmatrix}
\frac{\partial f}{\partial x_1}
\\
\frac{\partial f}{\partial x_2}
\end{bmatrix}
=
\begin{bmatrix}
2x_1
\\
4x_2
\end{bmatrix}. ∇ f ( x ) = [ ∂ x 1 ∂ f ∂ x 2 ∂ f ] = [ 2 x 1 4 x 2 ] .
The Hessian is obtained by differentiating each component of the gradient with respect to every input variable.
H ( x ) = [ ∂ ∂ x 1 ( ∂ f ∂ x 1 ) ∂ ∂ x 2 ( ∂ f ∂ x 1 ) ∂ ∂ x 1 ( ∂ f ∂ x 2 ) ∂ ∂ x 2 ( ∂ f ∂ x 2 ) ] H(x)
=
\begin{bmatrix}
\frac{\partial}{\partial x_1}
\left(\frac{\partial f}{\partial x_1}\right)
&
\frac{\partial}{\partial x_2}
\left(\frac{\partial f}{\partial x_1}\right)
\\
\frac{\partial}{\partial x_1}
\left(\frac{\partial f}{\partial x_2}\right)
&
\frac{\partial}{\partial x_2}
\left(\frac{\partial f}{\partial x_2}\right)
\end{bmatrix} H ( x ) = ∂ x 1 ∂ ( ∂ x 1 ∂ f ) ∂ x 1 ∂ ( ∂ x 2 ∂ f ) ∂ x 2 ∂ ( ∂ x 1 ∂ f ) ∂ x 2 ∂ ( ∂ x 2 ∂ f )
= [ ∂ ∂ x 1 ( 2 x 1 ) ∂ ∂ x 2 ( 2 x 1 ) ∂ ∂ x 1 ( 4 x 2 ) ∂ ∂ x 2 ( 4 x 2 ) ] = [ 2 0 0 4 ] . =
\begin{bmatrix}
\frac{\partial}{\partial x_1}(2x_1)
&
\frac{\partial}{\partial x_2}(2x_1)
\\
\frac{\partial}{\partial x_1}(4x_2)
&
\frac{\partial}{\partial x_2}(4x_2)
\end{bmatrix}
=
\begin{bmatrix}
2&0
\\
0&4
\end{bmatrix}. = [ ∂ x 1 ∂ ( 2 x 1 ) ∂ x 1 ∂ ( 4 x 2 ) ∂ x 2 ∂ ( 2 x 1 ) ∂ x 2 ∂ ( 4 x 2 ) ] = [ 2 0 0 4 ] .
At a stationary point where ∇ f ( x ) = 0 \nabla f(x)=0 ∇ f ( x ) = 0 :
If H ( x ) ≻ 0 H(x)\succ0 H ( x ) ≻ 0 , then the point is a strict local minimum.
If H ( x ) ≺ 0 H(x)\prec0 H ( x ) ≺ 0 , then the point is a strict local maximum.
If H ( x ) H(x) H ( x ) has both positive and negative eigenvalues, then the point is a saddle point.
If H ( x ) H(x) H ( x ) is only positive semidefinite or negative semidefinite, the Hessian test may be inconclusive.
If H ( x ) ⪰ 0 H(x)\succeq0 H ( x ) ⪰ 0 for every x x x , then f f f is convex.
If H ( x ) ⪯ 0 H(x)\preceq0 H ( x ) ⪯ 0 for every x x x , then f f f is concave.
Differentiating a Linear Function
For a constant vector b ∈ R n b\in\mathbb{R}^n b ∈ R n ,
f ( x ) = b T x = ∑ i = 1 n b i x i f(x)=b^Tx
=
\sum_{i=1}^{n}b_ix_i f ( x ) = b T x = i = 1 ∑ n b i x i
When differentiating with respect to x k x_k x k , every term except b k x k b_kx_k b k x k is treated as a constant.
∂ f ( x ) ∂ x k = b k \frac{\partial f(x)}{\partial x_k}
=
b_k ∂ x k ∂ f ( x ) = b k
Collecting all partial derivatives gives
∇ x f ( x ) = [ b 1 b 2 ⋮ b n ] = b \nabla_x f(x)
=
\begin{bmatrix}
b_1\\
b_2\\
\vdots\\
b_n
\end{bmatrix}
=
b ∇ x f ( x ) = b 1 b 2 ⋮ b n = b
∇ x ( b T x ) = b \nabla_x(b^Tx)=b ∇ x ( b T x ) = b
Since f ( x ) = b T x f(x)=b^Tx f ( x ) = b T x is linear, its gradient is constant and does not depend on x x x .
Differentiating a Quadratic Function
For f ( x ) = x T A x f(x)=x^TAx f ( x ) = x T A x , where A ∈ R n × n A\in\mathbb{R}^{n\times n} A ∈ R n × n ,
∇ x f ( x ) = ( A + A T ) x \nabla_x f(x)
=
(A+A^T)x ∇ x f ( x ) = ( A + A T ) x
The two terms appear because each variable can occur in both positions of the product x i x j x_ix_j x i x j .
If A A A is symmetric, then A = A T A=A^T A = A T , so
∇ x ( x T A x ) = 2 A x \boxed{
\nabla_x(x^TAx)=2Ax
} ∇ x ( x T A x ) = 2 A x
The l l l -th component of the gradient is
∂ f ( x ) ∂ x l = ( 2 A x ) l = 2 ∑ i = 1 n A l i x i \frac{\partial f(x)}{\partial x_l}
=
(2Ax)_l
=
2\sum_{i=1}^{n}A_{li}x_i ∂ x l ∂ f ( x ) = ( 2 A x ) l = 2 i = 1 ∑ n A l i x i
Differentiating the l l l -th gradient component with respect to x k x_k x k gives the ( l , k ) (l,k) ( l , k ) -th entry of the Hessian.
H l k = ∂ ∂ x k ( ∂ f ( x ) ∂ x l ) = ∂ ∂ x k ( 2 ∑ i = 1 n A l i x i ) = 2 A l k H_{lk}
=
\frac{\partial}{\partial x_k}
\left(
\frac{\partial f(x)}{\partial x_l}
\right)
=
\frac{\partial}{\partial x_k}
\left(
2\sum_{i=1}^{n}A_{li}x_i
\right)
=
2A_{lk} H l k = ∂ x k ∂ ( ∂ x l ∂ f ( x ) ) = ∂ x k ∂ ( 2 i = 1 ∑ n A l i x i ) = 2 A l k
∇ x 2 ( x T A x ) = 2 A \boxed{
\nabla_x^2(x^TAx)=2A
} ∇ x 2 ( x T A x ) = 2 A
The gradient depends on x x x , while the Hessian is constant because f ( x ) = x T A x f(x)=x^TAx f ( x ) = x T A x is a quadratic function.