<?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Mathematical Foundations · Tommy Cheese</title>
    <link>https://tommycheese.github.io/en/tags/%E6%95%B0%E5%AD%A6%E5%9F%BA%E7%A1%80/</link>
    <description>Tommy Cheese’s personal blog on software engineering, artificial intelligence, and learning through practice.</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Fri, 01 Sep 2023 22:53:58 +0530</lastBuildDate>
    <atom:link href="https://tommycheese.github.io/en/tags/%E6%95%B0%E5%AD%A6%E5%9F%BA%E7%A1%80/index.xml" rel="self" type="application/rss+xml"/>
    <item>
      <title>Beyond the Gradient: The Hessian Matrix</title>
      <link>https://tommycheese.github.io/en/blogs/h/</link>
      <pubDate>Fri, 01 Sep 2023 22:53:58 +0530</pubDate>
      <guid>https://tommycheese.github.io/en/blogs/h/</guid>
      <description>&lt;p&gt;This article explores the Hessian matrix, a powerful mathematical tool for studying gradient descent. Before discussing the Hessian, we first need the basic concepts of gradients and the Jacobian matrix.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;⭐ This article assumes familiarity with gradient descent and basic numerical analysis and linear algebra.
&lt;a href="https://tommycheese.github.io/blogs/%E6%A2%AF%E5%BA%A6%E4%B9%8B%E4%B8%8Ahessian-%E7%9F%A9%E9%98%B5/"&gt;Original article&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="梯度雅克比矩阵"&gt;Gradients and the Jacobian Matrix&lt;/h2&gt;
&lt;p&gt;Gradient descent requires derivative information at the current point of a function. For a function with multiple input directions, its gradient is the vector of partial derivatives in those directions.&lt;/p&gt;
&lt;p&gt;The discussion above assumes &lt;strong&gt;a single output&lt;/strong&gt;. When the function’s output is also a vector, we must take the gradient of each output element with respect to the inputs and &lt;strong&gt;stack them together&lt;/strong&gt;. The resulting matrix is the &lt;strong&gt;Jacobian matrix&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If a function $f$ takes three inputs $x1、x2、x3$ and produces one output $y$, its gradient is:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;$$
\begin{equation}
Grad = [\frac{\partial y}{\partial x_1}, \frac{\partial y}{\partial x_2}, \frac{\partial y}{\partial x_3}]
\end{equation}
$$&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If a function $f2$ takes three inputs $x1、x2、x3$ and produces three outputs $y1、y2、y3$, its Jacobian is:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;$$
\begin{equation}
Jacobian  = \begin{bmatrix}
\frac{\partial y_1}{\partial x_1} &amp;amp;  \frac{\partial y_1}{\partial x_2}&amp;amp;\frac{\partial y_1}{\partial x_3} \
\frac{\partial y_2}{\partial x_1} &amp;amp;  \frac{\partial y_2}{\partial x_2}&amp;amp;\frac{\partial y_2}{\partial x_3} \
\frac{\partial y_3}{\partial x_1} &amp;amp;  \frac{\partial y_3}{\partial x_2}&amp;amp;\frac{\partial y_3}{\partial x_3}
\end{bmatrix}
\end{equation}
$$&lt;/p&gt;
&lt;p&gt;Second derivatives describe the curvature of a function in a particular direction $d$. This information helps anticipate the behavior of gradient descent. Along direction $d$:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If the second derivative is positive, the first derivative increases along $d$, and the function value decreases more slowly.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the second derivative is negative, the first derivative decreases along $d$, and the function value decreases more quickly.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the second derivative is zero, the first derivative remains constant along $d$, and the function value decreases at a constant rate.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;⭐ Gradient descent reduces a loss function, so we analyze how derivatives change within &lt;strong&gt;a small local segment&lt;/strong&gt; of a decreasing function. The decreasing side of a quadratic function is often used as an approximation, as in a second-order Taylor expansion or Newton’s method.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="海森矩阵"&gt;The Hessian Matrix&lt;/h2&gt;
&lt;p&gt;Like the Jacobian, the &lt;strong&gt;Hessian matrix &lt;strong&gt;contains information about the function’s second derivatives:
$$
Hessian   = \begin{bmatrix}
\frac{\partial^2y}{\partial x_1\partial x_1} &amp;amp;  \frac{\partial^2y}{\partial x_1\partial x_2}&amp;amp;\frac{\partial^2y}{\partial x_1\partial x_3} \
\frac{\partial^2y}{\partial x_2\partial x_1} &amp;amp;  \frac{\partial^2y}{\partial x_2\partial x_2}&amp;amp;\frac{\partial^2y}{\partial x_2\partial x_3} \
\frac{\partial^2y}{\partial x_3\partial x_1} &amp;amp;  \frac{\partial^2y}{\partial x_3\partial x_2}&amp;amp;\frac{\partial^2y}{\partial x_3\partial x_3}
\end{bmatrix}
$$
Because mixed second derivatives can be interchanged, namely $\frac{\partial^2y}{\partial x_1\partial x_2}=\frac{\partial^2y}{\partial x_2\partial x_1}$, &lt;/strong&gt;the Hessian is a symmetric matrix&lt;/strong&gt;. For a symmetric matrix, we can use &lt;strong&gt;eigendecomposition&lt;/strong&gt; to study the relationship between eigenvalues and second derivatives and obtain a directional second derivative efficiently.&lt;/p&gt;
&lt;p&gt;For a particular direction d, the second directional derivative can be written as $d^THd$. Therefore:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;🔗 &lt;a href="https://blog.csdn.net/weixin_42397505/article/details/112066943"&gt;Second Directional Derivatives and Properties of the Hessian Matrix — CSDN&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If d is an eigenvector of H corresponding to eigenvalue λ:&lt;/p&gt;
&lt;p&gt;Since d is an eigenvector corresponding to λ, by definition:
$$
Hd = \lambda d\
\Rightarrow  d^THd=d^T\lambda d = \lambda d^Td=\lambda    \ \ \ 对称矩阵d^T = d^-
$$&lt;/p&gt;
&lt;p&gt;The eigenvalue λ corresponding to that eigenvector is therefore the second derivative in that direction.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For another direction d, let $e_i$ be an eigenvector of $H$ with eigenvalue $\lambda_i$. From the result above,
$$
\lambda_i=e_i^THe_i
$$
Any direction $d=\sum_i^mt_ie_i$ is a linear combination of eigenvectors, where m is the number of eigenvalues and $t_i$ is the weight of the $i$th eigenvector. Thus:
$$
d^THd=(\sum_i^mt_ie_i)^TH(\sum_i^mt_ie_i)=\sum_i^mt_ie_i^THt_ie_i=\sum_i^mt_i^2\lambda_i
$$
The second derivative in an arbitrary direction that is not an eigenvector is therefore a weighted sum of all eigenvalues. In particular, this weighted sum describes an ellipsoid. With two eigenvalues, it is an ellipse, with the equation:
$$
y=\frac{\lambda_1}{\frac{1}{t_1^2}}+\frac{\lambda_2}{\frac{1}{t_2^2}}
$$
&lt;img src="https://img-blog.csdnimg.cn/img_convert/bb30779d25d486346799cb0fce7d34ad.png#pic_center" alt="Article illustration"&gt;&lt;/p&gt;
&lt;p&gt;The figure shows that the maximum second derivative is determined by the largest eigenvalue, along the major semiaxis, and the minimum by the smallest eigenvalue, along the minor semiaxis.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="海森矩阵应用"&gt;Applications of the Hessian Matrix&lt;/h2&gt;
&lt;p&gt;With the definition of the Hessian established, we can use its properties to analyze optimization methods: identifying local maxima, local minima, and saddle points; choosing learning rates; and assessing how ill-conditioning affects gradient descent. We can also use the Hessian to implement &lt;strong&gt;Newton’s method&lt;/strong&gt; as an optimization algorithm.&lt;/p&gt;
&lt;p&gt;(End of section)&lt;/p&gt;
</description>
    <category>Machine Learning</category><category>Mathematical Foundations</category></item>
  </channel>
</rss>
