thumbnail

ベクトル・行列の微分チートシート

ベクトル・行列の微分の公式をまとめたチートシートです。

前提

ffはスカラ値関数、小文字の太文字アルファベットはベクトル、大文字の太文字アルファベットは行列とします。

スカラによる微分

x(AB)=AxB+ABx\dfrac{\partial}{\partial{x}}(\mathbf{A}\mathbf{B})=\dfrac{\partial\mathbf{A}}{\partial{x}}\mathbf{B}+\mathbf{A}\dfrac{\partial\mathbf{B}}{\partial{x}}
x(A1)=A1AxA1\dfrac{\partial}{\partial{x}}(\mathbf{A}^{-1})=-\mathbf{A}^{-1}\dfrac{\partial\mathbf{A}}{\partial{x}}\mathbf{A}^{-1}
xlnA=tr(A1Ax)\dfrac{\partial}{\partial{x}}\ln|\mathbf{A}|=\mathrm{tr}\bigg(\mathbf{A}^{-1}\dfrac{\partial\mathbf{A}}{\partial{x}}\bigg)

ベクトルによる微分

内積の微分

x(xy)=y\dfrac{\partial}{\partial\mathbf{x}}(\mathbf{x}^\top\mathbf{y})=\mathbf{y}
x(xy)=y\dfrac{\partial}{\partial\mathbf{x}^\top}(\mathbf{x}^\top\mathbf{y})=\mathbf{y}^\top

一次形式・一次式の微分

x(Ax)=A\dfrac{\partial}{\partial\mathbf{x}}(\mathbf{A}\mathbf{x})=\mathbf{A}^\top
x(Ax)=A\dfrac{\partial}{\partial\mathbf{x}^\top}(\mathbf{A}\mathbf{x})=\mathbf{A}
x(xA)=A\dfrac{\partial}{\partial\mathbf{x}}(\mathbf{x}^\top\mathbf{A})=\mathbf{A}
x(xA)=A\dfrac{\partial}{\partial\mathbf{x}}(\mathbf{x}^\top\mathbf{A}^\top)=\mathbf{A}^\top
x(Ax+b)=A\dfrac{\partial}{\partial\mathbf{x}}(\mathbf{A}\mathbf{x}+\mathbf{b})=\mathbf{A}^\top
x(yAx)=Ay\dfrac{\partial}{\partial\mathbf{x}}(\mathbf{y}^\top\mathbf{A}\mathbf{x})=\mathbf{A}^\top\mathbf{y}
y(yAx)=Ax\dfrac{\partial}{\partial\mathbf{y}}(\mathbf{y}^\top\mathbf{A}\mathbf{x})=\mathbf{A}\mathbf{x}

二次形式・二次式の微分

x(xAx)=(A+A)x\dfrac{\partial}{\partial\mathbf{x}}(\mathbf{x}^\top\mathbf{A}\mathbf{x})=(\mathbf{A}+\mathbf{A}^\top)\mathbf{x}
x(xAx)=x(A+A)\dfrac{\partial}{\partial\mathbf{x}^\top}(\mathbf{x}^\top\mathbf{A}\mathbf{x})=\mathbf{x}^\top(\mathbf{A}+\mathbf{A}^\top)
2xx(xAx)=A+A\dfrac{\partial^2}{\partial\mathbf{x}\partial\mathbf{x}^\top}(\mathbf{x}^\top\mathbf{A}\mathbf{x})=\mathbf{A}+\mathbf{A}^\top
2xAx+b2=2A(Ax+b)\dfrac{\partial^2}{\partial\mathbf{x}}\|\mathbf{A}\mathbf{x}+\mathbf{b}\|^2=2\mathbf{A}^\top(\mathbf{A}\mathbf{x}+\mathbf{b})

行列による微分

Atr(AB)=B\dfrac{\partial}{\partial\mathbf{A}}\mathrm{tr}(\mathbf{A}\mathbf{B})=\mathbf{B}^\top
Atr(AB)=B\dfrac{\partial}{\partial\mathbf{A}}\mathrm{tr}(\mathbf{A}^\top\mathbf{B})=\mathbf{B}
Atr(A)=I\dfrac{\partial}{\partial\mathbf{A}}\mathrm{tr}(\mathbf{A})=\mathbf{I}
Atr(ABA)=A(B+B)\dfrac{\partial}{\partial\mathbf{A}}\mathrm{tr}(\mathbf{A}\mathbf{B}\mathbf{A}^\top)=\mathbf{A}(\mathbf{B}+\mathbf{B}^\top)
AlnA=(A1)\dfrac{\partial}{\partial\mathbf{A}}\ln|\mathbf{A}|=(\mathbf{A}^{-1})^\top

一般的な関数のベクトル・行列による微分

次の記事でベクトル・行列の微分の基礎を解説し、より一般的な公式もいくつか掲載しております。