# Topic Detection Based on Sentence Embeddings and Agglomerative Clustering with Markov Moment
## Methods
### Approximation-Estimation Test
For this, we find the local minimum of the function of two variables  
\[f_{l}(a,b)=\sum_{i=0}^{k-1}(a\cdot i+b-y_{i})^{2}. \tag{3}\]  
We calculate the partial derivatives of the function \(f_{l}(a,b)\) :  
\[\frac{\partial f_{l}}{\partial a}=2a\sum_{i=0}^{k-1}i^{2}+2b\sum_ {i=0}^{k-1}i-2\sum_{i=0}^{k-1}i\cdot y_{i}\;; \tag{4}\] \[\frac{\partial f_{l}}{\partial b}=2a\sum_{i=0}^{k-1}i+2b\sum_{i= 0}^{k-1}1-2\sum_{i=0}^{k-1}y_{i}\;. \tag{5}\]  
By equating them to zero, we obtain a system of linear equations for the unknown \(a\) and \(b\):  
\[ \begin{cases}\frac{k(k-1)(2k-1)}{6}\cdot a+\frac{k(k-1)}{2}\cdot b=\sum_{i=1} ^{k-1}i\cdot y_{i}\\ \frac{k(k-1)}{2}\cdot a+k\cdot b=\sum_{i=1}^{k-1}y_{i}\;,\end{cases}  \tag{6}\]  
which implies:  
\[a=\frac{6}{k(k^{2}-1)}\sum_{i=1}^{k-1}(2i+1-k)y_{i}\qquad b=\frac{2}{k(k+1)} \sum_{i=1}^{k-1}(2k-1-3i)y_{i}. \tag{7}\]  
We calculate the coefficients \(c,d\) of the incomplete quadratic function \(cx^{2}+d\) as the coordinates of the local minimum for:  
\[f_{q}(c,d)=\sum_{i=0}^{k-1}(c\cdot i^{2}+d-y_{i})^{2}. \tag{8}\]  
Differentiating \(f_{q}(c,d)\), we find:  
\[\frac{\partial f_{q}}{\partial c}=2c\sum_{i=0}^{k-1}i^{4}+2d\sum _{i=0}^{k-1}i^{2}-2\sum_{i=0}^{k-1}i^{2}\cdot y_{i}, \tag{9}\] \[\frac{\partial f_{q}}{\partial d}=2c\sum_{i=0}^{k-1}i^{2}+2d\sum _{i=0}^{k-1}1-2\sum_{i=0}^{k-1}y_{i}, \tag{10}\]and  
\[\left\{ \begin{aligned} &\frac{k(k-1)(2k-1)(3k^{2}-3k-1)}{30}\cdot c +\frac{k(k-1)(2k-1)}{6}\cdot d=\sum_{i=1}^{k-1}i^{2}\cdot y_{i}\\ &\frac{k(k-1)(2k-1)}{6}\cdot c+k\cdot d=\sum_{i=1}^{k-1}y_{i}, \end{aligned} \right. \tag{11}\]  
We find that:  
\[c=\frac{30}{k(k-1)(2k-1)(8k^{2}-3k-11)}\sum_{i=1}^{k-1}(6i^{2}-(k-1)(2k-1))y_{i}; \tag{12}\]  
\[d=\frac{6}{k(8k^{2}-3k-11)}\sum_{i=1}^{k-1}(3k(k-1)-1-5i^{2})y_{i}. \tag{13}\]  
Subsequently, to determine the moment when the character of the increase in the monotonic sequence \(y_{n}\) changes from linear to parabolic, we construct the parabolic approximation-estimation test \(\delta_{gl}^{2}\). By definition, we assume that, for approximation nodes: \(y_{0},y_{1},\ldots,y_{k-1}\) the parabolic approximation-estimation test [23, 24] is expressed by the formula:  
\[\delta^{2}=\delta_{ql}^{2}(k)=\delta_{l}^{2}(k)-\delta_{q}^{2}(k). \tag{14}\]  
Moreover, we assume that always \(y_{0}=0\). It is easy to achieve this condition at any approximation step while using the transformation:  
\[y_{0}=y_{j}-y_{j},\quad y_{1}=y_{j+1}-y_{j},\,\ldots,\,y_{k-1}=y_{j+k-1}-y_{j}. \tag{15}\]  
Now, we calculate, using the values of the coefficients \(a,b,c,d\), the quadratic errors of the linear and incomplete parabolic approximations at four points \(y_{0}\), \(y_{1}\), \(y_{2}\), \(y_{3}\), and we obtain an explicit expression for \(\delta^{2}\)[23, 24]. \[\delta^{2}(4)=\delta_{ql}^{2}(k)=\delta_{l}^{2}(4)-\delta_{q}^{2}(4)=\frac{1} {245}(19y_{1}^{2}-11y_{2}^{2}+41y_{3}^{2}+12y_{1}y_{2}-64y_{1}y_{3}-46y_{2}y_{ 3}). \tag{16}\]  
Thus, we have derived a quadratic form equal to the difference of the quadratic errors of linear and incomplete parabolic approximation. This quadratic form changes its sign when the character of an increase in the numerical sequence changes from linear to parabolic.