【最优化】含卷积目标函数求导

本篇使用的符号说明,书接上回《含卷积矩阵优化问题的闭式解》,那么为什么会有这篇呢。

主要是求导部分不够严谨,实际上傅里叶变换后已经是复数了,求导规则不能完全参考实矩阵,因此本文尝试从另一个角度绕过对复矩阵求导可能会出现的问题。

考虑优化目标

\[\min\limits_K\|A*K-B\|_F^2,\tag{1} \]

其中\(A,B,K\)均为实矩阵,这里卷积的实现我们后文会提。为了方便推导我们假设均为方阵,实际上一般矩阵也有相同的结论。对于二维矩阵的傅里叶变换,实现方式为

\[\mathcal{F}(X)=FXF,\mathcal{F}^{-1}(X)=F^{-1}XF^{-1}=\frac{1}{n^2}F^{H}XF^{H}\tag{2}. \]

为了方便讨论,\(F\)我们考虑为归一化的傅里叶矩阵,跟原形式差一个常数倍,同时有一个矩阵拉直的引理

\[\operatorname{vec}(ABC)=(C^T\otimes A)\operatorname{vec}(B). \tag{3} \]

于是由傅里叶变换的性质,可以将\((1)\)进行变换

\[\begin{align} &\|A*K-B\|_F^2 \notag\\ =&\|\mathcal{F}^{-1}(\mathcal{F}(A)\odot\mathcal{F}(K))-B\|_F^2.\tag{4} \end{align} \]

由于\(F\)-范数本质是逐位置求2-范数,因此可以将其拉直得到

\[\begin{align} (4)&\Leftrightarrow\left\|\operatorname{vec}(\mathcal{F}^{-1}(\mathcal{F}(A)\odot\mathcal{F}(K)))-\bm{b}\right\|^2,\bm{b}=\operatorname{vec}(B) \notag \\ &=\left\|\operatorname{vec}(F^{-1}(\mathcal{F}(A)\odot\mathcal{F}(K))F^{-1})-\bm{b}\right\|^2 \notag\\ &=\left\|(F^{-1}\otimes F^{-1})\operatorname{vec}(\mathcal{F}(A)\odot\mathcal{F}(K))-\bm{b}\right\|^2 \notag\\ &=\left\|(F^{-1}\otimes F^{-1})\operatorname{vec}(\mathcal{F}(A))\odot\operatorname{vec}(\mathcal{F}(K))-\bm{b}\right\|^2 \notag\\ &=\left\|(F^{-1}\otimes F^{-1})\operatorname{diag}(\operatorname{vec}(\mathcal{F}(A)))\cdot\operatorname{vec}(\mathcal{F}(K))-\bm{b}\right\|^2 \notag\\ &=\left\|(F^{-1}\otimes F^{-1})\operatorname{diag}(\operatorname{vec}(\mathcal{F}(A)))(F\otimes F)(F^{-1}\otimes F^{-1})\operatorname{vec}(\mathcal{F}(K))-\bm{b}\right\|^2 \notag\\ &=\left\|(F^{-1}\otimes F^{-1})\operatorname{diag}(\operatorname{vec}(\mathcal{F}(A)))(F\otimes F)\operatorname{vec}(K)-\bm{b}\right\|^2. \tag{5} \end{align}\]

\(D=(F^{-1}\otimes F^{-1})\operatorname{diag}(\operatorname{vec}(\mathcal{F}(A)))(F\otimes F)\),于是有

\[\operatorname{vec}(A*K)=D\cdot\operatorname{vec}(K), \]

由于\(A,K\)为实矩阵,于是\(A*K\)为实矩阵,令\(K\)\(1\times1\)卷积核,由\(K\)的任意性可知\(D\)为实矩阵。令\(\bm{k}=\operatorname{vec}(K)\),将优化目标对\(\bm{k}\)求导得到

