Skip to article content

Neural Networks

Back to Article
Midterm 2 Review
Download Notebook

Midterm 2 Review

Probability definitions

Q1: Define Sample Space

Sample space is the set all possible of outcomes of an experiment, denoted by Ω\Omega.

For example, For 2-coin tosses the sample space is

Ω2-coin={HH,HT,TH,TT}\Omega_{\text{2-coin}} = \{ HH, HT, TH, TT \}

For roll of a dice with 6-sides

Ωdice={1,2,3,4,5,6}\Omega_{\text{dice}} = \{1, 2, 3, 4, 5, 6 \}

For weight measurements of an individual, the sample space is the set of all positive real numbers

Ωweight=R+\Omega_{\text{weight}} = \bbR^+

Q2: Define Event Space

An event is the set of outcomes that we might be interested in.

Event space is a set of subsets of the sample space.

or example, For 2-coin tosses the set of all subsets of the sample space in cluding the null set {}\{\} and the full sample Ω\Omega

F2-coin={{},{HH}{HT},{TH},{TT},{HH,HT},,{HH,HT,TH,TT}Ω}\mathcal{F}_{\text{2-coin}} = \{ \{\}, \{ HH \} \{ HT \}, \{ TH \}, \{ TT \}, \{ HH, HT \}, \dots, \underbrace{\{ HH, HT, TH, TT \}}_\Omega \}

For weight measurements of an individual, the event space is be the set of all unions and intersections of intervals (open and closed) of sample space (positive real numbers).

Fweight={ij[aij,bij]:aij<bij,aijR,bijR}\mathcal{F}_{\text{weight}} = \{ \cup_{i} \cap_j [a_{ij}, b_{ij}] : a_{ij} < b_{ij}, a_{ij} \in \bbR , b_{ij} \in \bbR\}

Q3: Define Power set

The set of all possible subsets of a set Ω\Omega is called a power set and is denoted by 2Ω2^{\Omega}.

For roll of a dice with 6-sides

2Ω={{},{HH}{HT},{TH},{TT},{HH,HT},,{HH,HT,TH,TT}Ω}2^{\Omega} = \{ \{\}, \{ HH \} \{ HT \}, \{ TH \}, \{ TT \}, \{ HH, HT \}, \dots, \underbrace{\{ HH, HT, TH, TT \}}_\Omega \}

For discrete sample space, event space is the power set of the sample space.

Q4: Define Probability measure

Probability measure is a function P:F[0,1]P: \mathcal{F} \to [0, 1] that maps from event space to real numbers between [0,1][0, 1] and satisfy the following Kolmogorov axioms

  1. P(E)[0,1]P(E) \in [0, 1] for all EFE \in \mathcal{F}, where F\mathcal{F} is event space

  2. P(Ω)=1P(\Omega) = 1 , where Ω\Omega is sample space

  3. For all disjoint set of events A1A_1, A2A_2 (A1A2=ϕA_1 \cap A_2 = \phi), the probability of union of events is the sum of individual event probabilities:

    P(A1)+P(A2)=P(A1A2)P(A_1) + P(A_2) = P(A_1 \cup A_2)

    when A1A2=ϕA_1 \cap A_2 = \phi.

    In general, for a countably infinite set of event A1,A2,AnA_1, A_2, \dots A_n \dots \infty,

    P(n=1An)=n=1P(An)P\left(\bigcup_{n=1}^\infty A_n\right) = \sum_{n=1}^\infty P(A_n)

    when AiAj=A_i \cap A_j = \infty for all ij i \ne j.

Q5: Define Probability space

The triple of sample space Ω\Omega, event space F\mathcal{F} and a probability measure P:F[0,1]P: \mathcal{F} \to [0, 1] is called a probability space.

Q6: Define Random variable

A random variable is a function X:ΩQX: \Omega \to \mathbb{Q} that maps from sample space Ω\Omega to a space of integers Z\mathbb{Z} or real numbers R\mathbb{R} (in general a measurable space), such that a preimage X1(B)ΩX^{-1}(B) \in \Omega of any set of numbers BQB \in \mathbb{Q} exists in the sample space.

