# Adaptive Segmentation of Streaming Sensor Data on Edge Devices
## 4 Proposed Solution
### The Algorithm
\tag{24}\]

where:

\[q_{k}=0.05\;k,k=0,1,\dots,\;10^{6} \tag{25}\]

\[\epsilon_{i_{k}}=\text{first }[\;e\;|\;e\;|\;e\;{\cal N}(\mu=0,\sigma=e_{i_{max} }/3),\;e<e_{i_{max}}\;] \tag{26}\]

i.e., the first \(e\), such that: \(e\sim{\cal N}(\mu,\sigma)\) and \(e<e_{i_{max}}\), and

\[[\;e_{i_{max}},e_{i_{max}},e_{i_{max}},e_{i_{max}},e_{i_{max}}\;]=[\;0.1,0.5,1. 5,3.5\;] \tag{27}\]

#### 5.1.2 Performance Descriptors

Each of the solutions, \(s\), was evaluated using the following measures:

* _Mean Absolute Error_: \[MAE(s,f)=\frac{1}{n}\sum_{k=1}^{n}\left|s(x_{k})-f(x_{k})\right|\] (28)
* _Root Mean Squared Error_: \[RMSE(s,f)=\left\{\frac{1}{n}\sum_{k=1}^{n}\left[s(x_{k})-f(x_{k})\right]^{2} \right\}^{1/2}\] (29)

Figure 3: The test streams: (**a**–**d**) \(f_{1}\)–\(f_{4}\) (for readability shown only in the interval \([0,500]\)) generated from signal \(g\) using four levels of Gaussian noise (see Equation (27)). Figure 2: Signal \(g\) (Equation (2), for readability shown only in the interval \([0,500]\)) used—after discretization and adding Gaussian noise—to generate the test streams used in the evaluation of the proposed algorithm. * _Normalized Root Squared Error_: \[\text{NMSE}(s,f)=\left\{\frac{\sum_{k=1}^{n}[s(x_{k})-f(x_{k})]^{2}}{\sum_{k=1}^{ n}[f(x_{k})]^{2}}\right\}^{1/2}\] (30)
* _Mean Absolute Error Quotient (local-to-global algorithm ratio 1)_: \[Q_{\text{MAE}}(s,s_{R})|_{f}=\frac{MAE(s,f)}{MAE(s_{R},f)}\] (31)
* _Root Mean Squared Error Quotient (local-to-global algorithm ratio 2)_: \[Q_{\text{RMSE}}(s,s_{R})|_{f}=\frac{\text{RMSE}(s,f)}{RMSE(s_{R},f)}\] (32)
* _Compression Ratio_: \[\epsilon_{i_{k}}=\text{first }[\;e\;|\;e\;|\;e\;{\cal N}(\mu=0,\sigma=e_{i_{max} }/3),\;e<e_{i_{max}}\;] \tag{26}\]0 (33) _Note:_ due to \(C^{2}\)-continuity of cubic splines we need only \(\{4+[\text{length}(\mathbf{S}_{out})-1]\}+\{\text{length}(\mathbf{S}_{out})+ 1\}=2\left[2+\text{length}(\mathbf{S}_{out})\right]\) values. * _Absolute Error (function)_: \[\epsilon_{i_{k}}=\text{first }[\;e\;|\;e\;|\;e\;{\cal N}(\mu=0,\sigma=e_{i_{max} }/3),\;e<e_{i_{max}}\;] \tag{26}\]1 (34)
* _Squared Error (function)_: \[\epsilon_{i_{k}}=\text{first }[\;e\;|\;e\;|\;e\;{\cal N}(\mu=0,\sigma=e_{i_{max} }/3),\;e<e_{i_{max}}\;] \tag{26}\]2 (35)

**Remark 4**. : _The above set covers local (AE and SQE), global (MAE, RMSE, and NRSE), and competitive (\(Q_{\text{RMSE}}\), \(Q_{\text{RMSE}}\), and CR) performance descriptors._

#### 5.1.3 Reference Algorithm and Its Limitations

Remember that an online (local, streaming) algorithm is one that can process its input piece-by-piece in a serial fashion without having the entire input available from the beginning (as is the case for offline/global algorithms). As a result, it might make \"decisions\" that later turn out not to be optimal. Consequently, a _local algorithm cannot outperform its global (optimal) counterpart_. To compare these two, a \"local-to-global algorithm ratio\" is often used. Unfortunately, this approach cannot be directly applied to the problem under consideration (i.e., adaptive segmentation of streaming data with the use of \(C^{2}\)-continuous cubic splines) because _there is no other algorithm to compare it with_. With this in mind, we can assume that the stream is finite and then use an existing cubic spline-based approximator as a (global) point of reference. An example of such an approximator is the R language smoothing spline function smooth.spline (accessed on 15 July 2021). It turns out, however, that this is still not a solution because from the automatic segmentation point of view, this reference function (algorithm) does not handle data streams longer than about 6% of the length of the test streams (as shown in Figure 4). For longer streams, we need to specify the number of smoothing spline segments (knots) manually. As shown in Figure 5, we can expect accurate approximations for all test streams when using more than \(4\times 10^{3}\) knots.