\[\begin{aligned} \frac{\partial}{\partial\bm{k}}\|D\bm{k}-\bm{b}\|^2&=2D^T(D\bm{k}-\bm{b}) \\ &=2D^H(D\bm{k}-\bm{b}) \\ &=2\frac1{n^2}(F^H\otimes F^H)\overline{\operatorname{diag}(\operatorname{vec}(\mathcal{F}(A)))}(F\otimes F)\left[(F^{-1}\otimes F^{-1})\operatorname{diag}(\operatorname{vec}(\mathcal{F}(A)))(F\otimes F)\bm{k}-\bm{b}\right] \\ &=2(F^{-1}\otimes F^{-1})\operatorname{diag}(\operatorname{vec}(\overline{\mathcal{F}(A)}))\left[\operatorname{diag}(\operatorname{vec}(\mathcal{F}(A)))\operatorname{vec}(\mathcal{F}(K))-\operatorname{vec}(\mathcal{F}(B)) \right] \\ &=2(F^{-1}\otimes F^{-1})\left[\operatorname{vec}\left(\overline{\mathcal{F}(A)}\odot\mathcal{F}(A)\odot\mathcal{F}(K) \right)-\operatorname{vec}\left(\overline{\mathcal{F}(A)}\odot\mathcal{F}(B) \right) \right] \\ &=2\operatorname{vec}\left[\mathcal{F}^{-1}\left[\overline{\mathcal{F}(A)}\odot\left(\mathcal{F}(A)\odot\mathcal{F}(K)-\mathcal{F}(B) \right)\right] \right]. \end{aligned} \]

于是还原成矩阵得到

\[\frac{\partial}{\partial K}\|A*K-B\|_F^2=2\mathcal{F}^{-1}\left[\overline{\mathcal{F}(A)}\odot\left(\mathcal{F}(A)\odot\mathcal{F}(K)-\mathcal{F}(B) \right)\right]. \tag{6} \]

另外,由\((5)\)可以观察到,如果矩阵卷积想满足\(\mathcal{F}(A*B)=\mathcal{F}(A)\odot\mathcal{F}(B)\)的性质,则这个卷积必须是循环padding卷积,参考下图。

然后举个例子实战下,考虑《Deep Convolutional Dictionary Learning for Image Denoising》中求解\(X\)的优化问题

\[\min\limits_{X^*}\frac12\|D*X^*-Y\|_F^2+\frac{\alpha}2\|X^*-X\|_F^2. \]

原文中的\(D,X,X^*,Y\)均为张量,这里为了方便举例只考虑为矩阵。于是将优化目标对\(X^*\)求导可以得到

\[\begin{aligned} \mathcal{F}^{-1}\left[\overline{\mathcal{F}(D)}\odot\left(\mathcal{F}(D)\odot\mathcal{F}(X^*)-\mathcal{F}(Y) \right)\right]+\alpha(X^*-X)&=0 \\ \overline{\mathcal{F}(D)}\odot\left(\mathcal{F}(D)\odot\mathcal{F}(X^*)-\mathcal{F}(Y) \right)+\alpha(\mathcal{F}(X^*)-\mathcal{F}(X))&=0 \\ \left(\overline{\mathcal{F}(D)}\odot\mathcal{F}(D)+\alpha\right)\odot\mathcal{F}(X^*)&=\overline{\mathcal{F}(D)}\odot\mathcal{F}(Y)+\alpha\mathcal{F}(X) \\ X^*&=\mathcal{F}^{-1}\left[\frac{\overline{\mathcal{F}(D)}\odot\mathcal{F}(Y)+\alpha\mathcal{F}(X)}{\overline{\mathcal{F}(D)}\odot\mathcal{F}(D)+\alpha}\right]. \end{aligned} \]

这个结果跟原文中考虑通道数为1的情况是一样的。

posted @ 2023-09-04 18:40  Edlinf  阅读(188)  评论(0编辑  收藏  举报