For example, a 2-coin toss:

Ω={HH,HT,TH,TT}\Omega = \{ HH, HT, TH, TT \}

A random variable maps the elements of sample space to a number,

X(HH)=0,X(HT)=1,X(TH)=2,X(TT)=3X(HH) = 0, X(HT) = 1, X(TH) = 2, X(TT) = 3

By slight abuse of notation, the random variable also maps events to a set of numbers X:FBX: \mathcal{F} \to B ,

X({HT,TH,TT})={1,2,3}X(\{HT, TH, TT\}) = \{1, 2, 3\}

Q7: What is the difference between discrete and continuous random variable

Discrete random variable: When the random variable maps the sample space to integers, then the random variable is discrete.

Continuous random variable: When the random variable maps the sample space to real numbers then the random variable is continuous.

Q8: Define Probability mass function (PMF)

For a discrete random variable (RV) the Probability mass function (PMF) is a function that assigns probability value to every discrete value of the random variable, such that

xΩP(X=x)=1.\sum_{x \in \Omega} P(X = x) = 1.

For example, a die roll

Ω={1,,6}\Omega = \{1, \dots, 6\}

P(X=1)=1/6,P(X=2)=1/6,,P(X=6)=1/6P(X=1) = 1/6, P(X=2) = 1/6, \dots, P(X=6) = 1/6

PMF is denoted as multiple symbols P(X=x)=PX(x)=P(x)P(X=x) = P_X(x) = P(x)

Q9: Define probability density function (PDF)

For a continuous random variable X:ΩRX: \Omega \to \mathbb{R}, the probability density function (PDF) is a function fX:R[0,)f_X : \mathbb{R} \to [0, \infty) such that:

  1. fX(x)0f_X(x) \ge 0 for all xRx \in \mathbb{R}

  2. RfX(x)dx=1\int_{\mathbb{R}} f_X(x) dx = 1

  3. P(aXb)=P(X[a,b])=abfX(x)dxP(a \le X \le b) = P(X \in [a, b]) = \int_a^b f_X(x) dx

Q10: Define joint probability mass function

P(X=x,Y=y)=P((X=x)(Y=y))=P((X=x) AND (Y=y))P(X=x, Y=y) = P((X=x) \cap (Y=y)) = P((X=x) \text{ AND } (Y=y))

Q11: Define joint probability density function

For two continuous random variable XX and YY, the joint probability density function (PDF) is a function fX,Y:(R,R)[0,)f_{X,Y} : (\mathbb{R}, \mathbb{R}) \to [0, \infty) such that:

  1. fX,Y(x,y)0f_{X,Y}(x, y) \ge 0 for all x,yRx, y \in \mathbb{R}

  2. RRfX,Y(x,y)dxdy=1\int_{\mathbb{R}} \int_{\mathbb{R}} f_{X, Y}(x, y) dx dy = 1

  3. P(aXb,cYd)=P(X[a,b],Y[c,d])=cdabfX,Y(x,y)dxdyP(a \le X \le b, c \le Y \le d) = P(X \in [a, b], Y \in [c, d]) = \int_c^d\int_a^b f_{X,Y}(x, y) dx dy

Q12: Define cumulative distribution function

A cumulative distribution function (CDF) is FX(x)F_X(x) is defined as

FX(x)=P(Xx).F_X(x) = P(X \le x).

For a discrete random variable, CDF is the sum of probability mass function

FX(x)=P(Xx)=axPX(a)F_X(x) = P(X \le x) = \sum_{a \le x} P_X(a)

For a continuous random variable, CDF is the integral of probability density function

FX(x)=P(Xx)=xfX(z)dzF_X(x) = P(X \le x) = \int_{-\infty}^{x} f_X(z) dz

Q13: Define conditional probability

Conditional probability of event AA given event BB is defined as

P(AB)=P(A,B)P(B)P(A | B) = \frac{P(A, B)}{P(B)}

when P(B)0P(B) \ne 0.

Q14: State Bayes theorem

For any two events, AA and BB

