# An Automated End-to-End Side Channel Analysis Based on Probabilistic Model
## 3 Proposed Approach
### Change Point Detection  
#### 3.2.1 Posterior Distribution  
As mentioned above, the model here detects the piecewise constant part from the time series. \[y_{t}=m_{k}+\epsilon, \tag{9}\]  
where random variable \(m_{k}\sim\mathcal{N}(\mu,V)\) is a mean of time series between \(\tau_{k}\) and \(\tau_{k+1}-1\) and \(\epsilon\sim\mathcal{N}(0,\sigma^{2})\). The likelihood that \(\mathbf{y}_{1:T}\) is observed given \(r_{1:T}\),\(m_{1:K_{r}}\) and \(\theta\) is  
\[p(\mathbf{y}_{1:T}|r_{1:T},m_{1:K_{r}},\theta) =\prod_{k=1}^{K_{r}}\prod_{t=\tau_{k}}^{\tau_{k+1}-1}\mathcal{N}(y _{t};m_{k},\sigma^{2})\] \[=\left(\frac{1}{2\pi\sigma^{2}}\right)^{-\frac{n}{2}}\exp\bigg{(} -\frac{1}{2\sigma^{2}}\sum_{k=1}^{K_{r}}\sum_{t=\tau_{k}}^{\tau_{k+1}-1}(y_{t} -m_{k})^{2}\bigg{)}. \tag{10}\]  
By conjugacy of the exponential family [20], posterior distribution of \(m_{1:K_{r}}\) is also Gaussian. \(m_{k}\sim\mathcal{N}(\frac{V\Psi_{k}+\sigma^{2}\mu}{V+\sigma^{2}},\frac{V \sigma^{2}}{n_{k}(V+\sigma^{2})})\), where \(\tilde{\mathbf{y}}_{k}=\frac{\sum_{t=\tau_{k}}^{\tau_{k+1}-1}y_{t}}{\tau_{k+1 }-\tau_{k}}\) and \(n_{k}=\tau_{k+1}-\tau_{k}\). If we plug the probability of \(m_{1:K_{r}}\) into Equation (10), we get by identification,  
Figure 2: Raw and noise-added power traces preprocessing with median sampling. (**a**) Power trace; (**b**) Noise-added trace; (**c**) Median-sampled power trace; (**d**) Noise-added and median-sampled power trace. \[p(m_{1:K_{r}}|\mathbf{y}_{1:T},r_{1:T},\theta)\times p(\mathbf{y}_{1:T }|r_{1:T},\theta)\] \[=p(\mathbf{y}_{1:T},m_{1:K_{r}}|r_{1:T},\theta)\] \[=\left[\prod_{k=1}^{K_{r}}\prod_{t=t-1}^{\eta_{k+1}-1}\mathcal{N}( \mathbf{y}_{t};m_{k},\sigma^{2})\right]\times\prod_{k=1}^{K_{r}}\mathcal{N}(m_{ k};\mu,V)\] \[=\prod_{k=1}^{K_{r}}\mathcal{N}\left(m_{k};\frac{V\mathbf{y}_{k}+ \sigma^{2}\mu}{V+\sigma^{2}},\frac{V\sigma^{2}}{n_{k}(V+\sigma^{2})}\right)\] \[\times\left(\frac{1}{2\pi\sigma^{2}}\right)^{-\frac{\eta}{2}} \left(\frac{V+\sigma^{2}}{\sigma^{2}}\right)^{\frac{-K_{r}}{2}}\exp\bigg{(}- \frac{1}{2(V+\sigma^{2})}\sum_{k=1}^{K_{r}}(y_{t}-\mu)^{2}+\frac{V}{\sigma^{2} }\sum_{k=1}^{K_{r}}\sum_{t=t_{k}}^{\eta_{k+1}-1}(y_{t}-\bar{\mathbf{y}}_{k})^ {2}\bigg{)}. \tag{11}\]  
Therefore, we can get from Equation (11),  
\[p(\mathbf{y}_{1:T}|r_{1:T},\theta)=\left(\tfrac{1}{2\pi\sigma^{2}}\right)^{- \frac{\eta}{2}}\left(\tfrac{V+\sigma^{2}}{\sigma^{2}}\right)^{\frac{-K_{r}}{2 }}\exp\bigg{(}-\tfrac{1}{2(V+\sigma^{2})}\sum_{k=1}^{K_{r}}(y_{t}-\mu)^{2}+ \tfrac{V}{\sigma^{2}}\sum_{k=1}^{K_{r}}\sum_{t=t_{k}}^{\eta_{k+1}-1}(y_{t}- \bar{\mathbf{y}}_{k})^{2}\bigg{)}. \tag{12}\]  
The trivial solution for this problem is to make every point as a change point, so that the sum of errors becomes least. In order to avoid this situation we have to model the number of change points \(K_{r}\). We modelled the prior distribution to control the number of change points as Bernoulli distribution. \[p(\mathbf{y}_{1:T}|r_{1:T},m_{1:K_{r}},\theta) =\prod_{k=1}^{K_{r}}\prod_{t=\tau_{k}}^{\tau_{k+1}-1}\mathcal{N}(y _{t};m_{k},\sigma^{2})\]0  
By [PERSON] theorem we can model the posterior distribution of random variable \(r_{1:T}\) by putting Equation (11) and (13) together as follows:  
\[p(\mathbf{y}_{1:T}|r_{1:T},m_{1:K_{r}},\theta) =\prod_{k=1}^{K_{r}}\prod_{t=\tau_{k}}^{\tau_{k+1}-1}\mathcal{N}(y _{t};m_{k},\sigma^{2})\]1 \[p(\mathbf{y}_{1:T}|r_{1:T},m_{1:K_{r}},\theta) =\prod_{k=1}^{K_{r}}\prod_{t=\tau_{k}}^{\tau_{k+1}-1}\mathcal{N}(y _{t};m_{k},\sigma^{2})\]2 \[p(\mathbf{y}_{1:T}|r_{1:T},m_{1:K_{r}},\theta) =\prod_{k=1}^{K_{r}}\prod_{t=\tau_{k}}^{\tau_{k+1}-1}\mathcal{N}(y _{t};m_{k},\sigma^{2})\]3  
Joint distribution of \(r_{1:T}\) and \(\mathbf{y}_{1:T}\), \(p(r_{1:T},\mathbf{y}_{1:T}|\theta)\) is needed since the evidence of the observation \(p(\mathbf{y}_{1:T}|\theta)\) is intractable to compute.