text stringlengths 0 65.5k | source stringclasses 21
values |
|---|---|
. . . . . . . . . . . . . . . . . . . . . . . . . 172
13.2 Densities and linear transformations . . . . . . . . . . . . . . . 173
13.3 ICA algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . . . . . . . . . 172
13.2 Densities and linear transformations . . . . . . . . . . . . . . . 173
13.3 ICA algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
14 Self-supervised learning and foundation models 177
14.1 Pretraining and adaptation . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . . . . 173
13.3 ICA algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
14 Self-supervised learning and foundation models 177
14.1 Pretraining and adaptation . . . . . . . . . . . . . . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . 173
13.3 ICA algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
14 Self-supervised learning and foundation models 177
14.1 Pretraining and adaptation . . . . . . . . . . . . . . . . . . . . 177
14.2 Pretraining methods in computer vision . . . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . . . . . . . . . . 174
14 Self-supervised learning and foundation models 177
14.1 Pretraining and adaptation . . . . . . . . . . . . . . . . . . . . 177
14.2 Pretraining methods in computer vision . . . . . . . . . . . . . 179
14.3 Pretrained large language models . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
174
14 Self-supervised learning and foundation models 177
14.1 Pretraining and adaptation . . . . . . . . . . . . . . . . . . . . 177
14.2 Pretraining methods in computer vision . . . . . . . . . . . . . 179
14.3 Pretrained large language models . . . . . . . . . . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . . . . . . . . . 177
14.2 Pretraining methods in computer vision . . . . . . . . . . . . . 179
14.3 Pretrained large language models . . . . . . . . . . . . . . . . 181
14.3.1 Open up the blackbox of Transformers . . . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . 177
14.2 Pretraining methods in computer vision . . . . . . . . . . . . . 179
14.3 Pretrained large language models . . . . . . . . . . . . . . . . 181
14.3.1 Open up the blackbox of Transformers . . . . . . . . . 183
14.3.2 Zero-shot learning and in-context learning . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . 179
14.3 Pretrained large language models . . . . . . . . . . . . . . . . 181
14.3.1 Open up the blackbox of Transformers . . . . . . . . . 183
14.3.2 Zero-shot learning and in-context learning . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . 179
14.3 Pretrained large language models . . . . . . . . . . . . . . . . 181
14.3.1 Open up the blackbox of Transformers . . . . . . . . . 183
14.3.2 Zero-shot learning and in-context learning . . . . . . . 186
CS229 Spring 20223 4
V Reinforcement Learning and Control 188
15 Reinforcement learning 189
... | https://cs229.stanford.edu/main_notes.pdf |
. . . 181
14.3.1 Open up the blackbox of Transformers . . . . . . . . . 183
14.3.2 Zero-shot learning and in-context learning . . . . . . . 186
CS229 Spring 20223 4
V Reinforcement Learning and Control 188
15 Reinforcement learning 189
15.1 Markov decision processes . . . . . . . . . . . . . . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . 183
14.3.2 Zero-shot learning and in-context learning . . . . . . . 186
CS229 Spring 20223 4
V Reinforcement Learning and Control 188
15 Reinforcement learning 189
15.1 Markov decision processes . . . . . . . . . . . . . . . . . . . . 190
15.2 Value iteration and policy iteration . . . . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . 186
CS229 Spring 20223 4
V Reinforcement Learning and Control 188
15 Reinforcement learning 189
15.1 Markov decision processes . . . . . . . . . . . . . . . . . . . . 190
15.2 Value iteration and policy iteration . . . . . . . . . . . . . . . 192
15.3 Learning a model for an MDP . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . . . . . . . . . 190
15.2 Value iteration and policy iteration . . . . . . . . . . . . . . . 192
15.3 Learning a model for an MDP . . . . . . . . . . . . . . . . . . 194
15.4 Continuous state MDPs . . . . . . . . . . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . . . . 192
15.3 Learning a model for an MDP . . . . . . . . . . . . . . . . . . 194
15.4 Continuous state MDPs . . . . . . . . . . . . . . . . . . . . . 196
15.4.1 Discretization . . . . . . . . . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . . . . . . . 194
15.4 Continuous state MDPs . . . . . . . . . . . . . . . . . . . . . 196
15.4.1 Discretization . . . . . . . . . . . . . . . . . . . . . . . 196
15.4.2 Value function approximation . . . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . . . . . . . . . . 196
15.4.1 Discretization . . . . . . . . . . . . . . . . . . . . . . . 196
15.4.2 Value function approximation . . . . . . . . . . . . . . 199
15.5 Connections between Policy and Value Iteration (Optional) . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . 196
15.4.1 Discretization . . . . . . . . . . . . . . . . . . . . . . . 196
15.4.2 Value function approximation . . . . . . . . . . . . . . 199
15.5 Connections between Policy and Value Iteration (Optional) . . 203
16 LQR, DDP and LQG 206
16.1 Finite-horizon MDPs . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . 196
15.4.2 Value function approximation . . . . . . . . . . . . . . 199
15.5 Connections between Policy and Value Iteration (Optional) . . 203
16 LQR, DDP and LQG 206
16.1 Finite-horizon MDPs . . . . . . . . . . . . . . . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . . . 199
15.5 Connections between Policy and Value Iteration (Optional) . . 203
16 LQR, DDP and LQG 206
16.1 Finite-horizon MDPs . . . . . . . . . . . . . . . . . . . . . . . 206
16.2 Linear Quadratic Regulation (LQR) . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. 203
16 LQR, DDP and LQG 206
16.1 Finite-horizon MDPs . . . . . . . . . . . . . . . . . . . . . . . 206
16.2 Linear Quadratic Regulation (LQR) . . . . . . . . . . . . . . . 210
16.3 From non-linear dynamics to LQR . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . . . . . . . . . . . . 206
16.2 Linear Quadratic Regulation (LQR) . . . . . . . . . . . . . . . 210
16.3 From non-linear dynamics to LQR . . . . . . . . . . . . . . . 213
16.3.1 Linearization of dynamics . . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . 206
16.2 Linear Quadratic Regulation (LQR) . . . . . . . . . . . . . . . 210
16.3 From non-linear dynamics to LQR . . . . . . . . . . . . . . . 213
16.3.1 Linearization of dynamics . . . . . . . . . . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . . . . 210
16.3 From non-linear dynamics to LQR . . . . . . . . . . . . . . . 213
16.3.1 Linearization of dynamics . . . . . . . . . . . . . . . . 214
16.3.2 Differential Dynamic Programming (DDP) . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . . . . 213
16.3.1 Linearization of dynamics . . . . . . . . . . . . . . . . 214
16.3.2 Differential Dynamic Programming (DDP) . . . . . . . 214
16.4 Linear Quadratic Gaussian (LQG) . . . . . . . . . . . . . . . . | https://cs229.stanford.edu/main_notes.pdf |
. . . . . . . . . . . . . . . 214
16.3.2 Differential Dynamic Programming (DDP) . . . . . . . 214
16.4 Linear Quadratic Gaussian (LQG) . . . . . . . . . . . . . . . . 216
17 Policy Gradient (REINFORCE) 220
Part I
Supervised learning
5
6
Let’s start by talking about a few examples of supervised learning prob-
lems. | https://cs229.stanford.edu/main_notes.pdf |
. . . . 214
16.4 Linear Quadratic Gaussian (LQG) . . . . . . . . . . . . . . . . 216
17 Policy Gradient (REINFORCE) 220
Part I
Supervised learning
5
6
Let’s start by talking about a few examples of supervised learning prob-
lems. Suppose we have a dataset giving the living areas and prices of 47
houses from Portland, O... | https://cs229.stanford.edu/main_notes.pdf |
To establish notation for future use, we’ll use x(i) to denote the “input”
variables (living area in this example), also called input features, and y(i)
to denote the “output” or target variable that we are trying to predict
(price). | https://cs229.stanford.edu/main_notes.pdf |
To establish notation for future use, we’ll use x(i) to denote the “input”
variables (living area in this example), also called input features, and y(i)
to denote the “output” or target variable that we are trying to predict
(price). A pair ( x(i),y(i)) is called a training example , and the dataset
that we’ll be using... | https://cs229.stanford.edu/main_notes.pdf |
A pair ( x(i),y(i)) is called a training example , and the dataset
that we’ll be using to learn—a list of n training examples {(x(i),y(i)); i =
1,...,n }—is called a training set. Note that the superscript “( i)” in the
notation is simply an index into the training set, and has nothing to do with
exponentiation. | https://cs229.stanford.edu/main_notes.pdf |
Note that the superscript “( i)” in the
notation is simply an index into the training set, and has nothing to do with
exponentiation. We will also use Xdenote the space of input values, and Y
the space of output values. | https://cs229.stanford.edu/main_notes.pdf |
Note that the superscript “( i)” in the
notation is simply an index into the training set, and has nothing to do with
exponentiation. We will also use Xdenote the space of input values, and Y
the space of output values. In this example, X= Y= R.
To describe the supervised learning problem slightly more formally, our
go... | https://cs229.stanford.edu/main_notes.pdf |
In this example, X= Y= R.
To describe the supervised learning problem slightly more formally, our
goal is, given a training set, to learn a function h: X↦→Y so that h(x) is a
“good” predictor for the corresponding value of y. For historical reasons, this
7
function h is called a hypothesis. | https://cs229.stanford.edu/main_notes.pdf |
In this example, X= Y= R.
To describe the supervised learning problem slightly more formally, our
goal is, given a training set, to learn a function h: X↦→Y so that h(x) is a
“good” predictor for the corresponding value of y. For historical reasons, this
7
function h is called a hypothesis. Seen pictorially, the proces... | https://cs229.stanford.edu/main_notes.pdf |
For historical reasons, this
7
function h is called a hypothesis. Seen pictorially, the process is therefore
like this:
Training
set
house.) (living area of
Learning
algorithm
h predicted y x
(predicted price)
of house)
When the target variable that we’re trying to predict is continuous, such
as in our housing e... | https://cs229.stanford.edu/main_notes.pdf |
(living area of
Learning
algorithm
h predicted y x
(predicted price)
of house)
When the target variable that we’re trying to predict is continuous, such
as in our housing example, we call the learning problem a regression prob-
lem. When y can take on only a small number of discrete values (such as
if, given the livin... | https://cs229.stanford.edu/main_notes.pdf |
When y can take on only a small number of discrete values (such as
if, given the living area, we wanted to predict if a dwelling is a house or an
apartment, say), we call it a classification problem. Chapter 1
Linear regression
To make our housing example more interesting, let’s consider a slightly richer
dataset in whi... | https://cs229.stanford.edu/main_notes.pdf |
Here, the x’s are two-dimensional vectors in R2. For instance, x(i)
1 is the
living area of the i-th house in the training set, and x(i)
2 is its number of
bedrooms. | https://cs229.stanford.edu/main_notes.pdf |
Here, the x’s are two-dimensional vectors in R2. For instance, x(i)
1 is the
living area of the i-th house in the training set, and x(i)
2 is its number of
bedrooms. (In general, when designing a learning problem, it will be up to
you to decide what features to choose, so if you are out in Portland gathering
housing da... | https://cs229.stanford.edu/main_notes.pdf |
(In general, when designing a learning problem, it will be up to
you to decide what features to choose, so if you are out in Portland gathering
housing data, you might also decide to include other features such as whether
each house has a fireplace, the number of bathrooms, and so on. We’ll say
more about feature select... | https://cs229.stanford.edu/main_notes.pdf |
We’ll say
more about feature selection later, but for now let’s take the features as
given.) To perform supervised learning, we must decide how we’re going to rep-
resent functions/hypotheses h in a computer. | https://cs229.stanford.edu/main_notes.pdf |
We’ll say
more about feature selection later, but for now let’s take the features as
given.) To perform supervised learning, we must decide how we’re going to rep-
resent functions/hypotheses h in a computer. As an initial choice, let’s say
we decide to approximate y as a linear function of x:
hθ(x) = θ0 + θ1x1 + θ2x2
... | https://cs229.stanford.edu/main_notes.pdf |
As an initial choice, let’s say
we decide to approximate y as a linear function of x:
hθ(x) = θ0 + θ1x1 + θ2x2
Here, the θi’s are the parameters (also called weights) parameterizing the
space of linear functions mapping from X to Y. When there is no risk of
8
9
confusion, we will drop the θ subscript in hθ(x), and writ... | https://cs229.stanford.edu/main_notes.pdf |
When there is no risk of
8
9
confusion, we will drop the θ subscript in hθ(x), and write it more simply as
h(x). To simplify our notation, we also introduce the convention of letting
x0 = 1 (this is the intercept term), so that
h(x) =
d∑
i=0
θixi = θTx,
where on the right-hand side above we are viewing θ and x both as ... | https://cs229.stanford.edu/main_notes.pdf |
Now, given a training set, how do we pick, or learn, the parameters θ? One reasonable method seems to be to make h(x) close to y, at least for
the training examples we have. | https://cs229.stanford.edu/main_notes.pdf |
Now, given a training set, how do we pick, or learn, the parameters θ? One reasonable method seems to be to make h(x) close to y, at least for
the training examples we have. To formalize this, we will define a function
that measures, for each value of the θ’s, how close the h(x(i))’s are to the
corresponding y(i)’s. | https://cs229.stanford.edu/main_notes.pdf |
To formalize this, we will define a function
that measures, for each value of the θ’s, how close the h(x(i))’s are to the
corresponding y(i)’s. We define the cost function:
J(θ) = 1
2
n∑
i=1
(hθ(x(i)) −y(i))2. | https://cs229.stanford.edu/main_notes.pdf |
We define the cost function:
J(θ) = 1
2
n∑
i=1
(hθ(x(i)) −y(i))2. If you’ve seen linear regression before, you may recognize this as the familiar
least-squares cost function that gives rise to the ordinary least squares
regression model. | https://cs229.stanford.edu/main_notes.pdf |
If you’ve seen linear regression before, you may recognize this as the familiar
least-squares cost function that gives rise to the ordinary least squares
regression model. Whether or not you have seen it previously, let’s keep
going, and we’ll eventually show this to be a special case of a much broader
family of algori... | https://cs229.stanford.edu/main_notes.pdf |
Whether or not you have seen it previously, let’s keep
going, and we’ll eventually show this to be a special case of a much broader
family of algorithms. 1.1 LMS algorithm
We want to choose θ so as to minimize J(θ). To do so, let’s use a search
algorithm that starts with some “initial guess” for θ, and that repeatedly
... | https://cs229.stanford.edu/main_notes.pdf |
To do so, let’s use a search
algorithm that starts with some “initial guess” for θ, and that repeatedly
changes θ to make J(θ) smaller, until hopefully we converge to a value of
θ that minimizes J(θ). Specifically, let’s consider the gradient descent
algorithm, which starts with some initial θ, and repeatedly performs t... | https://cs229.stanford.edu/main_notes.pdf |
Specifically, let’s consider the gradient descent
algorithm, which starts with some initial θ, and repeatedly performs the
update:
θj := θj −α ∂
∂θj
J(θ). (This update is simultaneously performed for all values of j = 0 ,...,d .) Here, α is called the learning rate. | https://cs229.stanford.edu/main_notes.pdf |
(This update is simultaneously performed for all values of j = 0 ,...,d .) Here, α is called the learning rate. This is a very natural algorithm that
repeatedly takes a step in the direction of steepest decrease of J. In order to implement this algorithm, we have to work out what is the
partial derivative term on the r... | https://cs229.stanford.edu/main_notes.pdf |
(This update is simultaneously performed for all values of j = 0 ,...,d .) Here, α is called the learning rate. This is a very natural algorithm that
repeatedly takes a step in the direction of steepest decrease of J. In order to implement this algorithm, we have to work out what is the
partial derivative term on the r... | https://cs229.stanford.edu/main_notes.pdf |
In order to implement this algorithm, we have to work out what is the
partial derivative term on the right hand side. Let’s first work it out for the
10
case of if we have only one training example ( x,y), so that we can neglect
the sum in the definition of J. We have:
∂
∂θj
J(θ) = ∂
∂θj
1
2 (hθ(x) −y)2
= 2 ·1
2 (hθ(x) −... | https://cs229.stanford.edu/main_notes.pdf |
The rule is called theLMS update rule (LMS stands for “least mean squares”),
and is also known as the Widrow-Hoff learning rule. This rule has several
properties that seem natural and intuitive. | https://cs229.stanford.edu/main_notes.pdf |
The rule is called theLMS update rule (LMS stands for “least mean squares”),
and is also known as the Widrow-Hoff learning rule. This rule has several
properties that seem natural and intuitive. For instance, the magnitude of
the update is proportional to the error term (y(i) −hθ(x(i))); thus, for in-
stance, if we are ... | https://cs229.stanford.edu/main_notes.pdf |
We’d derived the LMS rule for when there was only a single training
example. There are two ways to modify this method for a training set of
more than one example. | https://cs229.stanford.edu/main_notes.pdf |
We’d derived the LMS rule for when there was only a single training
example. There are two ways to modify this method for a training set of
more than one example. The first is replace it with the following algorithm:
Repeat until convergence {
θj := θj + α
n∑
i=1
(
y(i) −hθ(x(i))
)
x(i)
j ,(for every j) (1.1)
}
1We use ... | https://cs229.stanford.edu/main_notes.pdf |
In other words, this
operation overwrites awith the value of b. In contrast, we will write “ a= b” when we are
asserting a statement of fact, that the value of a is equal to the value of b. | https://cs229.stanford.edu/main_notes.pdf |
In other words, this
operation overwrites awith the value of b. In contrast, we will write “ a= b” when we are
asserting a statement of fact, that the value of a is equal to the value of b. 11
By grouping the updates of the coordinates into an update of the vector
θ, we can rewrite update (1.1) in a slightly more succi... | https://cs229.stanford.edu/main_notes.pdf |
So, this
is simply gradient descent on the original cost function J. This method looks
at every example in the entire training set on every step, and is called batch
gradient descent. | https://cs229.stanford.edu/main_notes.pdf |
So, this
is simply gradient descent on the original cost function J. This method looks
at every example in the entire training set on every step, and is called batch
gradient descent. Note that, while gradient descent can be susceptible
to local minima in general, the optimization problem we have posed here
for linear ... | https://cs229.stanford.edu/main_notes.pdf |
Note that, while gradient descent can be susceptible
to local minima in general, the optimization problem we have posed here
for linear regression has only one global, and no other local, optima; thus
gradient descent always converges (assuming the learning rate α is not too
large) to the global minimum. Indeed, J is a... | https://cs229.stanford.edu/main_notes.pdf |
Indeed, J is a convex quadratic function. Here is an example of gradient descent as it is run to minimize a quadratic
function. 5 10 15 20 25 30 35 40 45 50
5
10
15
20
25
30
35
40
45
50
The ellipses shown above are the contours of a quadratic function. | https://cs229.stanford.edu/main_notes.pdf |
Indeed, J is a convex quadratic function. Here is an example of gradient descent as it is run to minimize a quadratic
function. 5 10 15 20 25 30 35 40 45 50
5
10
15
20
25
30
35
40
45
50
The ellipses shown above are the contours of a quadratic function. Also
shown is the trajectory taken by gradient descent, which was i... | https://cs229.stanford.edu/main_notes.pdf |
5 10 15 20 25 30 35 40 45 50
5
10
15
20
25
30
35
40
45
50
The ellipses shown above are the contours of a quadratic function. Also
shown is the trajectory taken by gradient descent, which was initialized at
(48,30). The x’s in the figure (joined by straight lines) mark the successive
values of θ that gradient descent wen... | https://cs229.stanford.edu/main_notes.pdf |
Also
shown is the trajectory taken by gradient descent, which was initialized at
(48,30). The x’s in the figure (joined by straight lines) mark the successive
values of θ that gradient descent went through. When we run batch gradient descent to fit θ on our previous dataset,
to learn to predict housing price as a functio... | https://cs229.stanford.edu/main_notes.pdf |
When we run batch gradient descent to fit θ on our previous dataset,
to learn to predict housing price as a function of living area, we obtain
θ0 = 71.27, θ1 = 0.1345. If we plot hθ(x) as a function of x (area), along
with the training data, we obtain the following figure:
12
500 1000 1500 2000 2500 3000 3500 4000 4500 5... | https://cs229.stanford.edu/main_notes.pdf |
The above results were obtained with batch gradient descent. There is
an alternative to batch gradient descent that also works very well. | https://cs229.stanford.edu/main_notes.pdf |
The above results were obtained with batch gradient descent. There is
an alternative to batch gradient descent that also works very well. Consider
the following algorithm:
Loop {
for i= 1 to n, {
θj := θj + α
(
y(i) −hθ(x(i))
)
x(i)
j , (for every j) (1.2)
}
}
By grouping the updates of the coordinates into an update o... | https://cs229.stanford.edu/main_notes.pdf |
This algorithm is called stochastic gradient descent (also incremental
gradient descent). Whereas batch gradient descent has to scan through
the entire training set before taking a single step—a costly operation if n is
large—stochastic gradient descent can start making progress right away, and
13
continues to make pro... | https://cs229.stanford.edu/main_notes.pdf |
This algorithm is called stochastic gradient descent (also incremental
gradient descent). Whereas batch gradient descent has to scan through
the entire training set before taking a single step—a costly operation if n is
large—stochastic gradient descent can start making progress right away, and
13
continues to make pro... | https://cs229.stanford.edu/main_notes.pdf |
Often, stochastic
gradient descent gets θ “close” to the minimum much faster than batch gra-
dient descent. (Note however that it may never “converge” to the minimum,
and the parameters θ will keep oscillating around the minimum of J(θ); but
in practice most of the values near the minimum will be reasonably good
approx... | https://cs229.stanford.edu/main_notes.pdf |
1.2 The normal equations
Gradient descent gives one way of minimizing J. Let’s discuss a second way
of doing so, this time performing the minimization explicitly and without
resorting to an iterative algorithm. In this method, we will minimize J by
explicitly taking its derivatives with respect to the θj’s, and setting... | https://cs229.stanford.edu/main_notes.pdf |
In this method, we will minimize J by
explicitly taking its derivatives with respect to the θj’s, and setting them to
zero. To enable us to do this without having to write reams of algebra and
pages full of matrices of derivatives, let’s introduce some notation for doing
calculus with matrices. | https://cs229.stanford.edu/main_notes.pdf |
In this method, we will minimize J by
explicitly taking its derivatives with respect to the θj’s, and setting them to
zero. To enable us to do this without having to write reams of algebra and
pages full of matrices of derivatives, let’s introduce some notation for doing
calculus with matrices. 1.2.1 Matrix derivatives... | https://cs229.stanford.edu/main_notes.pdf |
For example, suppose A =
[
A11 A12
A21 A22
]
is a 2-by-2 matrix, and
the function f : R2×2 ↦→R is given by
f(A) = 3
2A11 + 5A2
12 + A21A22. | https://cs229.stanford.edu/main_notes.pdf |
For example, suppose A =
[
A11 A12
A21 A22
]
is a 2-by-2 matrix, and
the function f : R2×2 ↦→R is given by
f(A) = 3
2A11 + 5A2
12 + A21A22. 2By slowly letting the learning rate α decrease to zero as the algorithm runs, it is also
possible to ensure that the parameters will converge to the global minimum rather than
mer... | https://cs229.stanford.edu/main_notes.pdf |
2By slowly letting the learning rate α decrease to zero as the algorithm runs, it is also
possible to ensure that the parameters will converge to the global minimum rather than
merely oscillate around the minimum. 14
Here, Aij denotes the (i,j) entry of the matrix A. We then have
∇Af(A) =
[ 3
2 10A12
A22 A21
]
. | https://cs229.stanford.edu/main_notes.pdf |
14
Here, Aij denotes the (i,j) entry of the matrix A. We then have
∇Af(A) =
[ 3
2 10A12
A22 A21
]
. 1.2.2 Least squares revisited
Armed with the tools of matrix derivatives, let us now proceed to find in
closed-form the value of θ that minimizes J(θ). | https://cs229.stanford.edu/main_notes.pdf |
We then have
∇Af(A) =
[ 3
2 10A12
A22 A21
]
. 1.2.2 Least squares revisited
Armed with the tools of matrix derivatives, let us now proceed to find in
closed-form the value of θ that minimizes J(θ). We begin by re-writing J in
matrix-vectorial notation. | https://cs229.stanford.edu/main_notes.pdf |
1.2.2 Least squares revisited
Armed with the tools of matrix derivatives, let us now proceed to find in
closed-form the value of θ that minimizes J(θ). We begin by re-writing J in
matrix-vectorial notation. Given a training set, define thedesign matrix X to be the n-by-dmatrix
(actually n-by-d + 1, if we include the inte... | https://cs229.stanford.edu/main_notes.pdf |
Also, let ⃗ ybe the n-dimensional vector containing all the target values from
the training set:
⃗ y=
y(1)
y(2)
...
y(n)
. | https://cs229.stanford.edu/main_notes.pdf |
Now, since hθ(x(i)) = (x(i))Tθ, we can easily verify that
Xθ −⃗ y=
(x(1))Tθ
...
(x(n))Tθ
−
y(1)
...
y(n)
=
hθ(x(1)) −y(1)
...
hθ(x(n)) −y(n)
. | https://cs229.stanford.edu/main_notes.pdf |
Thus, using the fact that for a vector z, we have that zTz = ∑
iz2
i:
1
2(Xθ −⃗ y)T(Xθ −⃗ y) = 1
2
n∑
i=1
(hθ(x(i)) −y(i))2
= J(θ)
15
Finally, to minimize J, let’s find its derivatives with respect to θ. | https://cs229.stanford.edu/main_notes.pdf |
Hence,
∇θJ(θ) = ∇θ
1
2(Xθ −⃗ y)T(Xθ −⃗ y)
= 1
2∇θ
(
(Xθ)TXθ −(Xθ)T⃗ y−⃗ yT(Xθ) + ⃗ yT⃗ y
)
= 1
2∇θ
(
θT(XTX)θ−⃗ yT(Xθ) −⃗ yT(Xθ)
)
= 1
2∇θ
(
θT(XTX)θ−2(XT⃗ y)Tθ
)
= 1
2
(
2XTXθ −2XT⃗ y
)
= XTXθ −XT⃗ y
In the third step, we used the fact that aTb = bTa, and in the fifth step
used the facts ∇xbTx= b and ∇xxTAx= 2Ax for sy... | https://cs229.stanford.edu/main_notes.pdf |
To
minimize J, we set its derivatives to zero, and obtain thenormal equations:
XTXθ = XT⃗ y
Thus, the value of θ that minimizes J(θ) is given in closed form by the
equation
θ= (XTX)−1XT⃗ y.3
1.3 Probabilistic interpretation
When faced with a regression problem, why might linear regression, and
specifically why might the... | https://cs229.stanford.edu/main_notes.pdf |
In this section, we will give a set of probabilistic assumptions, under
which least-squares regression is derived as a very natural algorithm. Let us assume that the target variables and the inputs are related via the
equation
y(i) = θTx(i) + ϵ(i),
3Note that in the above step, we are implicitly assuming that XTX is an... | https://cs229.stanford.edu/main_notes.pdf |
Let us assume that the target variables and the inputs are related via the
equation
y(i) = θTx(i) + ϵ(i),
3Note that in the above step, we are implicitly assuming that XTX is an invertible
matrix. This can be checked before calculating the inverse. If either the number of
linearly independent examples is fewer than the... | https://cs229.stanford.edu/main_notes.pdf |
This can be checked before calculating the inverse. If either the number of
linearly independent examples is fewer than the number of features, or if the features
are not linearly independent, then XTX will not be invertible. Even in such cases, it is
possible to “fix” the situation with additional techniques, which we ... | https://cs229.stanford.edu/main_notes.pdf |
If either the number of
linearly independent examples is fewer than the number of features, or if the features
are not linearly independent, then XTX will not be invertible. Even in such cases, it is
possible to “fix” the situation with additional techniques, which we skip here for the sake
of simplicty. 16
where ϵ(i) i... | https://cs229.stanford.edu/main_notes.pdf |
16
where ϵ(i) is an error term that captures either unmodeled effects (such as
if there are some features very pertinent to predicting housing price, but
that we’d left out of the regression), or random noise. Let us further assume
that the ϵ(i) are distributed IID (independently and identically distributed)
according t... | https://cs229.stanford.edu/main_notes.pdf |
Let us further assume
that the ϵ(i) are distributed IID (independently and identically distributed)
according to a Gaussian distribution (also called a Normal distribution) with
mean zero and some variance σ2. We can write this assumption as “ ϵ(i) ∼
N(0,σ2).” I.e., the density of ϵ(i) is given by
p(ϵ(i)) = 1√
2πσ exp
... | https://cs229.stanford.edu/main_notes.pdf |
We can write this assumption as “ ϵ(i) ∼
N(0,σ2).” I.e., the density of ϵ(i) is given by
p(ϵ(i)) = 1√
2πσ exp
(
−(ϵ(i))2
2σ2
)
. This implies that
p(y(i)|x(i); θ) = 1√
2πσ exp
(
−(y(i) −θTx(i))2
2σ2
)
. | https://cs229.stanford.edu/main_notes.pdf |
This implies that
p(y(i)|x(i); θ) = 1√
2πσ exp
(
−(y(i) −θTx(i))2
2σ2
)
. The notation “ p(y(i)|x(i); θ)” indicates that this is the distribution of y(i)
given x(i) and parameterized by θ. | https://cs229.stanford.edu/main_notes.pdf |
The notation “ p(y(i)|x(i); θ)” indicates that this is the distribution of y(i)
given x(i) and parameterized by θ. Note that we should not condition on θ
(“p(y(i)|x(i),θ)”), since θ is not a random variable. | https://cs229.stanford.edu/main_notes.pdf |
Note that we should not condition on θ
(“p(y(i)|x(i),θ)”), since θ is not a random variable. We can also write the
distribution of y(i) as y(i) |x(i); θ∼N(θTx(i),σ2). | https://cs229.stanford.edu/main_notes.pdf |
Note that we should not condition on θ
(“p(y(i)|x(i),θ)”), since θ is not a random variable. We can also write the
distribution of y(i) as y(i) |x(i); θ∼N(θTx(i),σ2). Given X (the design matrix, which contains all the x(i)’s) and θ, what
is the distribution of the y(i)’s? | https://cs229.stanford.edu/main_notes.pdf |
We can also write the
distribution of y(i) as y(i) |x(i); θ∼N(θTx(i),σ2). Given X (the design matrix, which contains all the x(i)’s) and θ, what
is the distribution of the y(i)’s? The probability of the data is given by
p(⃗ y|X; θ). | https://cs229.stanford.edu/main_notes.pdf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.