P(AB)=P(BA)P(A)P(B)P(A|B) = \frac{P(B|A) P(A)}{P(B)}

Q15: State Bayes theorem in terms of likelihood, prior, evidence and posterior

For an observable event DD and a hidden event θ\theta, the posterior P(θD)P(\theta|D) can be estimated using Bayes theorem in terms of likelihood P(Dθ)P(D|\theta), prior P(θ)P(\theta) and evidence P(D)P(D) as

P(θD)=P(Dθ)P(θ)P(D)P(\theta|D) = \frac{P(D|\theta) P(\theta)}{P(D)}

Q16: Define statistical independence

Two random variables XX and YY are said to be independent, denoted as XYX \perp Y if any of the following equivalent condition hold for all x,yx, y :

  1. P(X=x,Y=y)=P(X=x)P(Y=y)P(X = x, Y = y) = P(X = x) P(Y = y)
  2. P(X=xY=y)=P(X=x)P(X = x| Y = y) = P(X = x)
  3. P(Y=yX=x)=P(Y=y)P(Y = y| X = x) = P(Y = y)

Q17: Define conditional independence

Two random variables XX and YY are said to be conditionally independent given random variable ZZ, denoted as XYZX \perp Y | Z if for all x,y,zx, y, z :

P(X=x,Y=yZ=z)=P(X=xZ=z)P(Y=yZ=z)P(X = x, Y = y | Z = z) = P(X = x | Z = z) P(Y = y | Z = z)

Q18: Identically independently distributed (IID)

The random variables (RVs) X1,X2,,XnX_1, X_2, \dots, X_n are identically independently distributed if they are mutually independent XiXjX_i \perp X_j and have the same probability distributions PXi(xi)=PXj(xj)P_{X_i}(x_i) = P_{X_j}(x_j).

Q19: Expectation of a function of a random variable

The expectation of a function g(X)g(X) of a discrete random variable XX is defined as:

EX[g(X)]=xZP(X=x)g(x)\mathbb{E}_X[g(X)] = \sum_{x \in \mathbb{Z}} P(X=x) g(x)

The expectation of a function g(X)g(X) of a continuous random variable XX is defined as:

EX[g(X)]=xRfX(x)g(x)dx\mathbb{E}_X[g(X)] = \int_{x \in \mathbb{R}} f_X(x) g(x) dx

Q20: What is the difference between sample mean and expectation

Sample mean of n samples is

μ(X1,,Xn)=1ni=1nXi\mu(X_1, \dots, X_n) = \frac{1}{n} \sum_{i=1}^n X_i

Expectation of a discrete random variable is

EX[X]=xΩXP(X=x)x\bbE_X[X] = \sum_{x \in \Omega_X} P(X=x) x

Sample mean converges to the expectation when nn with high probability:

limnμ(X1,,Xn)=EX[X]\lim_{n \to \infty} \mu(X_1, \dots, X_n) = E_X[X]

Q21: Define variance of a function of a random variable

The expectation of a function g(X)g(X) of a random variable XX is given by

VX[g(X)]=EX[(g(X)EX[g(X)])2]\bbV_X[g(X)] = \bbE_X\left[ \left(g(X) - \bbE_X[g(X)]\right)^2 \right]

Q22: Define a covariance matrix

For random vector X=[X1,X2,,Xn]\bfX = [X_1, X_2, \dots, X_n], the covariance matrix of XX is defined as:

VX[X]=EX[(XEX[X])(XEX[X])]\bbV_X[\bfX] = \bbE_X\left[ \left(\bfX - \bbE_X[\bfX]\right) \left(\bfX - \bbE_X[\bfX]\right)^\top\right]

Q23:

Given the dataset D={(x1,y1),,(xn,yn)}\calD = \{ (\bfx_1, y_1), \dots, (\bfx_n, y_n) \}, a model y^i=f(xi;θ)\hat{y}_i = f(\bfx_i; \theta), and a loss function l(yi,y^i)l(y_i, \hat{y}_i), show that the following optimization problem can be interpreted as maximum likelihood estimation. In the process show that for the interpretation, we need the IID (independently, identically distributed) assumption over the dataset. List any other assumptions that you need for the interpretation.

