## 2 Materials and Methods
### State Annotation
#### 2.5.1 Limited Max Sequential Annotation (LMSA)  
Define \(\overline{s}(t)\) as \(\overline{s}(t)=\underset{j}{argmax}B_{t,j}\), and the formulae given by [PERSON] et al. [3] are as follows,  
\[\hat{s}(0)=\overline{s}(0) \tag{4}\]  
\[\hat{s}(t)=\left\{\begin{array}{ll}\overline{s}(t),&\quad\text{  
by [PERSON] et al. [13], and obtaining the extra \(\delta_{t}(i)\) was equivalent to the assumption that \(b_{j}(O_{t})=1\) when \(N\leq t\leq N+d_{max}\) - 1 and \(t\leq 1\).  
Next, it was necessary to track back from \(q_{N}^{*}\). The previous transition state for each state was fixed, so the duration time \(d\) of the last state \(q_{N}^{*}\) was most important. When calculating the matrix \(\delta_{t}(j)\), the method proposed by [PERSON] et al. [13] also recorded the corresponding matrix \(D_{t}(j)\):  
\[D_{t}(j)=arg\underset{d}{\max}\left[\underset{i\
eq j}{\max}\left\{\delta_{t -d}(i)\cdot a_{ij}\right\}p_{j}(d)\cdot\prod_{s=0}^{d-1}b_{j}(O_{t-s})\right] \tag{11}\]  
With \(1\leq i,j\leq H\), \(1\leq t\leq N\), and \(1\leq d\leq d_{max}\). After determining the final state \(q_{N}^{*}\) of the optimal path, the duration time of the final state \(d_{N}^{*}\) was recorded, and thus \(q_{t}^{*}\) when \(t=N-d_{N}^{*}+1,\ldots,N\) were equal to \(q_{N}^{*}\). The previous state \(q_{N-d_{N}^{*}}^{*}\) could be inferred according to the fixed state transition and \(d_{N}^{*}\). These steps were repeated to obtain all of the annotations for the feature sequence. In contrast to LMSA, HSMM tracked back the whole signal and integrated all of the information rather than several previous time points, which could avoid changing the state labels when noise occurred, even if the noise appeared suddenly in the middle of a state, and thus the probability of this part being classified as the real state was very low because the time duration of each state tended to be in the high probability range for the Gaussian model, as shown in Figure 9a. However, [PERSON] et al. [15] showed that the strong anti-noise ability of the HSMM could cause labeling errors when the heart sounds contained arrhythmia, as shown in Figure 10 (TCN + Gauss 1.0). The probability value of a complete optimal path was equal to the classification probabilities at each time point multiplied by the probabilities of each continuous state duration according to the following formula:  
\[\delta_{N}^{*}\big{(}q_{N}^{*}\big{)}=\prod_{i=1}^{k}p_{q_{i}^{*}}\big{(}d_{i }^{*}\big{)}\cdot\prod_{j=1}^{N}b_{q_{j}^{*}}\big{(}O_{j}\big{)} \tag{12}\]  
where \(k\) is the total number of continuous state durations in the complete optimal path and \(q_{i,1\leq i\leq k}^{*}\) denotes the states for each duration. We determined the logarithm on both sides of Equation (12) as open-source code for LR-HSMM and obtain:  
Figure 9: Duration probabilities for four states. The S1, systole, and S2 duration probabilities follow the Gaussian distribution. (**a**) Gaussian distribution for diastolic duration. (**b**) Poisson distribution for diastolic duration. Which was convenient for computer processing. When the algorithm added an incorrect heartbeat cycle annotation because of arrhythmia, the classification probabilities \(\log\!\left(b_{q_{i}^{*}}\!\left(O_{j}\right)\right)\) became smaller but four state duration probabilities \(\log\!\left(p_{q_{i}^{*}}\!\left(d_{i}^{*}\right)\right)\) are also added instead of one low probability of diastole with an excessively long duration time. Hence, when the algorithm made an error, the increases in the values of the state duration probabilities \(\log\!\left(p_{q_{i}^{*}}\!\left(d_{i}^{*}\right)\right)\) exceeded the decreases in the values of the classification probabilities \(\log\!\left(b_{q_{j}^{*}}\!\left(O_{j}\right)\right)\), thereby resulting in the incorrect optimal path probability becoming higher than the probability of the correct path.