# Discriminating Pattern Mining for Diagnosing Reading Disorders +
## 3 Technique
### Phase 1: Discriminating Prototype Search
#### 3.2.2 Computational Issues
Recall on Trace Derivative Computation  
Preliminarily, recall that, given matrices \(\mathbf{X}\), \(\mathbf{Y}\), \(\mathbf{H}\) and \(\mathbf{T}\), it holds that:  
\[\frac{\partial tr[\mathbf{X}\mathbf{H}\mathbf{Y}]}{\partial\mathbf{H}}= \mathbf{X}^{T}\mathbf{Y}^{T},\quad\frac{\partial tr[\mathbf{X}\mathbf{H}^{T} \mathbf{Y}]}{\partial\mathbf{H}}=\mathbf{Y}\mathbf{X},\]  
where \(tr(\cdot)\) denotes the trace, and that  
\[\|\mathbf{X}-\mathbf{Y}\mathbf{H}\|_{F}^{2}= tr\Big{[}(\mathbf{X}-\mathbf{Y}\mathbf{H})(\mathbf{X}-\mathbf{Y} \mathbf{H})^{T}\Big{]}=tr\Big{[}\mathbf{X}\mathbf{X}^{T}\Big{]}-tr\Big{[} \mathbf{X}\mathbf{H}^{T}\mathbf{Y}^{T}\Big{]}-tr\Big{[}\mathbf{Y}\mathbf{H} \mathbf{X}^{T}\Big{]}+tr\Big{[}\mathbf{Y}\mathbf{H}\mathbf{H}^{T}\mathbf{Y}^{ T}\Big{]}.\]Thus  
\[\frac{\partial\|\mathbf{X}-\mathbf{Y}\mathbf{H}\|_{F}^{2}}{ \partial\mathbf{Y}}= \frac{\partial tr\big{[}\mathbf{X}\mathbf{X}^{T}\big{]}}{\partial \mathbf{Y}}-\frac{\partial tr\big{[}\mathbf{X}\mathbf{H}^{T}\mathbf{Y}^{T} \big{]}}{\partial\mathbf{Y}}-\frac{\partial tr\big{[}\mathbf{Y}\mathbf{H} \mathbf{X}^{T}\big{]}}{\partial\mathbf{Y}}+\frac{\partial tr\big{[}\mathbf{Y }\mathbf{H}\mathbf{H}^{T}\mathbf{Y}^{T}\big{]}}{\partial\mathbf{Y}}\] \[= 0-\mathbf{X}\mathbf{H}^{T}-\mathbf{X}\mathbf{H}^{T}+\frac{ \partial\mathbf{Y}\mathbf{A}}{\partial\mathbf{Y}}+\frac{\partial\mathbf{B} \mathbf{Y}^{T}}{\partial\mathbf{Y}}\]  
with \(\mathbf{A}=\mathbf{H}\mathbf{H}^{T}\mathbf{Y}^{T}\) and \(\mathbf{B}=\mathbf{Y}\mathbf{H}\mathbf{H}^{T}\), consequently  
Analogously  
\[\frac{\partial\|\mathbf{X}-\mathbf{Y}\mathbf{H}\|_{F}^{2}}{ \partial\mathbf{H}}= \frac{\partial tr\big{[}\mathbf{X}\mathbf{X}^{T}\big{]}}{ \partial\mathbf{H}}-\frac{\partial tr\big{[}\mathbf{X}\mathbf{H}^{T}\mathbf{Y }^{T}\big{]}}{\partial\mathbf{H}}-\frac{\partial tr\big{[}\mathbf{Y}\mathbf{ H}\mathbf{X}^{T}\big{]}}{\partial\mathbf{H}}+\frac{\partial tr\big{[} \mathbf{Y}\mathbf{H}\mathbf{H}^{T}\mathbf{Y}^{T}\big{]}}{\partial\mathbf{H}}\] \[= 0-\mathbf{Y}^{T}\mathbf{X}-\mathbf{Y}^{T}\mathbf{X}+\frac{ \partial\mathbf{Y}\mathbf{H}\mathbf{A}}{\partial\mathbf{H}}+\frac{\partial \mathbf{B}\mathbf{H}^{T}\mathbf{Y}^{T}}{\partial\mathbf{H}}\]  
with \(\mathbf{A}=\mathbf{H}^{T}\mathbf{Y}^{T}\) and \(\mathbf{B}=\mathbf{Y}\mathbf{H}\), consequently  
\[\frac{\partial\|\mathbf{X}-\mathbf{Y}\mathbf{H}\|_{F}^{2}}{ \partial\mathbf{H}}= -2\mathbf{Y}^{T}\mathbf{X}+\mathbf{Y}^{T}\mathbf{A}^{T}+ \mathbf{Y}^{T}\mathbf{B}=-2\mathbf{Y}^{T}\mathbf{X}+\mathbf{Y}^{T}\mathbf{Y }\mathbf{H}+\mathbf{Y}^{T}\mathbf{Y}\mathbf{H}\] \[= -2\mathbf{Y}^{T}\mathbf{X}+2\mathbf{Y}^{T}\mathbf{Y}\mathbf{H}=-2 \mathbf{Y}^{T}(\mathbf{X}-\mathbf{Y}\mathbf{H}).\]  
Finally  
\[\frac{\partial\|\mathbf{Y}\mathbf{X}\mathbf{H}-\mathbf{T}\|_{F}^{ 2}}{\partial\mathbf{X}}= \frac{\partial tr\big{[}\mathbf{Y}\mathbf{X}\mathbf{H}(\mathbf{Y }\mathbf{X}\mathbf{H})^{T}\big{]}}{\partial\mathbf{X}}-\frac{\partial tr \big{[}\mathbf{Y}\mathbf{X}\mathbf{H}\mathbf{T}^{T}\big{]}}{\partial\mathbf{X }}-\frac{\partial tr\big{[}\mathbf{T}(\mathbf{Y}\mathbf{X}\mathbf{H})^{T} \big{]}}{\partial\mathbf{X}}+\frac{\partial tr\big{[}\mathbf{T}\mathbf{T}^{T} \big{]}}{\partial\mathbf{X}}\] \[= \frac{\partial tr\big{[}\mathbf{Y}\mathbf{X}\mathbf{H}^{T}\mathbf{ X}^{T}\mathbf{Y}^{T}\big{]}}{\partial\mathbf{X}}-\frac{\partial tr\big{[} \mathbf{Y}\mathbf{X}\mathbf{H}\mathbf{T}^{T}\big{]}}{\partial\mathbf{X}}- \frac{\partial tr\big{[}\mathbf{T}\mathbf{H}^{T}\mathbf{X}^{T}\mathbf{Y}^{T} \big{]}}{\partial\mathbf{X}}+0\] \[\|\mathbf{X}-\mathbf{Y}\mathbf{H}\|_{F}^{2}= tr\Big{[}(\mathbf{X}-\mathbf{Y}\mathbf{H})(\mathbf{X}-\mathbf{Y} \mathbf{H})^{T}\Big{]}=tr\Big{[}\mathbf{X}\mathbf{X}^{T}\Big{]}-tr\Big{[} \mathbf{X}\mathbf{H}^{T}\mathbf{Y}^{T}\Big{]}-tr\Big{[}\mathbf{Y}\mathbf{H} \mathbf{X}^{T}\Big{]}+tr\Big{[}\mathbf{Y}\mathbf{H}\mathbf{H}^{T}\mathbf{Y}^{ T}\Big{]}.\]0  
with \(\mathbf{A}=\mathbf{H}\mathbf{H}^{T}\mathbf{X}^{T}\mathbf{Y}^{T}\) and \(\mathbf{B}=\mathbf{Y}\mathbf{X}\mathbf{H}\mathbf{H}^{T}\), consequently  
\[\|\mathbf{X}-\mathbf{Y}\mathbf{H}\|_{F}^{2}= tr\Big{[}(\mathbf{X}-\mathbf{Y}\mathbf{H})(\mathbf{X}-\mathbf{Y} \mathbf{H})^{T}\Big{]}=tr\Big{[}\mathbf{X}\mathbf{X}^{T}\Big{]}-tr\Big{[} \mathbf{X}\mathbf{H}^{T}\mathbf{Y}^{T}\Big{]}-tr\Big{[}\mathbf{Y}\mathbf{H} \mathbf{X}^{T}\Big{]}+tr\Big{[}\mathbf{Y}\mathbf{H}\mathbf{H}^{T}\mathbf{Y}^{ T}\Big{]}.\]1 \[\|\mathbf{X}-\mathbf{Y}\mathbf{H}\|_{F}^{2}= tr\Big{[}(\mathbf{X}-\mathbf{Y}\mathbf{H})(\mathbf{X}-\mathbf{Y} \mathbf{H})^{T}\Big{]}=tr\Big{[}\mathbf{X}\mathbf{X}^{T}\Big{]}-tr\Big{[} \mathbf{X}\mathbf{H}^{T}\mathbf{Y}^{T}\Big{]}-tr\Big{[}\mathbf{Y}\mathbf{H} \mathbf{X}^{T}\Big{]}+tr\Big{[}\mathbf{Y}\mathbf{H}\mathbf{H}^{T}\mathbf{Y}^{ T}\Big{]}.\]2  
As for the computation of \(\Theta_{\epsilon}\), the gradient of \(\phi_{\text{s}}\) has to be computed relatively to \(\Theta_{\epsilon}\) and, then, since both \(\frac{1}{2n_{r}}\|\mathbf{D}\mathbf{S}_{r}^{s}-\Theta_{r}\cdot\mathcal{P}_{ \epsilon}^{s}\|_{F}^{2}\) and \(\gamma(\mathcal{P}_{\epsilon}^{s},\mathcal{P}_{\epsilon}^{s})\) do not depend on \(\Theta_{\epsilon}\), it follows that  
\[\|\mathbf{X}-\mathbf{Y}\mathbf{H}\|_{F}^{2}= tr\Big{[}(\mathbf{X}-\mathbf{Y}\mathbf{H})(\mathbf{X}-\mathbf{Y} \mathbf{H})^{T}\Big{]}=tr\Big{[}\mathbf{X}\mathbf{X}^{T}\Big{]}-tr\Big{[} \mathbf{X}\mathbf{H}^{T}\mathbf{Y}^{T}\Big{]}-tr\Big{[}\mathbf{Y}\mathbf{H} \mathbf{X}^{T}\Big{]}+tr\Big{[}\mathbf{Y}\mathbf{H}\mathbf{H}^{T}\mathbf{Y}^{ T}\Big{]}.\]3 \[\|\mathbf{X}-\mathbf{Y}\mathbf{H}\|_{F}^{2}= tr\Big{[}(\mathbf{X}-\mathbf{Y}\mathbf{H})(\mathbf{X}-\mathbf{Y} \mathbf{H})^{T}\Big{]}=tr\Big{[}\mathbf{X}\mathbf{X}^{T}\Big{]}-tr\Big{[} \mathbf{X}\mathbf{H}^{T}\mathbf{Y}^{T}\Big{]}-tr\Big{[}\mathbf{Y}\mathbf{H} \mathbf{X}^{T}\Big{]}+tr\Big{[}\mathbf{Y}\mathbf{H}\mathbf{H}^{T}\mathbf{Y}^{ T}\Big{]}.\]4Conversely, as for the computation of \(\mathcal{P}_{\varepsilon}^{s}\), the gradient of \(\phi_{s}\) has to be computed relatively to \(\mathcal{P}_{\varepsilon}^{s}\) and, then, since \(\frac{1}{2n_{t}}\|\mathbf{D}\mathbf{S}_{r}^{s}-\Theta_{r}\cdot\mathcal{P}_{ \varepsilon}^{s}\|_{F}^{2}\) does not depend on \(\mathcal{P}_{\varepsilon}^{s}\), it follows that  
\[\|\mathbf{X}-\mathbf{Y}\mathbf{H}\|_{F}^{2}= tr\Big{[}(\mathbf{X}-\mathbf{Y}\mathbf{H})(\mathbf{X}-\mathbf{Y} \mathbf{H})^{T}\Big{]}=tr\Big{[}\mathbf{X}\mathbf{X}^{T}\Big{]}-tr\Big{[} \mathbf{X}\mathbf{H}^{T}\mathbf{Y}^{T}\Big{]}-tr\Big{[}\mathbf{Y}\mathbf{H} \mathbf{X}^{T}\Big{]}+tr\Big{[}\mathbf{Y}\mathbf{H}\mathbf{H}^{T}\mathbf{Y}^{ T}\Big{]}.\]5  
By separately considering the two elements of the sum, we obtain  
\[\|\mathbf{X}-\mathbf{Y}\mathbf{H}\|_{F}^{2}= tr\Big{[}(\mathbf{X}-\mathbf{Y}\mathbf{H})(\mathbf{X}-\mathbf{Y} \mathbf{H})^{T}\Big{]}=tr\Big{[}\mathbf{X}\mathbf{X}^{T}\Big{]}-tr\Big{[} \mathbf{X}\mathbf{H}^{T}\mathbf{Y}^{T}\Big{]}-tr\Big{[}\mathbf{Y}\mathbf{H} \mathbf{X}^{T}\Big{]}+tr\Big{[}\mathbf{Y}\mathbf{H}\mathbf{H}^{T}\mathbf{Y}^{ T}\Big{]}.\]6  
and  
\[\|\mathbf{X}-\mathbf{Y}\mathbf{H}\|_{F}^{2}= tr\Big{[}(\mathbf{X}-\mathbf{Y}\mathbf{H})(\mathbf{X}-\mathbf{Y} \mathbf{H})^{T}\Big{]}=tr\Big{[}\mathbf{X}\mathbf{X}^{T}\Big{]}-tr\Big{[} \mathbf{X}\mathbf{H}^{T}\mathbf{Y}^{T}\Big{]}-tr\Big{[}\mathbf{Y}\mathbf{H} \mathbf{X}^{T}\Big{]}+tr\Big{[}\mathbf{Y}\mathbf{H}\mathbf{H}^{T}\mathbf{Y}^{ T}\Big{]}.\]7 \[\|\mathbf{X}-\mathbf{Y}\mathbf{H}\|_{F}^{2}= tr\Big{[}(\mathbf{X}-\mathbf{Y}\mathbf{H})(\mathbf{X}-\mathbf{Y} \mathbf{H})^{T}\Big{]}=tr\Big{[}\mathbf{X}\mathbf{X}^{T}\Big{]}-tr\Big{[} \mathbf{X}\mathbf{H}^{T}\mathbf{Y}^{T}\Big{]}-tr\Big{[}\mathbf{Y}\mathbf{H} \mathbf{X}^{T}\Big{]}+tr\Big{[}\mathbf{Y}\mathbf{H}\mathbf{H}^{T}\mathbf{Y}^{ T}\Big{]}.\]8  
thus  
\[\|\mathbf{X}-\mathbf{Y}\mathbf{H}\|_{F}^{2}= tr\Big{[}(\mathbf{X}-\mathbf{Y}\mathbf{H})(\mathbf{X}-\mathbf{Y} \mathbf{H})^{T}\Big{]}=tr\Big{[}\mathbf{X}\mathbf{X}^{T}\Big{]}-tr\Big{[} \mathbf{X}\mathbf{H}^{T}\mathbf{Y}^{T}\Big{]}-tr\Big{[}\mathbf{Y}\mathbf{H} \mathbf{X}^{T}\Big{]}+tr\Big{[}\mathbf{Y}\mathbf{H}\mathbf{H}^{T}\mathbf{Y}^{ T}\Big{]}.\]9