Live data from Hacker News

Matrix Calculus (For Machine Learning and Beyond)

arxiv.org

21–30 of 31 posts

Re: Matrix Calculus (For Machine Learning and Beyond)

#22

Earlier quoted context omitted.

Can you give an example?

Check out this classic from 3b1b - How (and why) to raise e to the power of a matrix: https://youtu.be/O85OWBJ2ayo

For those who prefer reading (I’ve not seen the video, but it seems related):

https://sassafras13.github.io/MatrixExps/

“Thanks to a fabulous video by 3Blue1Brown [1], I am going to present some of the basic concepts behind matrix exponentials and why they are useful in robotics when we are writing down the kinematics and dynamics of a robot.”

Re: Matrix Calculus (For Machine Learning and Beyond)

#23
post #14

Earlier quoted context omitted.

I've only skimmed through both of them, so I might be entirely incorrect here, but isn't the essential approach a bit different for both? The MIT one emphasis not to view matrices as tables of entries, but instead as holistic mathematical objects. So when they perform the derivatives, they try to avoid the "element-wise" approach of differentiation, while the one by Parr et Howard seems to do the "element-wise" appro…

I got the same impression as you the Bright, Edelman, and Johnson (MIT) notes seems more driven my mathematicians where I find the Parr and Howard paper wanting. Though I agree with them > Note that you do not need to understand this material before you start learning to train and use deep learning in practice I have an alternative version > You don't need to know math to train good models, but you do need to know ma…

Regarding the math in ML, what I would love to see (links if you have any) is a nuanced take on the matter, showing examples from both sides. Like in good faith discussing what contributions one can make with and without a strong math background in the ML world.

edit: On the math side I've encountered one that seemed unique, as I haven't seen anything like this elsewhere: https://irregular-rhomboid.github.io/2022/12/07/applied-math.... However, this only points out courses that he enrolled in his math education that he thinks is relevant to ML, each course is given a very short description and or motivation as to the usefulness it has to ML.

I like this concluding remarks:

Through my curriculum, I learned about a broad variety of subjects that provide useful ideas and intuitions when applied to ML. Arguably the most valuable thing I got out of it is a rough map of mathematics that I can use to navigate and learn more advanced topics on my own.

Having already been exposed to these ideas, I wasn’t confused when I encountered them in ML papers. Rather, I could leverage them to get intuition about the ML part.

Strictly speaking, the only math that is actually needed for ML is real analysis, linear algebra, probability and optimization. And even there, your mileage may vary. Everything else is helpful, because it provides additional language and intuition. But if you’re trying to tackle hard problems like alignment or actually getting a grasp on what large neural nets actually do, you need all the intuition you can get. If you’re already confused about the simple cases, you have no hope of deconfusing the complex ones.

Re: Matrix Calculus (For Machine Learning and Beyond)

#24
post #11

Earlier quoted context omitted.

> Also, don't forget the Jacobian and gradient aren't the same thing! Every gradient is a Jacobian but not every Jacobian is a gradient. If you have a map f from R^n to R^m then the Jacobian at a point x is an m x n matrix which linearly approximates f at x. If m = 1 (namely if f is a scalar function) then the Jacobian is exactly the gradient. If you already know about gradients (e.g. from physics or ML) and can't qu…

For m = 1, the gradient is a "vector" (a column vector). The Jacobian is a functional/a linear map (a row vector, dual to a column vector). They're transposes of one another. For m > 1, I would normally just define the Jacobian as a linear map in the usual way and define the gradient to be its transpose. Remember that these are all just definitions at the end of the day and a little bit arbitrary.

I'd say a gradient is usually a covector / one-form. It's a map from vector directions to a scalar change. ie. df = f_x dx + f_y dy is what you can actually compute without a metric; it's in T*M, not TM. If you have a direction vector (e.g. 2 d/dx), you can get from there to a scalar.

Re: Matrix Calculus (For Machine Learning and Beyond)

#25
post #6

What does calculus mean ?

Calculus is the branch of mathematics that deals with continuous change. Broadly speaking there are two parts to it - differential calculus, which deals with rates of change and integral calculus which deals with areas, volumes and that sort of thing. Pretty early on you learn that these are essentially two sides of the same coin.

So in this particular instance since we are talking about matrix calculus it’s a type of multivariable calculus where you’re dealing with functions which take matrices as inputs and “matrix-valued functions” (ie functions which return matrices as an output).

Calculus is used for a lot of things but for example if you have a continuous function you can use calculus to find maxima and minima, inflection points etc. Since the focus here is machine learning, one of the most important things you want to be able to do is gradient descent to optimise some cost function by tweaking the weights on your model. The gradient here is a vector field which at every point in the space of your model points in the direction of steepest ascent[1]. So if you want to go down you take the gradient at a particular point and go exactly in the opposite direction. That means you know exactly what model weight tweaks will cause the biggest decrease in your cost function the next time you do a training run.

[1] To imagine the gradient, think of an old-school contour map like you’re going to do a hike or something. This is a “scalar field” (a map from spatial coordinates to a scalar value - altitude). The contour lines on the map link points of equal altitude. The gradient is a “vector field” which is a map from spatial coordinates to a vector. So imagine at every point on your contour map there was a little arrow that pointed in the direction of steepest ascent. Because this is matrix calculus you will be dealing with “matrix fields” (maps from spatial coordinates to matrices) as well. So for example say you did a measurement of stress in a steel beam. At each point you would have a “stress tensor” which says what the forces are at that point and in which direction they are pointing. This is a “tensor field” (map from spatial coordinates to a tensor) and a tensor is like a multidimensional matrix but with some additional rules about how it transforms.

