# An Interoperable Component-Based Architecture for Data-Driven IoT System
## 3 Component-Based IoT Architecture
### Data-driven Feedback Model Component  
The data-driven feedback model component is a Unix-like development environment for the data-driven models for smart optimization and prediction. Users can build new data-driven models, select or update existing data-driven models in this component. Considering the latency and data integrity concern for an analysis and decision-making component, we have built the component on top of the edge device, where it operates on the same device as the central control system component. It greatly reduces the latency of data transmission and the possibility of data loss in the process of data transferring between components. There are two main sub-components under this component:  
* Data-driven models: This sub-component stores all the data-driven models. The component is built as an entirely independent component to ensure the changes in the models will never affect the operations of other components. Furthermore, since both the data-driven models in this sub-component and the data from the central control system component are declared as global variables, they can be shared across different application domains or optimization models for more comprehensive optimization results. For instance, a linear regression model can be used to predict future household electricity consumption, water consumption and other applications under one unified system. Similarly, the data input of a solar irradiance sensor used for solar intensity prediction can be used by the weather prediction model or any application that makes the variable call. In short, these models can be utilized in more than one application and data can be processed by more than one data-driven models to provide higher system flexibility and interoperability.
* Data-driven model selector: This sub-component is an automated model selector and assigner for the end devices. Users can conduct performance evaluations on each algorithm, under the same, specific model or situation. Through the evaluation, users can sort out the optimum algorithm and rank the performance of different models tested under the same parameters. In addition, practitioners can also validate and test newly developed optimization or prediction models under the deployed system, which provides a realistic environment for model validation. Algorithm 1 describes the data-driven selection mechanism of the data-driven model selector. The algorithm first extracts the device ID into _deviceID_ and sensor value into _sensorValue_ from the in-feed data of each end device. After that, based on the preset data-driven model assigned to each _deviceID_, the data are processed and feedback is generated to update the operating parameter of the end device. The generated feedback is then stored in the database for reference and performance comparison other models used by the same _deviceID_ previously. If there is no model from the _modelList_ pre-assigned to the _deviceID_, the data are processed by the first model in the _modelList_ until convergence and all the generated feedback data are stored to the database. During the next iteration of optimization, the second model is used to generate feedback until convergence and this continues until all the models in the _modelList_ are used. The stored data of all the models are compared against each other to select the model with the best optimization performance for that specific _deviceID_. Lastly, the model id assigned to the _deviceID_ for future feedback generations.  
```
1:for each end device do
2: extract deviceID
3: extract sensorValue
4:for each i\(\in[0,\) length(\(modelList\))-1] do
5:if\(deviceID=modelList[i]\)then
6:\(modelList[i]\gets sensorValue\)
7: generate feedback
8:elseif\(prevModel=modelList[i]\)then
9:\(modelList[i+1]\leftarrow sensorValue\)
10: generate feedback
11:else
12:\(modelList[0]\leftarrow sensorValue\)
13: generate feedback
14:endif
15: update operating parameter of end device with feedback
16: store feedback in database
17:endfor
18:endfor
```  
**Algorithm 1** Data-Driven Model Selector