Comprehensive notes from the Machine Learning Research Lab course @ Universitas Indonesia [In Progress]
·21 min read·Eryawan Presma Yulianrifat
machine-learning
deep-learning
notes
Introduction to Deep Learning
1. Fundamental Definition of Machine Learning
Tom Mitchell (1997) provided a concise definition of machine learning:
A computer program is said to learn from experience E with respect to some task T and performance measure P, if its performance at task T, as measured by P, improves with experience E.
Illustrative Examples:
Handwriting Recognition:
Task (T): Classify handwritten characters
Performance (P): Accuracy of classification
Experience (E): Database of labeled handwritten words
Autonomous Driving:
Task (T): Navigate and control a vehicle
Performance (P): Distance traveled before human intervention
Experience (E): Recorded videos and steering commands
Chess Playing:
Task (T): Play chess strategically
Performance (P): Win rate against opponents
Experience (E): Database of self-play games
Major Categories of Machine Learning Tasks:
Supervised Learning:
Classification
Regression
Unsupervised Learning:
Clustering
Dimensionality Reduction
Density Estimation
Advanced Paradigms:
Self-supervised Learning
Reinforcement Learning
Deep Learning is a specialized subfield of machine learning that employs neural networks with multiple layers to solve complex tasks, particularly excelling in supervised learning scenarios.
2. Supervised Learning: Core Concepts
Supervised learning involves learning a function f: X → Y from labeled pairs (x, y).
Input Space: X, typically represented as ℝ^D (D-dimensional real space)
Output Space: Y (discrete for classification, continuous for regression)
Goal: Develop a hypothesis h(x) that closely approximates f(x)
Primary Types:
Classification:
Binary Classification: y ∈ {0,1} or {−1, +1}
Multiclass Classification: y ∈ {1,2,…,C}
Multilabel Classification: Categories not mutually exclusive
Regression:
Output y ∈ ℝ (continuous values)
Real-World Applications:
Iris Dataset Classification: Distinguishing between Setosa, Versicolor, and Virginica species
Image Classification: Mapping RGB pixel arrays to categorical labels
Rubik’s Cube Orientation: Regression problem for spatial positioning
Medical Diagnostics: Melanoma detection using transfer learning techniques
Protein Structure Prediction: AlphaFold’s approach combining deep CNNs with transformers
Hyperparameters: λ (regularization strength), M (model complexity)
Selection Methods: Validation set or cross-validation
Important Caution: Avoid direct optimization of λ and M on test data to prevent meta-overfitting
Probabilistic Framework
Motivation
ML models face uncertainty. Application of machine learning implies dealing with uncertainty. No machine learning model can achieve a perfect accuracy
Epistemic uncertainty or systematic uncertainty. uncertainty due to observing finite size of datasets. This uncertainty can be reduced with more data.
Aleatoric uncertainty or intrinsic uncertainty or stochastic uncertainty. uncertainty due to inherent randomness in the data. Happens because our observation can only capture partial information about the world.
Probability Theory
Probability Theory. Handling uncertainty requires the framework of probability theory
Frequentist view of probability. Probability is the proportion of the frequency of an event happening in the limit of an infinite number of trials.
Suppose an unfair coin is tossed a large number of times such that 60% of the time, the head-side faces up, and 40% of the time, the tail-side faces up. Then the probability of getting a head is 0.6.
Bayesian View of Probability. Probability is the quantification of uncertainty.
In the above example, we are not allowed to look at the coin and do not know which side is heads and which is tails. If asked to bet on whether the coin will land heads or tails, we would bet that the probability of seeing a head is 0.5.
In the absence of additional information, the above is the rational choice — whether the heads or tails occur is not itself a repeatable event, it simply unknown.
We simply assign a “score” indicating our belief about the event.
Uncertainty of our belief can be lowered once we observe more data.
Joint Probability P(X,Y). Probability of X=x AND Y=y denoted as P(X=x,Y=y)=pX,Y(x,y)
Conditional probability P(X∣Y). Probability of X=x given Y=y denoted as P(X=x∣Y=y)=pX∣Y(x∣y)
Marginal probability P(X) Probability of X=x obtained via sum rule, denoted as P(X=x)=pX(x)=∑ypX,Y(x,y) for discrete case or ∫−∞∞pX,Y(x,y)dy in continuous case.
Probability Distribution. A probability distribution for a random variable X is “complete specification of a way to compute probabilities of events about X.” It specify probability mass function (pmf) for discrete case and probability density function (pdf) for continuous case. Typically, pmf or pdf also depends on a set of parameters that governs the shape of pmf/pdf. Keep in mind that pmf/pdf must satisfy the requirement that they are nonnegative and normalized (their sum/integrate to 1 over all their support set). If a distribution is not normalized, it is called improper.
Bayes Theorem. The core principle in bayesian statistics, how do we measure belief after seeing some data (which is learning in some sense).
P(Y∣X)=P(X)P(X∣Y)P(Y)
Term
Name
Intuition
P(Y∣X)
Posterior
What we want to know: belief about Y after seeing data X
P(X∣Y)
Likelihood
How likely is data X under hypothesis Y?
P(Y)
Prior
Belief about Y before seeing any data
P(X)
Evidence (aka Marginal Likelihood)
How likely is the data X overall, across all possible values of Y?
For those who confuse likelihood and probability, here are genius explanation from my bro ChatGPT.
Likelihood and probability look similar but are conceptually different depending on the context. Whether we call P(X∣Y) the likelihood depends on what is fixed and what is variable.
Term
Variable
Fixed
Interpretation
Probability P(X∣Y)
X
Y
Given model/parameter Y, how likely is the data X?
Likelihood L(Y)=P(X∣Y)
Y
X
Given observed data X, how likely is a particular model/parameter Y?
Independent Event.
P(X,Y)=P(X)P(Y)⟺P(Y∣X)=P(Y)
If the posterior probability equal to prior probability (Additional information does not change the prior probability), then X and Y are independent.
Expectation. Expectation of some function f(x) is the weighted average of f under a probability distribution p(x).
Ep(x)[f(x)]=x∑f(x)p(x)or∫−∞∞f(x)p(x)dx
Ep(x)[f(x,y)] indicates expectation of a function over several variables, and the subscript p(x) denotes the distribution under which the expected value of the function is computed. In this case, Ep(x)[f(x,y)] becomes a function of y.
Conditional Expectation. Conditional expectation is defined w.r.t. a conditional distribution p(x∣y).
Ep(x∣y)[f(x)]=x∑p(x∣y)f(x)or∫−∞∞p(x∣y)f(x)dx
Variance. Variance of f(x) measures how much the value of f varies over all possible values of x under a certain p(x).
Probability vs Likelihood. Probability is the chance that a particular outcome occurs based on the values of the distribution parameters. When calculating probability, we assume that the parameters are trustworthy. Likelihood is how well a sample/data provides support for particular values of the distribution parameter. When calculating likelihood, we’re trying to determine if we can trust the parameter values based on the data that we observe.
L(θ∣X=x)=Pθ(x)=P(X=x;θ)=fθ(x) for continuous pdf fθ(x)
In continuous case, we use pdf f which interpreted as density where in discrete case we use pmf p which interpreted as true probability. The integral of the likelihood over all parameter values may not be equal to 1.
Computing Likelihood. Given dataset D=x1,…,xN that is i.i.d (independent and identically distributed), the likelihood is computed as
L(θ∣D)=i=1∏NP(xi;θ)=i=1∏Nfθ(xi)
Product/multiplication of large number of small numbers can be problematic. So we often work with log-likelihood.
LL(θ)=logL(θ∣D)=i=1∑NlogP(xi;θ)
Density estimation aka Parameter Estimation. Task of estimating the distribution, given a finite set of observations. Ill-posed because there are infinitely many distributions that could have generate the observed finite dataset.
One solution (among others) for density estimation is maximizing likelihood of the
parameters with respect to the given dataset. Parameters obtained by likelihood maximization are usually called maximum likelihood estimators.
Information Theory
Shannon’s idea: relate information content to degree of surprise. It view that Surprise ⟺ Rarity and Rarity ⟺ Contains more information.
Measuring information. Suppose, for a discrete RV X, we observe that X=x for a particular x, how much information do we receive? Let h(x) be the measure of information.
h(x) should be additive. If two unrelated facts x, y occur at the same time, the surprise seeing both of them should be the sum of the individual surprises. So,
h(x,y)=h(x)+h(y)
But, x and y are unrelated, hence also independent. So, p(x,y)=p(x)p(y) and h(x) should be logarithm of p(x).
h(x) should be monotonic in the opposite direction to p(x).h(x) increases iff p(x) decreases.
We obtain,
h(x)=−logbp(x)
Entropy: expected amount of information. Entropy H[x] of x: expected amount of information (i.e., amount of surprise) over all possible outcomes of x under distribution of x, which is p(x):
H[x]=Ep(x)[h(x)]=x∑p(x)h(x)=−x∑p(x)logp(x)
Entropy can also be understood as a measure of uncertainty of a system.
Minimum and Maximum Entropy Problem. The minimum of H[p] is H[p] = 0 that happens when there exists some xi such that p(xi)=1 while p(xj)=0 for the other xj‘s. Its maximum however, is harder and more useful, choosing the most unbiased distribution given what you know.
If you know nothing about a discrete variable, use uniform distribution (max entropy under no constraint).
If you know mean and variance, Gaussian has max entropy among all distributions with that mean and variance.
If you only know a positive support and expected value, Exponential distribution is max entropy.
Solving Maximum Entropy Problem using Langragian Contrained Optimization.
We aim to solve for p(xi) (discrete case) that maximize following objective
See that contrained g(x) is to kept them under probability axiom (sum to 1). In the end, we would have something like p(x1)=p(x2)=⋯=p(xn)=exp(λ−1)=1/K. In other words, H[p] is maximum when p(x) is a uniform (discrete) distribution.
Entropy for continuous variable. We can extend entropy to continous variables as differential.
One can show using calculus of variations and Lagrange function that the distribution that maximizes the differential entropy is the Gaussian.
Cross Entropy. Cross-entropy measures the difference between two probability distributions: the true distribution p(x) and the predicted distribution q(x). It tells you how many “nats” or “bits” you need to encode data from p(x) using the coding scheme designed for q(x).
Hp(q)Hp(p)=H(q,p)=−x∑q(x)logp(x)=H[p]
Note that we use parentheses for cross entropy instead of square brackets.
Expression above is the same as saying how many bits (or nats) you need to encode data from q(x) using the coding scheme designed for p(x). In machine learning, the message corresponds to the true (unknown) distribution of the prediction outcome, while the code corresponds to the approximating distribution of the prediction obtained by the model.
Kullback-Leibler (KL) Divergence. The average additional amount of information (in nats) needed to specify the value x (using the approximating distribution q(x)), is given by:
KLq(p∣∣q)=Hq(p)−Hp[x]=x∑p(x)logq(x)p(x)
KL divergence can be interpreted as a measure of dissimilarity between two distributions p(x) and q(x).
KL Divergence and Likelihood. If training data comes from the unknown distribution p(x), we approximate p(x) using some parametric distribution q(x∣θ). θ can be determined by minimizing KL(p∣∣q) but p(x) is unknown. Since we have training data {xi} drawn from p(x), we can estimate as a finite sum over these points.
log p(xi) is independent of θ and q(x∣θ) is negative log-likelihood. Therefore minimizing KL(p∣∣q) is equivalent to maximizing log-likelihood θ of q. In deep learning, KL-divergence is usually used in variational autoencoders, generative adversarial networks, and diffusion models.
Linear Regression
Task. Predict continuous target t from input x∈RD
Model.
y(x,w)=j=0∑M−1wjϕj(x)=wTϕ(x)
Basis Function. Linear in weights, but not necessarily in inputs.
Polynomial ϕj(x)=xj
Gaussian ϕj(x)=exp(−2s2(x−μj)2)
Sigmoid ϕj(x)=σ(sx−μj)
Fourier and Wavelet bases
Probabilistic Modeling. Assume noise in targets t such that
t=y(x,w)+ϵe∼N(0,σ2)
Where
y(x,w)=wTϕ(x)
Probabilistically, we can write
p(t∣x,w,σ2)=N(t∣y(x,w),σ2)
Given a dataset of inputs X={x1,…,xN} with corresponding targets t=(t1,…,tN)T where data points are i.i.d. The likelihood of parameters w,σ2 defined as
L(w,σ2∣X,t)LL(w,σ2∣X,t)LL(w,σ2∣X,t)LL(w,σ2∣X,t)=p(t∣X,w,σ2)=i=1∏NN(ti∣wTϕ(xi),σ2)=i=1∑NN(ti∣wTϕ(xi),σ2)=Nlogσ2π1−21i=1∑N(σti−wTϕ(xi))2=−2Nlog(2πσ2)−σ21Sum of Squares Error21i=1∑N(ti−wTϕ(xi))2
if σ2 is assumed to be fixed/constant, maximizing the log-likelihood above is equivalent to minimzing the sum-of-squares error.
The maximization of the log-likelihood in previous equation is done with respect to two parameters: w and σ2, leading to solutions for both defined as:
Both are called maximum likelihood estimators for the model. For homoskedastic linear regression model, σ2 is actually assumed to be constant, leading to wMLE as a least-square solution to the sum-of-squares error.
Design Matrix. Is a matrix X∈RN×D for number of data N and feature dimension D. The basis function ϕ:RN→RM is applied to each row of X to yield a (row) vector of length M. y=[yi]i is also commonly used together with Design Matrix.
Maximize log likelihood. We will try to solve this using gradient in a closed form style, make it equal to 0. We will solve it in design matrix form Φ∈.
This is normal equation: wmle=(ΦTΦ)−1ΦTt. Can lead to numerical difficulties when ΦTΦ is close to singular. Can be addressed using SVD or sequential or online stochastic gradient descent algorithms.
Regularized Least Square Solving for Overfitting Problem. We change the objective to minimize for
ED(w)+λEW(w)=21i∑(ti−wTϕ(xi))2+2λwTw
We use ℓ2 regularizer for Ew. This method also called as weight decay allowing our models to turning off some of the parameters w.
Multiple Regression. Conditional distribution of the K-dimensional target vector t.
a K × K covariance matrix Σ=σ2I, required to be positive-semi definite — the notation ∣Σ∣=∣σ2I∣ represents the determinant of Σ.
The Gaussian is assumed isotropic: equal variance in each dimension (thus equal density in every direction) and all dimensions are independence. So, the shape will be spherical and aligned at all axes.
Decision Theory
Approximating Distribution to Decision Probablistic model p(t∣x,wML,σML2)=N(t∣y(x,wML),σML2) is a predictive distribution expressing uncertanity over value of t for some new input x. But often we need to predict specific value for t, rather than returning the distribution, especially if we must take a specific action. Example, If our aim is to determine the optimal level of radiation to use for treating tumor and model predicts a probability distribution over radiation dose, then we need to use that distribution to determine the specific dose to be administered. We explain this formally using the notion of decision theory.
Formal Objective. Suppose we choose f(x) for our prediction when the true value is t. Then, this choice incur a penalty/cost given by a loss function L(t,f(x)). We define the objective
E[l]=∫∫L(t,f(x))dxdt
Example of L(t,f(x)) is squared loss.
L(t,f(x))=(f(x)−t)2
Choosing decision function f(x). Minimizing above expected loss using squared loss, using calculus of variations, we obtain.
f∗(x)=∫tp(t∣x)dt=Et[t∣x]
f∗(x)=Et[t∣x] is called the regression function.
Which is just conditional expectation of t given x. For Gaussian conditional distribution, this becomes the following.
E[t∣x]=∫tp(t∣x)dt=y(x,w)
Bias Variance Tradeoff
Derivation of Bias Variance Tradeoff.
E[L]=∫(f(x)−E[t∣x])2p(x)dx+∫var(t∣x)p(x)dx
Note that term E[t∣x] is just one choice of the regression function. Second term is independent of f(x) arises from intrinsic noise of the data – represents minimum value achievable for expected loss.
Consider the first integrand, done over a particular dataset D: (f(x;D)−h(x))2.
We do experiments over the ensemble of datasets, so we can take the average of the above
over many possible datasets. Consider we model E[t∣x]=h(x).
There will be 3 terms with the last term will vanish. The first term is the squared bias of the model. Second term is variance of the
We will ended up with expected loss= bias 2+ variance + irreducible noise.
Classification
Task. Predicting a class label y∈{1,…,K} from input x∈RD.
Three approaches to solve classification task.
Discriminant function: directly assigns x to a specific class.
Discriminative probabilistic model: train the conditional distribution p(Ck∣x) directly using a training set, and then use the model to decide the class of x.
Generative probabilistic model: model the class-conditional density p(x∣Ck), and the class prior p(Ck), then compute the posterior p(Ck∣x) via Bayes theorem; after that, use the posterior distribution to decide the class of x.
Maximum Likelihood on Classification Task. Likelihood is defined the same regardless of regression or classification. All that matters is our estimator definition. Suppose we model classification task as below.
p(y=c∣x;w)=fc(x;w)
where fc(x;w) is a parametric function. Likelihood is in the form of.
Linear discriminant function: Two-class case. Suppose we model
y(x)=wTx+w0
The decision to assign x into class y^ is
y^={C1if y(x)≥0C2otherwise
Decision boundary corresponds to the y(x)=0, D−1 dimensional hyperplane within D dimensional input space.
Decision boundary is orthogonal to w. Under the same model above, we could prove that for any vector (x0−x1) such that y(x0)=y(x1)=0 (they are on the same side of the decision boundary), they are orthogonal with w.
where ⟨⋅,⋅⟩ is the standard dot product. This property holds true for any two points x0,x1 on the decision boundary. This implies that the distance between any x and the decision boundary is r∥w∥w,r∈R.
Multiple classes. The trick above (Defining decision boundary yc(x)>0) will draw a single line for single class c.
One-versus-the-rest. When there are C classes, we draw C decision boundaries, but this will lead into ambiguous regions where both classes are predicted (problem in mutually exclusive classes).
One-versus-one. When there are C classes, we draw C(C−1) decision boundaries, but this will lead into ambiguous regions where both classes are predicted (problem in mutually exclusive classes).
Solution, use K linear functions f1(x),…,fK(x), then y^=argmaxk=1,…,Kfk(x), i.e assign x to the class i with highest fi(x). Decision regions will be singly connected and convex.
Using Least Square to find W. For one hot vector ti∈RK with prediction wTϕ(xi)∈RK, we stack into the matrix form T=[ti]i∈RN×K,X=[ϕ(xi)]i∈RN×D,W=[wiT]i∈RD×K (essentially just stacking vertically).
Prediction and Action. Prediction in supervised learning is modeled probabilistically as a posterior distribution p(y∣x). Intuitively, our follow up action for prediction is to choose the value of y that makes p(y∣x) the highest. But is this mathematically justified?
Mathematical Justification. We assume an agent / decision maker has set of possible action a∈A. Each action a has costs and benefits that depend on the state (hidden) of nature y. These dependencies can be modeled as a loss function ℓ(y,a) that gives the loss incurred if the agent takes action a when the state of nature is y.
Posterior Expected Risk. We define the posterior expected risk as
R(a∣x)=Ep(y∣x)[ℓ(y,a)]=y∈Y∑p(y∣x)ℓ(y,a)
Optimal Policy (Bayes Estimator). The optimal policy is the one that minimizes the posterior expected risk.
a∗=arga∈AminR(a∣x)
Alternative: Use utility function, Maximum Expected Utility Principle. Define U(y,a) expressing desirability of each possible action and state then seek action that maximize expected utility.
a∗=arga∈AmaxEp(y∣x)[U(y,a)]
Decision on Classification, Zero-one loss for Binary Classification. Assign loss 1 if action is wrong, 0 otherwise.
Maximum a posteriori (MAP) estimate. This maximization decision rule is corresponds to the mode of the posterior distribution. Specifically for binary case:
a∗={01if p(y=0∣x)≥p(y=1∣x)otherwise
Cost Sensitive Classification. Instead of zero-one loss, we may have the following cost matrix where ℓij is the cost of predicting j when true label is i.
Reject Option Classification. Sometimes we want to say “I don’t know” instead of returning an answer (called the reject option). The loss will then become
ℓl(y,a)=⎩⎨⎧0λrλeif a=y^if a=rejectotherwise
The optimal decision rule that minimizes posterior risk is (prove as exervise)
Confusion Matrix. We can define the number of true positives (TP), false positive (FP), true negatives (TN), and false negatives (FN) with respect to the threshold τ:
Choosing from a number of different thresholds. With ROC curves, we can consider a set of different thresholds and compare the resulting performance. For each threshold τ, we plot FPRτ versus TPRτ as a point and draw a curve connecting them. This gives the receiver operating characteristic (ROC) curve.
ROC curve is insensitive to changes in class distribution. Changes in the proportion of positive to negative instances in the (test) set do not cause change to the curve.
Precision-Recall (PR) curve.
F-scores.Fβ score is a combined statistics between precision (Prec) and recall (Rec).Useful for looking at a single threshold. F-score is affected by class distribution changes.
Classification Modeling
Three approaches for training and inference.
Generative Models. Train class conditional densities p(x∣Ck) for each class Ck individually. Then use Bayes theorem to compute the posterior probabilities:
“Generative” because by sampling from them, it is possible to generate synthetic data points in the input space.
Deterministic Models. Train posterior class probabilities p(Ck∣x). Then, use decision theory to perform inference to assign each new x to one of the classes.
Discriminative Models. Find a discriminant function f(x) that maps each input x directly onto a class label, e.g., for binary classification f might be binary valued such that f=0 represents class C1 and f=1 represents class C2.
Why compute posterior instead of discriminant function directly?.
Modular, For problems where loss matrix is revised from time to time, knowing posterior probabilities implies that we only need to modify minimum risk criterion without having to re-train the model.
Reject option. Posterior probabilities allow us to determine a rejection criterion that minimizes the expected loss for a given fraction of rejected data points
Can compensate different class priors. Model trained using one class prior can be adapted to new class prior
Combining models. Different posterior probabilities can be combined.
Discriminative Classifiers, Logistic Regression. Intuitively, we classify
Since S(Wx) is a vector of C probability values, softmax regression is based on a categorical distribution M whose parameters are precisely those C probability values:
p(y∣x;θ)=M(y∣θ),θ=S(Wx)
Log Sum Trick. When working with softmax distribution, we often want to compute the normalized probability. Define ai=wiTx
p(y=c∣x)=∑i=1Cexp(ai)exp(ac)=Z(a)exp(ac)
where Z(a) is the sum defined the same across all c.
Its computation may not be numerically stable.
Explosive expai, since ai could take a number 1000 for example
Division by Z(a)=0, since ai<−1000 there is possibility ∑iexpai=0
We choose m=maxi(ai) so that the largest exponential will be zero. Even if there’s underflow, the answer is still sensible.
Deep Neural Networks
Motivation
Motivation. When one uses linear models, one strongly assumes that the input-output mapping is linear. Model can be made more flexible by performing non linear feature transformation. But hand-crafting such transformation is very restrictive: curse of dimensionality. Real data does not live in all regions of the input space.
DNN as universal approximator, no free lunch theorem, and inductive bias
Heteroskedastic and Homoskedastic non linear regression.
Representation, Transfer, Multitask, and Meta Learning.
Contrastive Learning. Learn representation such that positive input pairs are close and negative input pairs are far part in embedding space. So error function is defined wrt inputs. Example is infoNCE loss.
If D=1, we say f is univariate. Otherwise multivariate.
If K=1, we say f is real-valued. Otherwise vector-valued.
Example definition of multivariate real-valued function of f(x)=xTx,x=(x1,x2) specifically specified as
f:R2→Rx→x12+x22
Different Quotient and Derivative in Univariate Real-Valued Function For a univariate real-valued function f(x), the difference quotient is given by
δxδf=δxf(x+δx)−f(x)
while the derivative is given by
dxdf=δx→0limδxf(x+δx)−f(x)
If the limit exists at then f is differentiable at x, and the derivative is the tangent of f at x. The derivative of f at points in the direction of the steepest ascent of f.
Partial Derivatives in Multivariate Real-Valued Function For a multivariate real-valued function f(x), the partial derivative with respect to xi is given by
Compact writing of chain rule as matrix multiplication only makes sense if the gradient is defined as a row vector. Otherwise, we will need to introduce transposes, which complicates the operation, especially when we are dealing with tensors of higher dimensions.
Vector-Valued Functions. We generalize to f:Rn→Rm.
The gradient of f wrt a column vector is a row vector of the partial derivatives. This is the Jacobian matrix Jij=∂xj∂fi.
Numerator Layout vs Denominator Layout. What we use before is numerator layout where i-th output function fi corresponds to the i-th row of the jacobian dxdf output matrix. Some authors use denominator layout which require transpose operation.
In general, for f:Rn→Rm, the derivative is in the dimension of output times input, dxdf∈Rm×n.
Gradients of Matrices. Gradient of matrices w.r.t. vectors (or other matrices) are multidimensional tensors. The rule is the same, output dimension times input dimension.
Flattening Approach to Gradients of Matrices. Given a matrix A∈Rm×n, flatten it into a vector vec(A)∈Rmn. Compute the gradient dvec(B)dvec(A) where B∈Rp×q, and reshape the resulting vector back R(m×n)×(p×q).
Kronecker product. Allows two matrices of arbitrary dimension to be multiplied. Given matrices A∈RM×N, B∈RP×Q, its Kronecker product A⊗B is a (MP×NQ)-matrix:
A⊗B=A11B⋮AM1B⋯⋱⋯A1NB⋮AMNB
Vector by Matrix Derivative using Vectorization and Kronecker Product.
Kronecker Product for Tensor Derivative.
Forward and Backward Propagation
Forward Autodiff. Good for small input large output.
vˉkvi connected to vj=∂xc∂vk, for all k for some c⟹viˉ=∂xc∂vi=∂vj∂vi∂xc∂vj=∂vj∂vivˉj
Backward Autodiff. Good for large input small output.
vˉkvi connected to vj=∂vk∂f, for all k⟹viˉ=∂vi∂f=∂vi∂vjvj∂f=∂vi∂vjvjˉ