Mathematics for Machine Learning: Multivariate Calculus

数学在机器学习领域的应用二:多元微积分

课程简介

This course offers a brief introduction to the multivariate calculus required to build many common machine learning techniques. We start at the very beginning with a refresher on the “rise over run” formulation of a slope, before converting this to the formal definition of the gradient of a function. We then start to build up a set of tools for making calculus easier and faster. Next, we learn how to calculate vectors that point up hill on multidimensional surfaces and even put this into action using an interactive game. We take a look at how we can use calculus to build approximations to functions, as well as helping us to quantify how accurate we should expect those approximations to be. We also spend some time talking about where calculus comes up in the training of neural networks, before finally showing you how it is applied in linear regression models. This course is intended to offer an intuitive understanding of calculus, as well as the language necessary to look concepts up yourselves when you get stuck. Hopefully, without going into too much detail, you’ll still come away with the confidence to dive into some more focused machine learning courses in future.

函数

函数是从输入到输出的映射,选择函数来建模世界的过程是伟大天才的科学目的,微积分只是对这些函数如何相对于它们的输入变量如何变化的研究。

导数(derivative)

对于线性函数而言,斜率(梯度、gradient)=‘rise over run’,也就是任意取两点,方向的距离与方向的距离之比即为梯度。

对于梯度一直在变化的函数来说,设函数为,任意取两点

即,

导数的求和法则:

幂函数求导法则:令,则

不连续(discontinuity)的函数,例如,在处没有定义,导数处也没有定义.

例如这种函数,,这种类型的函数与导数始终相等,因此有两个特点:

  1. 函数必须恒大于0或者恒小于0,如果函数改变符号,导数也会改变符号,会使得函数不改变符号,与定义不符
  2. 函数是单调的,因为函数永远不可能达到其原来的值

三角函数:

导数乘积法则:令,则

求导的链式法则:若,且,则

偏导数求导法则:

偏导数仍然遵循导数的求导法则

雅可比行列式(Jacobian)

设函数,它的雅可比行列式为

这样给予一组的值,可以快速得出函数在该点指向此函数最陡斜率方向的向量。

设函数,则它的雅可比行列式为

海森矩阵(The Hessian)

对雅可比行列式再求一次偏导数,构成的二阶偏导数矩阵为海森矩阵

设函数,它的雅可比行列式为,则海森矩阵为

雅可比行列式求得的值为0的情况下,首先求海森矩阵的行列式,如果行列式为正数,说明目前的点是一个极值点;然后看海森矩阵的第一个数字,如果第一个数字是正数,说明目前在极小值点,否则在极大值点;如果海森矩阵的行列式为负,说明目前的点是一个鞍点。

神经网络

最简单的神经网络:,其中,表示活动,表示权重,表示偏差,表示激活函数

输入可能不仅仅是一个,设输入的神经元有个,则

输出可能也不仅仅是一个,设输出的神经元有个,总体的神经网络表示为:

可以简化表示为:

如果神经网络不止一层,则可以表示为:

神经网络(分类任务)的损失函数为

泰勒展开式

泰勒展开式是对一个复杂函数的简化估计函数

(麦克劳林形式,需要知道零点)

泰勒形式:

(泰勒形式,知道任意一点即可)

二维泰勒展开

(零阶泰勒展开)
(一阶泰勒展开-雅可比行列式)

(二阶泰勒展开-海森矩阵)

牛顿迭代法(Newton-Raphson)

迭代求解方程的近似根:

这种方法会存在一些问题,如果选取的点比较靠近函数的拐点,会得不到正确的结果,或者得到的结果并不是与选取的点最接近的。

梯度下降

如何使用梯度找到多元函数的最大值或者最小值

函数的梯度:,即为函数值增加最快的方向

如果希望找到最大值,将梯度与它的单位向量相乘,则

梯度下降:

拉格朗日乘子法(Lagrange multipliers)

计算函数在某些约束下的最大值或者最小值

为拉格朗日乘子

即:

多元微积分在回归问题中的应用

线性回归

设函数

计算平方误差:

求解使得误差最小:

则可以解得:

非线性回归

  1. 梯度下降法
  2. 泰勒展开式+海森矩阵
  3. 莱文贝格-马夸特方法(Levenberg-Marquardt)
  4. 高斯-牛顿迭代法 (Gauss-Newton iteration method)
  5. 拟牛顿法(BFGS)

资料

Formula Sheet: Sheet summarising all the formulae covered in this course.

Code and Notebooks


Mathematics for Machine Learning: Multivariate Calculus
https://zhangzhao219.github.io/2022/07/31/Coursera/Mathematics-for-Machine-Learning-Multivariate-Calculus/
作者
Zhang Zhao
发布于
2022年7月31日
许可协议