# On Evaluating IoT Data Trust via Machine Learning
## 3 Synthesis of Trust-Labeled Data
### Random Walk Infilling  
The proposed RWI algorithm synthesizes untrustworthy data that share similarities with the given trustworthy data but purposely deviate from them to an extent that renders them untrustworthy. We devise the algorithm such that it respects the time-series nature of the data despite utilizing random processes for data synthesis. Despite the intentional deviations, the synthesized untrustworthy data are designed to appear realistic, resembling the main characteristics and patterns present in the trustworthy data. Thus, RWI avoids synthesizing unrealistic data that, for example, may contain discontinuities, excessively abrupt changes, or dramatic drifts in the values over long sequences. We implement the RWI algorithm through the following three main steps. * For the data of any sensor collected during given intervals, such as every day (24 h), we extract the indexes (timestamps) of the first and last values and find a predetermined number of (e.g., ten) equally spaced indexes between the first and last indexes. * We replace the sensor data values in each segment, defined between every pair of adjacent indexes, with synthetic values generated through a random walk process with a predetermined step variance. * We adjust the synthesized values within each segment to approximately align the start and end values of the segments with the preceding and succeeding segments. We achieve the alignment by pivoting the synthesized values around the first value of each segment. In this way, we preserve the long- and mid-term trends present in the original data and avoid introducing abrupt changes or discontinuities in the synthesized data, maintaining the overall continuity and coherence with the original data. The resultant synthesized data have the same number of values as the original data, roughly capturing the non-short-term cyclic behaviors or trends in the original data without featuring any improbable discontinuities, sudden changes, or undue trend shifts. We summarize the main computational steps of the proposed RWI algorithm in Algorithm 1. Moreover, in Figure 2, we plot the values of a 24-h long time-series data instance, labeled as trustworthy, and its corresponding synthetic counterpart created via RWI and labeled as untrustworthy. Figure 2: An example actual trustworthy data instance (time-series data collected by a sensor in a 24-h period) and a corresponding untrustworthy data instance synthesized via RWI. ```
input dataset containing instances corresponding to the time-series data of each sensor and given interval (e.g., 24 h); random-walk step variance \(\sigma_{S}^{2}\); number of middle points \(M\) output synthesized dataset \(\mathcal{A}\)  initialize \(\mathcal{A}\leftarrow\emptyset\) for every instance in the input dataset do  find the indexes of the first and last values and \(M\) mid ones: \(\mathcal{P}=\{p_{0},\ldots,p_{M+1}\}\) for every segment \(i=0,\ldots,M\)do  find the segment values indexed between \(p_{i}\) and \(p_{i+1}\): \(\mathcal{S}\leftarrow\{s_{p_{i}},\ldots,s_{p_{i+1}}\}\)  calculate the segment slope (inclination): \(b=\frac{\sum_{j=p_{i}+1}^{p_{i+1}}(j-p_{i})(s_{j}-s_{p_{j}})}{\sum_{j=p_{i}+1 }^{p_{i+1}}(j-p_{i})^{2}}\)  replace the values with synthetic ones via random walk: for\(j=p_{i}+1,\ldots,p_{i+1}\)do \(s_{j}\gets s_{j-1}+s_{j},s_{j}\sim\mathcal{N}(0,\,\sigma_{S}^{2})\) endfor  calculate the slope difference: \(b\gets b-\frac{\sum_{j=p_{i}+1}^{p_{i+1}}(j-p_{i})(s_{j}-s_{p_{j}})}{\sum_{ j=p_{i}+1}^{p_{i+1}}(j-p_{i})^{2}}\)  pivot the synthesized values to restore the original slope: for\(j=p_{i}+1,\ldots,p_{i+1}\)do \(s_{j}\gets s_{j}+b(j-p_{i})\) endfor  update the synthesized dataset: \(\mathcal{A}\leftarrow\mathcal{A}\cup\mathcal{S}\) endfor endfor
```  
**Algorithm 1** Random walk infilling. The main advantages of RWI lie in its capability to generate data that closely follow the major temporal behaviors of the original data, with subtle variations that may not be immediately discernible.