θ=arg minθi=1nl(yi,f(xi;θ))\theta^* = \arg~\min_\theta \sum_{i=1}^n l(y_i, f(\bfx_i; \theta))

A23:

Let the xi\bfx_i and yiy_i be random vectors for all ii. Model the probability distribution as a negative log of the loss function:

P((xi,yi)θ)=1Zexp(l(yi,f(xi;θ)).P((\bfx_i, y_i)| \theta) = \frac{1}{Z} \exp(-l(y_i, f(\bfx_i; \theta)).

If the samples are IID, then we can write the probability of the entire dataset as products of sample probabilities

P(Dθ)=i=1nP((xi,yi)θ)P(\calD|\theta) = \prod_{i=1}^n P((\bfx_i, y_i)| \theta)
P(Dθ)=i=1n1Zexp(l(yi,f(xi;θ)).P(\calD|\theta) = \prod_{i=1}^n \frac{1}{Z} \exp(-l(y_i, f(\bfx_i; \theta)).

A product of exponents is the summation of their powers,

P(Dθ)=1Zexp(i=1nl(yi,f(xi;θ)).P(\calD|\theta) = \frac{1}{Z} \exp(-\sum_{i=1}^n l(y_i, f(\bfx_i; \theta)).

Denote

L(D;θ)=i=1nl(yi,f(xi;θ).L(\calD; \theta) = \sum_{i=1}^n l(y_i, f(\bfx_i; \theta).

The original optimization problem can be written as:

θ=arg minθL(D;θ)\theta^* = \arg~\min_\theta L(\calD; \theta)

Taking negative exponent on both sides turns the problem into a maximization problem because exp(y)\exp(-y) is a monotonically decreasing function.

θ=arg maxθexp(L(D;θ))\theta^* = \arg~\max_\theta \exp(-L(\calD; \theta))

This problem is the same as maximizing the likelihood P(Dθ)P(\calD|\theta), hence maximum likelihood estimate.

Q24:

Given the dataset D={(x1,y1),,(xn,yn)}\calD = \{ (\bfx_1, y_1), \dots, (\bfx_n, y_n) \}, a model y^i=f(xi;θ)\hat{y}_i = f(\bfx_i; \theta), a regularizer R(θ)R(\theta) and a loss function l(yi,y^i)l(y_i, \hat{y}_i), show that the following optimization problem can be interpreted as maximum-a-posteriori estimation. In the process show that for the interpretation, we need the IID (independently, identically distributed) assumption over the dataset. List any other assumptions that you need for the interpretation.

θ=arg minθi=1nl(yi,f(xi;θ))+λR(θ),\theta^* = \arg~\min_\theta \sum_{i=1}^n l(y_i, f(\bfx_i; \theta)) + \lambda R(\theta),

where λ\lambda is some positive constant that balances between the loss function and the regularizer.

A24:

Let the xi\bfx_i and yiy_i be random vectors for all ii. Model the probability distribution as a negative log of the loss function:

P((xi,yi)θ)=1Zexp(l(yi,f(xi;θ)).P((\bfx_i, y_i)| \theta) = \frac{1}{Z} \exp(-l(y_i, f(\bfx_i; \theta)).

If the samples are IID, then we can write the probability of the entire dataset as products of sample probabilities

P(Dθ)=i=1nP((xi,yi)θ)P(\calD|\theta) = \prod_{i=1}^n P((\bfx_i, y_i)| \theta)
P(Dθ)=i=1n1Zexp(l(yi,f(xi;θ)).P(\calD|\theta) = \prod_{i=1}^n \frac{1}{Z} \exp(-l(y_i, f(\bfx_i; \theta)).

A product of exponents is the summation of their powers,

P(Dθ)=1Zexp(i=1nl(yi,f(xi;θ)).P(\calD|\theta) = \frac{1}{Z} \exp(-\sum_{i=1}^n l(y_i, f(\bfx_i; \theta)).

Denote

L(D;θ)=i=1nl(yi,f(xi;θ).L(\calD; \theta) = \sum_{i=1}^n l(y_i, f(\bfx_i; \theta).

The original optimization problem can be written as:

θ=arg minθL(D;θ)+λR(θ)\theta^* = \arg~\min_\theta L(\calD; \theta) + \lambda R(\theta)

Taking negative exponent on both sides turns the problem into a maximization problem because exp(y)\exp(-y) is a monotonically decreasing function.

θ=arg maxθexp(L(D;θ))exp(λR(θ))\theta^* = \arg~\max_\theta \exp(-L(\calD; \theta))\exp(-\lambda R(\theta))

The first term is the same as maximizing the likelihood P(Dθ)P(\calD|\theta). If we interpret the second term as a prior:

P(θ)=1Zexp(λR(θ)),P(\theta) = \frac{1}{Z'} \exp(-\lambda R(\theta)),

then we can rewrite the original optimization problem as

θ=arg maxθP(Dθ)P(θ)\theta^* = \arg~\max_\theta P(\calD|\theta) P(\theta)

By Bayes theorem P(Dθ)P(θ)=P(θD)P(D)P(\calD|\theta) P(\theta) = P(\theta|\calD)P(\calD), hence we can write the optimization problem as maximizing the posterior

θ=arg maxθP(θD)P(D).\theta^* = \arg~\max_\theta P(\theta|\calD) P(\calD).

We can ignore the evidence term P(D)P(\calD), because it is independent of θ\theta the optimization variable. The original problem reduces to maximizing the posterior, hence maximum a posteriori:

θ=arg maxθP(θD)\theta^* = \arg~\max_\theta P(\theta|\calD)

Q25: Define L-p norm for p={1,2,}p = \{1, 2, \dots \}

xp=(x1p+x2p++xnp)1p\|\bfx\|_p = \left(|x_1|^p + |x_2|^p + \dots + |x_n|^p \right)^{\frac{1}{p}}

Q26: Find the minimum point for the following regularized least square problem and

w=arg minwyXw2+λw2,\bfw^* = \arg~\min_\bfw \|\bfy - \bfX \bfw\|^2 + \lambda \|\bfw\|^2,

where wRn\bfw \in \bbR^n, yRm\bfy \in \bbR^m, XRm×n\bfX \in \bbR^{m \times n} and λR+\lambda \in \bbR^+

A26:

Let f(w)=yXw2+λw2f(\bfw) = \|\bfy - \bfX \bfw\|^2 + \lambda \|\bfw\|^2

Write f(w)f(\bfw) in terms of inner product,

f(w)=(yXw)(yXw)+λwwf(\bfw) = (\bfy - \bfX \bfw)^\top(\bfy - \bfX \bfw) + \lambda \bfw^\top \bfw

Expand and collect the terms,

f(w)=w(XX+λIn)w2yXw+yyf(\bfw) = \bfw^\top (\bfX^\top \bfX + \lambda I_n) \bfw - 2\bfy^\top \bfX \bfw + \bfy^\top \bfy

Taking the derivative of f(w)f(\bfw) we get,

wf(w)=2w(XX+λIn)2yX.\frac{\partial}{\partial \bfw} f(\bfw) = 2 \bfw^\top(\bfX^\top \bfX + \lambda I_n) - 2\bfy^\top \bfX.

At the maximum point w\bfw^* the derivative of f(w)f(\bfw) is zero,

wf(w)w=0n,\left.\frac{\partial}{\partial \bfw} f(\bfw)\right|_{\bfw^*} = \mathbf{0}^\top_n,

Equating the derivative to zero at w\bfw^*, we can solve for w\bfw^*,

2w(XX+λIn)2yX=0n.2 \bfw^{*\top}(\bfX^\top \bfX + \lambda I_n) - 2\bfy^\top \bfX = \mathbf{0}^\top_n.

Rearranging we get,

w=(XX+λIn)1Xy\bfw^* = (\bfX^\top \bfX + \lambda I_n)^{-1} \bfX^\top \bfy