# Maths Notation in Andrew Ng's CS229 course online

I have just started Andrew Ng's Machine Learning course of which a legacy version is online. Here are the notes I am using, it is lecture two of the series on youtube too:

He derives an equation for LMS/ gradient descent. I thought I understood the derivation until the $x^{(i)}_j$ (raised i, lowered j) I do not understand what this means! I thought it was perhaps a matrix index but that would be both lowered, it is to do with the summation and the iteration separately, I believe, but do not understand what this would represent (is the last $x$ on the right meaning $x_1, x_2,\dots, x_n$ summed but then what is the $j$?). A simple example would help! If anyone could help out that would be much appreciated. Thanks

To make it abundantly clear (I took the same course), Andrew Ng's notation uses superscripts to index examples, and subscripts to denote features.

Hence, if we are looking at some botanical study, and collect data on a grove of trees, the tree labeled $\text{number } 25$ would be an example in the training data, and the features measured on the tree would be expressed as a vector of the form:

$$\small x^{(25)}=\left( x^{(25)}_1, x^{(25)}_2,\dots,x^{(25)}_n \right)=\small\left(x^{(25)}_1 = \text{height}; \,x^{(25)}_2 = \text{crown diameter};\,\dots, \,x^{(25)}_n=\text{trunk diameter}\right)$$

So the updating sums over each $i$ examples (subjects if you imagine a medical study), simultaneously for every $j$ (for every feature).

Notice that in calculating the gradient, we obtain partial derivatives of a quadratic, $(h_\theta(x)-y)^2$ form, such as the $\color{blue}{2}(h_\theta(x)-y)$ will cancel out with a $\frac{1}{2}$ inserted in the $J(\theta)$ formula for this purpose.

When you apply the chain rule, you end up getting the partial of inside of the parenthesis $h_\theta(x)-y$ for every feature $j$, running into the "unfolding" of $h_\theta(x)$, which, for the tree in the example above, is really the dot product of the vector $x^{(25)}$ ("for all $j$) with the vector of weights as they are at any particular iteration. However, $h_\theta(x)$ updates factoring the input from all the examples (subjects or trees).

$x_i^{(j)}$ designates the value of the $i^{\text {th}}$ feature of the $j^ {\text {th}}$ sample in the training set.