Re: Matrix Calculus (For Machine Learning and Beyond)

#26

Earlier quoted context omitted.

For m = 1, the gradient is a "vector" (a column vector). The Jacobian is a functional/a linear map (a row vector, dual to a column vector). They're transposes of one another. For m > 1, I would normally just define the Jacobian as a linear map in the usual way and define the gradient to be its transpose. Remember that these are all just definitions at the end of the day and a little bit arbitrary.

I'd say a gradient is usually a covector / one-form. It's a map from vector directions to a scalar change. ie. df = f_x dx + f_y dy is what you can actually compute without a metric; it's in T*M, not TM. If you have a direction vector (e.g. 2 d/dx), you can get from there to a scalar.

I'm not a big Riemannian geometry buff, but I took a look at the definition in Do Carmo's book and it appears that "grad f" actually lies in TM, consistent with what I said above. Would love to learn more if I've got this mixed up.

This would be nice, because it would generalize the "gradient" from vector calculus, which is clearly and unambiguously a vector.

Re: Matrix Calculus (For Machine Learning and Beyond)

#27
post #3

The Matrix Cookbook [1] can be handy when learning this topic. https://www.math.uwaterloo.ca/~hwolkowi/matrixcookbook.pdf

I think this encourages "look it up" and "this layout is just a convention" when one convention is much more "natural" i.e. at a point x, a dual element df(x) acts on vectors y via df(x)(y) = .

I wouldn't teach it this way, but I would definitely take the taylor expansion and define the grad vector as the one to make the best local linear approximation. This tells you that the grad lives in the same space, i.e. same dimensions.

Of course, you can always switch things around if you want to calculate things and put in transposes where they belong. But I find it insane to take the unnatural view point as standard, which I find a lot of papers do.

Re: Matrix Calculus (For Machine Learning and Beyond)

#28

Earlier quoted context omitted.

Can you give an example?

Check out this classic from 3b1b - How (and why) to raise e to the power of a matrix: https://youtu.be/O85OWBJ2ayo

They didn't show how to actually do it using matrix decomposition!

Re: Matrix Calculus (For Machine Learning and Beyond)

#29

Earlier quoted context omitted.

I'd say a gradient is usually a covector / one-form. It's a map from vector directions to a scalar change. ie. df = f_x dx + f_y dy is what you can actually compute without a metric; it's in T*M, not TM. If you have a direction vector (e.g. 2 d/dx), you can get from there to a scalar.

I'm not a big Riemannian geometry buff, but I took a look at the definition in Do Carmo's book and it appears that "grad f" actually lies in TM, consistent with what I said above. Would love to learn more if I've got this mixed up. This would be nice, because it would generalize the "gradient" from vector calculus, which is clearly and unambiguously a vector.

It's probably just a notation/definition issue. I'm not sure if "grad f" is 100% consistently defined

I'm a simple-minded physicist. I just know if you apply the same coordinate transformation to the gradient and to the displacement vector, you get the wrong answer.

My usual reference is Schutz's Geometrical Methods of Mathematical Physics, and he defines the gradient as df, but other sources call that the "differential" and say the gradient is what you get if you use the metric to raise the indices of df.

But that raised-index gradient (i.e. g(df)), is weird and non-physical. It doesn't behave properly under coordinate transformations. So I'm not sure why folks use that definition.

You can see difference by looking at the differential in polar coordinates. If you have f=x+y, then df=dx+dy=(cos th + sin th)dr + r(cos th - sin th)d th. If you pretend this is instead a vector and transform it, you'd get "df"=(cos th + sin th)dr + (1/r)(cos th - sin th)d th, which just gives the wrong answer.

To be specific, if v=(1,1) in cartesian (ex,ey), then df(v)=2. But (1,1) in cartesian is (1,1/r) in polar (er, etheta). The "proper" df still gives 2, but the "weird metric one" gives 1+1/r^2, since you get the 1/r factor twice, instead of a 1/r and a balancing r.

Re: Matrix Calculus (For Machine Learning and Beyond)

#30
post #23

Earlier quoted context omitted.

I got the same impression as you the Bright, Edelman, and Johnson (MIT) notes seems more driven my mathematicians where I find the Parr and Howard paper wanting. Though I agree with them > Note that you do not need to understand this material before you start learning to train and use deep learning in practice I have an alternative version > You don't need to know math to train good models, but you do need to know ma…

Regarding the math in ML, what I would love to see (links if you have any) is a nuanced take on the matter, showing examples from both sides. Like in good faith discussing what contributions one can make with and without a strong math background in the ML world. edit: On the math side I've encountered one that seemed unique, as I haven't seen anything like this elsewhere: https://irregular-rhomboid.github.io/2022/12/…

I think that author's next article does a great job explaining. While they don't say it with these words, I'd say that by learning math you are able to speak the same language as the model. This does wonders for interpreting what is going on and why it is making certain decisions. The "black box" isn't transparent, but neither is it so dark. And it the space is so dark that you should be trying to shed any light that you can on it.

https://irregular-rhomboid.github.io/2022/12/27/math-is-a-la...

Post reply on HN