介绍矩阵求导法则,以及常用的求导公式、迹函数、行列式求导结论。

矩阵求导法则

矩阵求导应该分为标量求导、向量求导、矩阵求导三个方面来介绍,公式繁多,但仔细看看其实是有规律可循的。

标量求导

无论是矩阵、向量对标量求导,或者是标量对矩阵、向量求导,其结论都是一样的:等价于对矩阵(向量)的每个分量求导,并且保持维数不变。

例如,我们可以计算标量对向量求导:

yy为一个元素,xT=[x1...xq]x^T = [x_1...x_q]qq维行向量,则:

yxT=[yx1...yxq]\frac{\partial y}{\partial x^T} = [\frac{\partial y}{\partial x_1}...\frac{\partial y}{\partial x_q}]

向量求导

对于向量求导,我们可以先将向量看做一个标量,然后使用标量求导法则,最后将向量形式化为标量进行。

例如,我们可以计算行向量对列向量求导:

yT=[y1...yn]y^T=[y_1...y_n]nn维行向量,x=[x1,...,xp]x=[x_1,...,x_p]pp维列向量,则:

yTx=[y1xynx]=[y1x1ynx1y1xpynxp] \begin{aligned} \frac{\partial y^{T}}{\partial x} &=\left[\frac{\partial y_{1}}{\partial x} \cdot \cdots \frac{\partial y_{n}}{\partial x}\right] \\ &=\left[\begin{array}{lll} \frac{\partial y_{1}}{\partial x_{1}} & \cdots & \frac{\partial y_{n}}{\partial x_{1}} \\ \cdots & \cdots & \cdots \\ \frac{\partial y_{1}}{\partial x_{p}} & \cdots & \frac{\partial y_{n}}{\partial x_{p}} \end{array}\right] \end{aligned}

矩阵求导

与向量求导类似,先将矩阵化当做一个标量,再使用标量对矩阵的运算进行。

例如,我们可以计算矩阵对列向量求导:

Y=(y11y1nym1ymn) Y=\left(\begin{array}{lll} y_{11} & \ldots & y_{1 n} \\ \ldots & \ldots & \ldots \\ y_{m 1} & \ldots & y_{m n} \end{array}\right)

m×nm\times n矩阵,x=[x1,...,xp]x=[x_1,...,x_p]pp维列向量,则:

Yx=[Yx1,...,Yxp]\frac{\partial Y}{\partial x} = [\frac{\partial Y}{\partial x_1},...,\frac{\partial Y}{\partial x_p}]

矩阵微积分

常见求导性质

实值函数相对于实向量的梯度

f(x)=x=[x1,...,xn]Tf(x) = x = [x_1,...,x_n]^T

f(x)xT=xxT=In×n\frac{\partial f (x)}{\partial x^T} = \frac{\partial x}{\partial x^T} = I_{n\times n}

(f(x))Tx=xTx=In×n\frac{\partial (f (x))^T}{\partial x} = \frac{\partial x^T}{\partial x} = I_{n\times n}

f(x)x=xx=vec(In×n)\frac{\partial f (x)}{\partial x} = \frac{\partial x}{\partial x} = vec(I_{n\times n})

(f(x))TxT=xTxT=vec(In×n)T\frac{\partial (f (x))^T}{\partial x^T} = \frac{\partial x^T}{\partial x^T} = vec(I_{n\times n})^T

其中,vecvec表示向量化矩阵,按列将矩阵表示为向量,具体可见Wikipedia。

常见性质

  • f(x)=Axf(x) = Ax,则

    f(x)xT=(Ax)xT=A\frac{\partial f (x)}{\partial x^T} = \frac{\partial (Ax)}{\partial x^T} =A

  • f(x)=xTAxf(x) = x^TAx,则

    f(x)x=(xTAx)x=Ax+ATx\frac{\partial f (x)}{\partial x} = \frac{\partial (x^TAx)}{\partial x} =Ax+A^Tx

  • f(x)=aTxf(x) = a^Tx,则

    aTxx=xTax=a\frac{\partial a^Tx}{\partial x} = \frac{\partial x^Ta}{\partial x} =a

  • f(x)=xTAyf(x) = x^TAy,则

    xTAyx=Ay\frac{\partial x^TAy}{\partial x} = Ay

    xTAyA=xyT\frac{\partial x^TAy}{\partial A} = xy^T

  • df(X)=tr((f(X)X)TdX)df(X) = tr((\frac{\partial f(X)}{\partial X})^T d X)

  • 矩阵微分也满足线性法则、乘积法则。

  • 矩阵的逆的微分

    d(X1)=X1(dX)X1d(X^{-1}) = -X^{-1}(dX)X^{-1}

迹函数

迹函数相对于矩阵的梯度

(tr(ZZT))Z=(tr(ZTZ))Z=2Z\frac{\partial (tr (ZZ^T))}{\partial Z} = \frac{\partial (tr (Z^TZ))}{\partial Z} = 2Z

矩阵微分算子和迹算子的可交换性

d(tr(X))=tr(d(X))=i=1ndxiid(tr(X)) = tr(d(X)) = \sum\limits_{i=1}^{n} dx_{ii}

常见性质

  • tr(A)A=In×n\frac{\partial tr(A)}{\partial A} = I_{n\times n}

  • tr(AB)A=BT\frac{\partial tr(AB)}{\partial A} = B^T

  • d(tr(AXB))=tr(A(dX)B)=tr(BA(dX))d(tr(AXB)) = tr(A(dX)B) = tr(BA(dX))

    tr(AXB)X=(BA)T=ATBT\frac{\partial tr(AXB)}{\partial X} = (BA)^T = A^TB^T

  • d(tr(AX1B))=tr(A(dX1)B)=tr(AX1(dX)X1B)=tr(X1BAX1dX)d(tr(AX^{-1}B)) = tr(A(dX^{-1})B) = -tr(AX^{-1}(dX)X^{-1}B) = -tr(X^{-1}BAX^{-1}dX)

    tr(AX1B)X=(X1BAX1)T=XTATBTXT\frac{\partial tr(AX^{-1}B)}{\partial X} = -(X^{-1}BAX^{-1})^T = -X^{-T}A^TB^TX^{-T}

  • tr(XTX)X=2X\frac{\partial tr(X^TX)}{\partial X} = 2X

行列式

行列式相对于矩阵的梯度

ZZ=Z(Z1)T\frac{\partial |Z|}{\partial Z} = |Z|(Z^{-1})^T

微分形式

dX=tr(XX1dX)d|X| = tr(|X| X^{-1} dX)

常见性质

dAXB=tr(AXB(AXB)1d(AXB))=tr(AXB(AXB)1A(dX)B)=tr(AXBB(AXB)1A(dX)) \begin{aligned} d|A X B| &=\operatorname{tr}\left(|A X B|(A X B)^{-1} d(A X B)\right) \\ &=\operatorname{tr}\left(|A X B|(A X B)^{-1} A(d X) B\right) \\ &=\operatorname{tr}\left(|A X B| B(A X B)^{-1} A(d X)\right) \end{aligned}

AXBX=AXBAT(BTXTAT)1BT \frac{\partial|A X B|}{\partial X}=|A X B| A^{T}\left(B^{T} X^{T} A^{T}\right)^{-1} B^{T}

XX=XXT \frac{\partial|X|}{\partial X}=|X| X^{-T}

XXTX=2XXT(XXT)1X \frac{\partial |XX^T|}{\partial X} = 2|XX^T| (XX^{T})^{-1}X

reference

  1. 矩阵的导数与迹

results matching ""

    No results matching ""