# Adaptive Segmentation of Streaming Sensor Data on Edge Devices
## 4 Proposed Solution
### Cubic Splinelet of Type \(Wssr_{min}\)--The Solution Building Block  
Without loss of generality, we can consider the problem in the following local frame:  
\[(x,y)=(q-q_{0},y) \tag{3}\]  
which means that an interval \([q_{A},q_{D}]\), given in the global frame, \(Oqy\), is shifted in \(q\)-direction by the _offset_, \(q_{0}\):  
\[[q_{A},q_{D}]\xrightarrow{\text{shift by }q_{0}}[x_{A},x_{D}]=[q_{A}-q_{0},q_{D} -q_{0}] \tag{4}\]  
In a special case, when \(q_{0}=q_{A}\), we get:  
\[[q_{A},q_{D}]\xrightarrow{\text{shift by }q_{A}}[x_{A},x_{D}]=[0,q_{D}-q_{A}] \tag{5}\]  
_Note_: this local frame, \(Oxy\), will be used in the following paragraphs.  
**Definition 1**.: _A cubic splinelet of type \(Wssr_{min}\) is a three-segment piece-wise cubic function defined in the local frame (when \(q_{0}=q_{A}\)) as ([64]):_  
\[s(x)=\left\{\begin{array}{ll}s^{(1)}(x)&0\leq x\leq x_{B}\\ s^{(2)}(x)&x_{B}\leq x\leq x_{C}\\ s^{(3)}(x)&x_{C}\leq x\leq x_{D}\end{array}\right. \tag{6}\]  
_where:_  
\[s^{(i)}(x)=\sum_{j=1}^{4}a_{j}^{(i)}x^{4-j},\ i=1,2,3 \tag{7}\]  
_and with the following properties:_  
* \(s(x)\) _is_ \(C^{2}\)_-continuous on the interval_ \(I_{s}=[0,x_{D}]\)_,_
* \(s(x)\) _has the following boundary conditions:_ \[x_{A}=0:\left\{\begin{array}{ll}s(x_{A})=s_{A}\\ s^{\prime}(x_{A})=s^{\prime}_{A}\\ s^{\prime\prime}(x_{A})=s^{\prime\prime}_{A}\end{array}\right.\] (8)* minimizes the _Weighted Sum of Squared Residuals_, i.e., \[\text{WSSR}=\sum_{i=1}^{3}\sum_{x_{k}\in I_{s}^{(i)}}w_{i}(x_{k})\left[y_{k}-s^{(i )}(x_{k})\right]^{2}\to min\] (9) where: \(I_{s}^{(1)}=[0,x_{B})\), \(I_{s}^{(2)}=[x_{B},x_{C})\) and \(I_{s}^{(3)}=[x_{C},x_{D}]\).  
To find the splinelet corresponding to Equation (9), we first note that each coefficient in Equation (7) can be expressed in the following way:  
\[a_{j}^{(i)}=A_{j1}^{(i)}s_{D}+A_{j2}^{(i)}s_{D}^{\prime}+A_{j3}^{(i)}s_{D}^{ \prime\prime}+A_{j4}^{(i)}=\sum_{l=1}^{4}A_{jl}^{(i)}\alpha_{l} \tag{10}\]  
where: \(i=1,2,3,j=1,2,3,4\), and \((\alpha_{1},\alpha_{2},\alpha_{3},\alpha_{4})=(s_{D},s_{D}^{\prime},s_{D}^{ \prime\prime},1)\). Equation (9) can be now restated as the following _parametric optimization problem_:  
\[\text{WSSR}=J(\alpha_{1},\alpha_{2},\alpha_{3})=\sum_{i=1}^{3}\sum_{x_{k}\in I _{s}^{(i)}}w_{i}(x_{k})\left[y_{k}-\sum_{j=1}^{4}\sum_{l=1}^{4}A_{jl}^{(i)} \alpha_{l}x_{k}^{4-j}\right]^{2}\to min \tag{11}\]  
or, in another notation:  
\[\underset{\alpha_{1},\alpha_{2},\alpha_{3}}{\text{arg min}}\sum_{i=1}^{3}\sum _{x_{k}\in I_{s}^{(i)}}w_{i}(x_{k})\left[y_{k}-\sum_{j=1}^{4}\sum_{l=1}^{4}A_ {jl}^{(i)}\alpha_{l}x_{k}^{4-j}\right]^{2}. \tag{12}\]  
Next, we compute:  
\[\left\{\begin{array}{l}\frac{\partial J}{\partial x_{1}}(\alpha_{1},\alpha_ {2},\alpha_{3})=0\\ \frac{\partial J}{\partial x_{2}}(\alpha_{1},\alpha_{2},\alpha_{3})=0\\ \frac{\partial J}{\partial x_{3}}(\alpha_{1},\alpha_{2},\alpha_{3})=0\\ \end{array}\right. \tag{13}\]  
which leads to a system of three linear equations (since \(J(\alpha_{1},\alpha_{2},\alpha_{3})\) is linear with respect to \(\alpha_{i}\), \(i=1,2,3\)):  
\[\sum_{j=1}^{3}B_{ij}\alpha_{j}=C_{i},\ i=1,2,3 \tag{14}\]  
whose solution (i.e., the optimal values of \(\alpha_{i}\), \(i=1,2,3\)) we substitute into Equation (10), and obtain the coefficients of the corresponding splinelet.  
**Remark 2**.: _Having set \(w_{i}(x)\), \(i=1,2,3\), and \(x_{A}\), \(x_{B}\), \(x_{C}\), \(x_{D}\), we can find the closed-form solution (compare [64]) for \(a_{j}^{(i)}\), \(i=1,2,3\), \(j=1,2,3,4\)._