# Adaptive Segmentation of Streaming Sensor Data on Edge Devices
## 4 Proposed Solution
### The Algorithm
## Appendix A Pseudo-Code of the Proposed Algorithm (Full Version)

```
Input: \(h\) - sliding window buffer size, \(\mathbf{S}_{in}\) - non-empty stream of data points Output: \(\mathbf{S}_{out}\) - stream of cubic spline segments which form a \(C^{2}\)-continuous curve /* prepare the streams */ open (\(\mathbf{S}_{in}\)); open (\(\mathbf{S}_{out}\)) /* estimate initial conditions for the first segment */ (\(s_{ic},x_{D_{0}}\)) - init_conditions (\(\mathbf{S}_{in}\)) // \(s_{ic}=(s_{0},s^{\prime}_{0},s^{\prime\prime}_{0})\); \(x_{D_{0}}\) - see Equation (15) /* initialise the buffer offset (see Equation (3)) and search interval parameter */ \(q_{0}\gets 0\); \(x_{D_{i}}\gets x_{D_{0}}\) whilenot end of \(\mathbf{S}_{in}\)do  fill (sl_buffer, \(\mathbf{S}_{in},q_{0}\), \(h\)) // fill in the sliding window buffer whilenot end ofsl_bufferdo /* compute the new search interval (i.e., \(x_{D}\) domain) */ \([x_{D_{S}},x_{D_{E}}]\leftarrow\) search_interval (sl_buffer, \(q_{0},x_{D_{i}}\)) // see Equation (15) /* divide the search interval into sub-intervals */ \(\Sigma_{I_{SE}}\leftarrow\) sub_intervals (\([x_{D_{S}},x_{D_{E}}]\)) /* find the best splinelet in the interval \([x_{D_{S}},x_{D_{E}}]\) */ foreach \(I_{SE}\) in \(\Sigma_{I_{SE}}\)do /* build a list of candidate splinelets */ \(\Sigma_{s}\leftarrow\) cand_splinelets (sl_buffer, \(q_{0}\), \(I_{SE}\), \(s_{ic}\)) /* find the best of the candidate splinelets */ (\(\phi_{I_{Best}},s_{I_{Best}}\)) \(\leftarrow\) best_of (\(\Sigma_{s}\)) /* if necessary, update the best */ if\(\phi_{I_{Best}}>\phi_{Best}\)then \(\phi_{Best}\leftarrow\phi_{I_{Best}}\) \(s_{Best}\gets s_{I_{Best}}\) \(\leftarrow\)
1  put(\(s_{Best}^{(1)},\mathbf{S}_{out}\)) // add the first segment of \(s_{Best}\) to \(\mathbf{S}_{out}\) \(s_{ic}\leftarrow\) init_conditions (\(s_{Best}^{(2)}\)) // compute new initial conditions \(q_{0}\gets q_{0}+s_{Best}^{(2)}\).\(x_{S}\) // \(s_{Best}^{(2)}\).\(x_{S}=s_{Best}\).\(x_{B}\), see Equation (6) \(x_{D_{i}}\leftarrow s_{Best}^{(3)}\).\(x_{E}\) // \(s_{Best}^{(3)}\).\(x_{E}=s_{Best}\).\(x_{D}\), see Equation (6) /* add the remaining two segments, \(s_{Best}^{(2)}\) and \(s_{Best}^{(3)}\) to \(\mathbf{S}_{out}\) */ put(\(s_{Best}^{(2)}\).\(\mathbf{S}_{out}\)) \(\leftarrow\)\((s_{Best}^{(3)}\).\(\mathbf{S}_{out}\)) /* close the streams */ close (\(\mathbf{S}_{in}\)); close (\(\mathbf{S}_{out}\))
```

**Algorithm 1**Adaptive segmentation of streaming data (_full version_). * [PERSON] et al. (2013) [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON] TimeStream: Reliable Stream Computation in the Cloud. In _EurosSys'13: Proceedings of the 8 th ACM European Conference on Computer Systems_; ACM Press: Prague, Czech Republic, 2013; pp. 1-14. [CrossRef]
* [PERSON] et al. (2015) [PERSON]; [PERSON]; [PERSON]; [PERSON] Key Technologies for Big Data Stream Computing. In _Big Data-Algorithms, Analytics, and Applications_; [PERSON], [PERSON], [PERSON], [PERSON]; Chapman and Hall/CRC: New York, NY, USA, 2015; pp. 193-214. [CrossRef]
* [PERSON] et al. (2015) [PERSON]; [PERSON]; [PERSON]; [PERSON] Automatic Sensor Data Stream Segmentation for Real-Time Activity Prediction in Smart Spaces. In _IoT-Sys'15: Proceedings of the 2015 Workshop on IoT Challenges in Mobile and Industrial Systems_; Association for Computing Machinery: New York, NY, USA, 2015; pp. 13-18. [CrossRef]
* [PERSON] et al. (2011) [PERSON]; [PERSON]; [PERSON] A Dynamic Sliding Window Approach for Activity Recognition. In _User Modeling, Adaption and Personalization_; Springer: Berlin/Heidelberg, Germany, 2011; pp. 219-230. [CrossRef]
* [PERSON] and [PERSON] (2004) [PERSON]; [PERSON]; [PERSON] Activity Recognition in the Home Using Simple and Ubiquitous Sensors. In _Pervasive Computing_; Springer: Berlin/Heidelberg, Germany, 2004; pp. 158-175. [CrossRef]
* [PERSON] and [PERSON] (2009) [PERSON]; [PERSON] Partitioning Time Series Sensor Data for Activity Recognition.