DEGREE PROJECT IN COMPUTER SCIENCE AND ENGINEERING, SECOND CYCLE, 30 CREDITS STOCKHOLM, SWEDEN 2020

Flood Prediction System Using IoT and Artificial Neural Networks with Edge Computing

Eric Samikwa

KTH ROYAL INSTITUTE OF TECHNOLOGY ELECTRICAL ENGINEERING AND COMPUTER SCIENCE Prediction System Using IoT and Artificial Neural Networks with Edge Computing

Eric Samikwa

2020-06-18

Master’s Thesis

Place for Project: RISE Research Institutes of Sweden Examiner: Magnus Boman Supervisors at RISE: Thiemo Voigt and Joakim Eriksson Supervisor at KTH: Ying Liu

ii Abstract

Flood disasters affect millions of people across the world by causing severe loss of life and colossal damage to property. Internet of things (IoT) has been applied in areas such as flood prediction, flood monitoring, flood detection, etc. Although IoT technologies cannot stop the occurrence of flood disasters, they are exceptionally valuable apparatus for conveyance of catastrophe readiness and counteractive action data. Advances have been made in flood prediction using artificial neural networks (ANN). Despite the various advancements in flood prediction systems through the use of ANN, there has been less focus on the utilisation of edge computing for improved efficiency and reliability of such systems. Inthis thesis, a system for short-term flood prediction that uses IoT and ANN, where the prediction computation is carried out on a low power edge device is proposed. The system monitors real-time rainfall and water level sensor data and predicts ahead of time flood water levels using long short-term memory. The system can be deployed on battery power as it uses low power IoT devices and communication technology. The results of evaluating a prototype of the system indicate a good performance in terms of flood prediction accuracy and response time. The application of ANN with edge computing will help improve the efficiency of real-time flood early warning systems by bringing the prediction computation close to where data is collected.

Keywords Internet of things; Flood prediction; Artificial neural network; Edge computing; Long short-term memory.

iii Abstract

Översvämningar drabbar miljontals människor över hela världen genom att orsaka dödsfall och förstöra egendom. Sakernas Internet (IoT) har använts i områden som översvämnings förutsägelse, översvämnings övervakning, översvämning upptäckt, etc. Även om IoT-teknologier inte kan stoppa förekomsten av översvämningar, så är de mycket användbara när det kommer till transport av katastrofberedskap och motverkande handlingsdata. Utveckling har skett när det kommer till att förutspå översvämningar med hjälp av artificiella neuronnät (ANN). Trots de olika framstegen inom system för att förutspå översvämningar genom ANN, så har det varit mindre fokus på användningen av edge computing vilket skulle kunna förbättra effektivitet och tillförlitlighet. I detta examensarbete föreslås ett system för kortsiktig översvämningsförutsägelse genom IoT och ANN, där gissningsberäkningen utförs över en låg effekt edge enhet. Systemet övervakar sensordata från regn och vattennivå i realtid och förutspår översvämningsvattennivåer i förtid genom att använda långt korttidsminne. Systemet kan köras på batteri eftersom det använder låg effekt IoT-enheter och kommunikationsteknik. Resultaten från en utvärdering av en prototyp av systemet indikerar en bra prestanda när det kommer till noggrannhet att förutspå översvämningar och responstid. Användningen av ANN med edge computing kommer att förbättra effektiviteten av tidiga varningssystem för översvämningar i realtid genom att ta gissningsberäkningen närmare till där datan samlas.

Nyckelord Sakernas Internet; Översvämning av översvämningar; Artificiella neuronnät; Kant datoranvändning; Långt kortvarigt minne

iv Acknowledgements

I would like to express my gratitude to the supervisors Thiemo Voigt and Joakim Eriksson at Research Institutes of Sweden for their guidance and support during my thesis work. I would like to thank my thesis examiner Magnus Boman and thesis supervisor Ying Liu at KTH for their invaluable help during the finalization of my thesis. Finally, I would like to extend my appreciation to Swedish Institute for granting me scholarship to study in Sweden.

v Acronyms and Abbreviations

IoT Internet of Things BLE Bluetooth Low Energy WSN Wireless Sensor networks RNN Recurrent Neural Network LSTM Long Short Term Memory ANN Artificial Neural Network RMSE Root Mean Squared Error NARX Nonlinear Autoregressive network with EXogenous inputs R the correlation coefficient MAE Mean Absolute Error ReLU Rectified Linear Unit MSE Mean Squared Error Adam Adaptive moment estimation FFNN Feed Forward Neural Network SGD Stochastic Gradient Descent

vi Contents

1 Introduction 1 1.1 Problem Statement ...... 2 1.2 Objectives ...... 3 1.3 Scope and Limitations ...... 3 1.4 Research Methodology ...... 4 1.5 Structure of the Report ...... 4

2 Background 5 2.1 Internet of Things ...... 5 2.2 Edge Computing ...... 6 2.2.1 Edge Computing Platforms ...... 7 2.3 Recurrent Neural Networks ...... 8 2.4 Flood Forecasting Using ANN ...... 11 2.5 Related Work ...... 12

3 Design and Implementation 15 3.1 Proposed System ...... 15 3.2 IoT Framework ...... 16 3.2.1 IoT Wireless Technologies Alternatives ...... 17 3.3 ANN Analysis ...... 19 3.3.1 Dataset Description ...... 19 3.3.2 Data Preparation ...... 20 3.3.3 Short-Term Flood Prediction Using LSTM ..... 21 3.3.4 Alternative Methods for Flood Prediction ...... 24 3.4 System Flow ...... 25 3.5 System Setup ...... 26 3.5.1 TensorFlow Lite ...... 26 3.5.2 Raspberry Pi 3B+ ...... 27 3.5.3 Arduino Nano 33 BLE ...... 28

vii CONTENTS

3.5.4 Sensors ...... 28

4 Evaluation 30 4.1 Forecast Accuracy ...... 30 4.2 Performance of the Prototype ...... 36 4.2.1 Response Time ...... 36 4.3 Comparison of Alternative Design Approaches ...... 37 4.3.1 Model Size Reduction by Tensorflow Lite ...... 38 4.3.2 Performance Comparison of ReLU, Sigmoid and Tanh Activation Functions ...... 38 4.3.3 Performance Comparison of Adam and SGD Optimizers 39

5 Conclusions and Future Work 40 5.1 Conclusions ...... 40 5.2 Future Work ...... 41

References 42

Appendix 48

A Prototype Demo 48 A.1 Sensor Data Visualisation ...... 48 A.2 in the Form of ThingTweet ...... 49

viii Chapter 1

Introduction

Floods are among the most common damaging natural disasters that affect millions of people across the world leading to severe loss oflifeand colossal damage to property, infrastructure and agriculture. According to the World Meteorological Organization, flooding remains the third biggest disaster in the world [1]. Due to climate change, scientists estimate a 4-inch sea level rise by 2030, which could potentially cause severe flooding in many parts of the world[2]. Based on a research conducted by Institute of Environmental Studies, more that 60% of world cities will be vulnerable to flooding in the next 30 years due to effects of the sea level rise [3]. Studies have been conducted in different areas such as flood data collection, flood prediction, flood monitoring, flood detection, flood early warning systems, and flood data visualization, with an aim of reducing the impact of flood disasters by alerting the affected societies abouta flood occurrence ahead of time. With current technological advancements in the domains of sensing systems, wireless communication networks, cloud computing, machine learning, and data science, it is possible to develop an integrated flood disaster management system which can efficiently alert the flood affecting regions. Internet of Things (IoT) is a core technology being used in flood early warning systems. IoT characteristics provide effective guarantee for ahead of time perception and precaution, advance to reduce the impact of disasters [4]. Despite the fact that IoT technologies cannot stop the occurrence of disasters, they are exceptionally valuable apparatus for conveyance of catastrophe readiness and counteractive action data. Such data can be used for geographical flood simulation modeling [5], which

1 CHAPTER 1. INTRODUCTION aids in policy making in flood disaster risk management. For real time flood early warning systems, information delivery is key [6]. Thus, there is a need to ensure that information delivery must be concise, right to the point, useable and in timely manner. There are several factors that are attributed to the efficiency and effectiveness of early warning systems for . These include the correctness of prediction of a flood occurrence, the amount of time needed to makea prediction, the reliability of the communication networks used in the early warning system, the deployment and maintenance cost of the systems, etc. This thesis presents a system for real time flood prediction that utilises IoT sensing and artificial neural networks where processing of the sensor data is carried out on a low power edge device.

1.1 Problem Statement

One major challenge for the future of IoT applications is that all data collected from end devices, such as IoT sensors has to be sent via the Internet to a central processing platform. This creates a scalability problem in IoT as there is an exponential growth of IoT devices which connect to the internet for either receiving information from the cloud or delivering data back to the cloud [7]. There are a number of challenges that are specific to the implementation of IoT flood early warning systems. Timeliness isone of the major parameters that contribute to the effectiveness of early warning systems. Information about the occurrence of a flood disaster needs to be presented to the affected areas as early as possible for both short term and long term flood predictions. Collecting data to a central processing platform may take a considerable amount of time especially for real time flood prediction systems. Flood early warning systems that run predictions on real time sensor data on the cloud require very good Internet connection at all times so that the quality of the forecasts is not compromised. Most of the deployments of IoT sensors that collect information that is used for prediction of flood events are located close to water bodies that may be far from the cities and maintaining a good Internet communication at all times may lead to costly deployments. The reliability of the early warning systems is also another issue to consider. Most flooding events occur in unpleasant conditions such as heavy rainfall or storms which can disrupt the Internet

2 CHAPTER 1. INTRODUCTION connectivity speeds. We need a mechanism that can allow us to process the sensor data within the proximity of where is it collected, both logically and physically. Since most IoT devices are battery powered or operate on low power, the mechanism for processing the data close to the sensors will be much effective when the processing platform also operates on low power orcan be battery powered. That means the implementation of the prediction algorithms and software are suitable for resource constrained devices. The communication mechanism between the end devices (sensors) and the data processing edge platform also needs to operate on low power. Despite the various advancements in flood prediction systems through the use of artificial intelligence methods, there has been less focus onthe utilisation of edge computing for improved efficiency and reliability of such systems.

1.2 Objectives

The objective of thesis is to design and implement a system for real-time short-term flood prediction that uses data from IoT sensors and makes a forecast of a flooding event using Artificial Neural Network (ANN) on a low power edge device. The study focuses on two major aspects. One is application of ANN for ahead of time flood prediction implemented on a low power edge device. The second aspect is designing the flood prediction system to operate on low power through the utilisation of ultra low power IoT wireless communication technology.

1.3 Scope and Limitations

In this thesis, I present a system for short-term flood prediction that utilises rainfall and water level values collected by IoT sensors in real time. The thesis focuses on the implementation of ANN for ahead of time flood prediction on a low power edge device. Another focus of this thesis is implementing the system to use low power wireless communication technology so that the whole system operates on low power and can be deployed on battery power. The system implemented will be tested in a lab setting and not on real flooding event. The thesis focuses on short term prediction of

3 CHAPTER 1. INTRODUCTION flooding events with less focus on the dissemination techniques ofthe early warning messages.

1.4 Research Methodology

This thesis follows applied research [8], where a specific real-world problem, like flood prediction is taken into account. Initially, literature study of the fields related to the problem, IoT, ANN, edge computing, is carried out as well as previous flood prediction systems are investigated. From the literature study, ANN method for short-term flood prediction, Long Short Term Memory (LSTM) and low power IoT wireless communication suitable for low power applications, Bluetooth Low Energy (BLE) are identified and motivated. After analysis of the previous flood prediction systems and identifying suitable approaches, a system for short-term flood prediction is proposed. The system is designed and a prototype is built. The system is evaluated in terms of flood prediction accuracy and response time using quantitative methods. To evaluate the prediction accuracy, statistical error methods such as the correlation coefficient (R) and Root Mean Squared Error (RMSE) are utilised. The prediction model is evaluated at different time steps ahead prediction of flood water levels and the results are compared with similar flood prediction systems. The prediction accuracy is also utilised to compare the performance of the model when using different activation and optimisation functions that were considered during design decisions. Lastly, the response time of the prototype is measured and the results are analysed.

1.5 Structure of the Report

The remaining part of this report is structured as follows. Chapter 2 gives an introduction to IoT, edge computing and Recurrent Neural Network (RNN), where there is a description of wireless communication technology and the type of RNN used in the system. The background part of the report is ended with an overview of other flood prediction systems that are related to this work. The design and implementation choices are covered in Chapter 3, followed by evaluation and analysis of results in Chapter 4. The report is concluded in Chapter 5, along with suggestions for future work.

4 Chapter 2

Background

This chapter presents an introduction to the areas related to this thesis, namely IoT, edge computing, and RNN, presented together with an overview of other flood early warning systems that are related tothis work.

2.1 Internet of Things

IoT is a network of connected embedded objects or devices, with identifiers, in which a communication using standard communication protocol can happen without human intervention [9]. IoT is currently the main technology trend in monitoring of natural and human made resources to provide early prediction which enable detection of disaster incidents like floods, fire and other disasters that may result in loss oflife or damage to property [10]. IoT functions such as overall perception of information, reliable transmission of information, and intelligent processing of information, play a crucial role in intelligent control and management. IoT characteristics provide effective guarantee for ahead of perception and precaution, advance to reduce the impact of disasters through IoT based early warning systems [4]. The implementation of IoT requires interconnected network of devices, as such Wireless Sensor networks (WSN) are the key component and can be considered as a backbone of IoT systems. WSN is a technology that is mix of reasonable and low power group of sensors and microcontrollers that might offer ubiquitous computing to discover the environmental diversity [11]. Some of the WSN that are commonly used in IoT include WiFi, BLE and ZigBee. These WSN carry different features in terms of power consumption, distance in data transmission and bandwidth. For example, BLE is a ultra low power, relatively short range communication mechanisms which is essential for future IoT

5 CHAPTER 2. BACKGROUND deployments.

BLE is a low energy version of Bluetooth specified in the Bluetooth version 4.0 [12]. BLE communication uses adaptive frequency hopping spread spectrum to access the shared channel just like classic Bluetooth communication. In BLE communication, a device can operate either in master or slave role. A master can also manage multiple simultaneous connections with a number of slave devices. A master scans multiple channels in order to discover slaves. After discovery, data transmission happens in the form of connection events in which the master and the slave wake up in synchrony to exchange frames. Both devices sleep the rest of time, unlike Wifi or Zigbee communication where the devices are always active on the communication channel. This makes BLE communication consume extremely little energy and gives it an attractive ratio of energy per bit transmitted. BLE is therefore a good choice for flood early warning systems as deployments are likely to use low power, short range communication technologies.

2.2 Edge Computing

Edge computing is defined as a part of a distributed computing topology in which information processing is located close to the edge [13]. Thus, edge computing brings computation closer to the devices where information is collected, rather than relying on a central location. The concept of edge computing was introduced in IoT to overcome the scalability problem of the traditional IoT architecture [14]. The scalability problem of IoT architectures is attributed to the exponential growth of IoT devices which connect to the internet for either receiving information from the cloud or delivering data back to the cloud [7]. Many IoT devices such as sensors generate enormous amounts of data at a fast velocity during the course of their operations. The data generated from the distributed IoT devices are transmitted to the remote cloud platform for processing via the Internet in the traditional IoT architecture [15]. The process of transferring the big data is expensive, consuming a huge amount of bandwidth, energy, and time [14]. Hence the need to design efficient data processing architectures to explore the valuable information in real time at the edge. To achieve good real-time performance of applications where computation is carried on multiple edge nodes, proper content scheduling needs to be carried out at the edge layer. Edge layer content scheduling can be efficiently carried out using deep learning methods which can be deployed at the edge [16]. Figure 2.2.1 illustrates an IoT architecture that utilizes edge computing

6 CHAPTER 2. BACKGROUND by running a deep learning network on an IoT gateway (edge server) which can be run as an independent system or complementary to a cloud based system.

Figure 2.2.1: Edge computing structure for IoT [17].

2.2.1 Edge Computing Platforms Edge devices especially those that are used in IoT applications are characterised by low power [18]. There are a number of parameters that are considered when determining an edge computing platform for an application [19].

• Power Consumption: power consumption is a key consideration when it comes to deployments of IoT edge systems. As computation is being decentralised using edge platforms, it is important to understand the power consumption of the edge devices that are used. The power consumption on the end devices is a major contributing factor if the end devices are resource constrained. Some deployments of IoT systems may be battery powered, hence the edge devices used in such systems need to operate on as much low power as possible.

• Computation Time: This is the time that is required for the edge platform to complete a specific task. Edge computing can be viewed as relocating computation from a powerful central processing platform to a relatively low power processing platform. This is because most of the edge devices are resource constrained devices and use low power. The computation time of on an edge

7 CHAPTER 2. BACKGROUND

device should not compromise the integrity of the results of the computation as in most of these systems timeliness of results is of high essence. Hence computation time is one critical factor when determining edge computing platform.

• Proximity: This is one the core ideas that edge computing was built on. Proximity can be viewed from two angles, logical proximity and physical proximity. Logical proximity is where the proximity is defined by the number of hops between the end device and the edge layer while physical proximity is defined by the actual distance of the end device from its higher layer of computation. In case of IoT systems, this is the distance from the sensors to where the corrected sensor data is processed for results. Proximity is directly linked to the response time of the system as factors such as speed of communication channels being used and reliability of the network are factored in.

• Access Mediums: End devices can connect to an edge computing platform though different connection mechanisms such as BLE, Zigbee, Wi-Fi, Bluetooth, Mobile Radio Networks etc. Access medium is an import factor since it determines the bandwidth that is available to the end devices and the number of connections that can be possible from end devices to the edge device. Proximity of the edge device to the end devices is also related to the choice of access medium as different communication technologies have different ranges of transmission, e.g. BLE has a range of about 100 m [12]. Additionally, the choice of access medium to be used should also factor in the power requirements of the system, e.g. battery powered deployments.

• Context Awareness: This is a critical factor to consider when designing a system with edge computing, especially when there are multiple edge devices that perform complementary computations. Information about the network and surrounding devices is exposed to each edge node so that it is aware of the performance or tasks carried on other devices. Different approaches are used such as creating the ability to communicate among the nodes themselves or having a node that manages messages on the network.

2.3 Recurrent Neural Networks

RNN is a class of artificial neural networks where connections between nodes form a directed graph along a temporal sequence [20]. An RNN can

8 CHAPTER 2. BACKGROUND be described as a class of ANN that extends the conventional feedforward neural network with loops in connections which is able to process the sequential inputs by having a recurrent hidden state whose activation at each step depends on that of the previous step [21]. RNNs uses their internal state to process variable length sequences of inputs there by exhibiting memory in the model. When unrolled in time, an RNN can be considered as a deep neural network with indefinitely many layers. Figure 2.3.1 shows an RNN that has been unfolded in time, where xt and yˆt are the input and output at time t respectively, and ht is the value of the hidden state at time t. At each time step t, every neuron of a layer receives both the input vector xt and the output vector from the previous time step h(t−1).

Figure 2.3.1: RNN unfolded in time [22].

This dynamic system is defined by the equations:

T T ht = Φh(w ht−1 + u xt)

T yˆt = Φo(v ht) where w, u and v are respectively the transition, input and output matrices, and Φs and Φo are element-wise nonlinear activation functions such as ReLU for Φs and sigmoid for Φo.

LSTM is a special type of recurrent hidden unit, capable of learning long-term dependencies [23]. In contrast to RNN which has traditional recurrent hidden unit that calculates a weighted linear sum of inputs and then applies a nonlinear function, LSTM recurrent layer creates memory cell ct at step t. RNN may suffer from the vanishing/exploding gradients problem as gap between the relevant observed information and the desired prediction grows, as such RNN become unable to learn to connect the information [24]. LSTM was introduced to solve this problem and has since been very useful in practical time series predictions. Figure

9 CHAPTER 2. BACKGROUND

2.3.2 shows the internal structure of an LSTM cell which is made of input, output, forget gates, and cell state.

Figure 2.3.2: LSTM with internal structure [24].

LSTM state is split in two vectors, namely short-term state h and long-term state c. The LSTM can remove or add information to the cell state, regulated by three gates, forget gate, input gate and output gate. The forget gate decides what information we are going to throw away from the cell state. This decision is made by a sigmoid layer, called the forget gate layer. T T ft = σ(uf xt + wf ht−1) (2.1) The second step is to decide what new information we are going to store in the cell state. A sigmoid layer, called the input gate layer, decides which values will be updated. A tanh layer then creates a vector of new candidate values that could be added to the state.

T T it = σ(ui xt + wi ht−1) (2.2)

T T ct = tanh(uc xt + wc ht−1) (2.3)

The third step is to update the old cell state ct−1 into the new cell state ct, by multiplying the old state by ft.

ct = ft ⊗ ct−1 + it ⊗ ct (2.4)

The final step decides the output, a sigmoid layer determines what parts of the cell state we are going to output.

T T yˆt = Φh(u xt + w ht−1) (2.5)

10 CHAPTER 2. BACKGROUND

2.4 Flood Forecasting Using ANN

Forecasting future data points using past time series data is of great interest for many applications that require time series analysis. Flood prediction is one of such type of applications as flood events can be modelled as non linear time series events. ANN have shown good results in working upon the non-linear times series data obtained from the sensors for prediction purpose [25]. Nonlinear Autoregressive network with EXogenous inputs (NARX) network is one of the ANNs that has been widely used in the prediction of floods and rainfall. NARX is a dynamic recurrent network with feed- forward connections having multiple layers of network. NARX is mainly applied to input-output modelling of nonlinear dynamic systems such as time-series prediction [26]. Figure 2.4.1 shows structure of a NARX neural network.

Figure 2.4.1: NARX neural network model structure [27].

Recently, studies have shown that LSTM is a reliable alternative in hydrological sequence time-series predictions [25], due the capability of learning long-term dependencies. LSTM has become a suitable flexible alternative to NARX network and has shown better results against NARX in different non linear time series prediction applications28 [ ].

11 CHAPTER 2. BACKGROUND

2.5 Related Work

The development of flood related early warning systems using IoT sensing has been conducted in various research projects, with focus on detection and prediction of flood events. Statistical methods have been used in the prediction of flood occurrences based on environmental conditions while recently the use of machine learning methods such as artificial neural networks has gained popularity. This section discusses some of the IoT flood early warning systems that are related to this work. A prototype for IoT based flood monitoring system that provides users with real time water levels and weather conditions was developed by Satria et al. [29], with a focus on flood detection. Water level and rainfall data is acquired using ultrasonic sensors HC-SR04 and rain sensor respectively. The data collected from the sensors is transmitted to an Arduino Uno microcontroller platform to determine the threat level in reference to set water level thresholds. Flood altitude information and rainy weather from the Arduino are distributed using an ethernet module integrated with Wireless N Router TL-MR3020 as an Internet gateway. A user can access the real-time web-based water level status on a web browser with different colors depicting the threat level on the interface. The prototype was evaluated in a controlled environment and performed well on detection of flood water level and rainfall and displaying the information to users in real time. The prototype does not include more processing of the collected data to determine the threat level ahead of time as it mainly targets at displaying current water level and rainfall status. Furthermore, the system requires Internet connectivity at all times and may consume a lot of power in a deployment setting due to the hardware platforms being used. Bande et al. designed a flood prediction system using IoT and ANN that aimed at enhancing the scalability and reliability of flood management systems [30]. The system monitors humidity, temperature, air pressure, rainfall and water level to find their temporal correlative information for flood prediction analysis. Temperature sensor (LM35), humidity sensor (BME280), water level sensor (FDC1004) are connected to a Raspberry Pi module. Each Raspberry Pi module acts as a single IoT node in a network where all devices are connected by Wi-Fi using WLAN technology from a Wi-Fi hotspot. The data is then sent over the Internet to a cloud based ANN for flood prediction and the results are displayed in a web based platform. NARX is utilized for the prediction of flood water level in this work. A flood dataset obtained from Chennai region was used in the training of the ANN and its evaluation. The system was evaluated to provide a one time-step ahead of time prediction with an

12 CHAPTER 2. BACKGROUND accuracy of 0.88. Abdullahi et al. [31] developed an IoT based intelligent flood disaster warning system, where they utilised a 2-class neural network for on the fly prediction of flood status. The system was evaluated in a controlled environment where they used a miniaturized flow sensor, water level sensor and pressure sensor. The data from the sensors was used to predict the flood status in real time. Microsoft Azure Machine learning (AzureML) pre-trained 2 class neural network was retrained and used to predict flood status according to predefined rules of the testing environment. NodeMCU ESP8266 was used for collecting the sensor data and transmitting it to the cloud based platform via WiFi. The system provided on the fly flood prediction using the real time sensor data with the highest accuracy of 0.98 for the controlled environment. The system was evaluated using rules and generated data that was suited for the controlled environment and the prediction did not use a time series prediction model. Additionally, this system would require reliable internet connectivity at all times to be able to perform the on the fly prediction. Furthermore, if deployed at a large scale, the system will be expensive to maintain as WiFi connection consumes more battery power for IoT connected devices. Maspo et al. proposed an IoT flood early warning system that is complised of WSN, camera, and mini weather station [32]. The wireless sensors are used to collect water level and water flow data. A weather station collects temperature, wind speed and direction. Cameras capture images of surrounding environment. The system proposed has a layered architecture. WiFi and Zigbee are used in network layer to transfer the collected data from sensors and camera for analysis of the flood occurrence in the cloud service. The middle layer is a cloud based prediction analysis platform. The analysis result is then presented as a flood map that is displayed in application layer for user toaccess and make use of information through smartphone. Push notification are used for the dissemination of the warning messages in case of a critical situation. The layered architecture of the flood early warning system proposed in this paper gives flexibility and ability to reuse the parts of the system in other early warning systems. Jayashree et al. proposed a flood early warning system that is not dependent on mobile towers for alert message broadcasting [33]. The system operates on low power and works well even in absence of Internet using ZigBee. A dam water filling plant consists of distance sensor and flow sensor for monitoring level and speed of flow of water. If thewater level changes, a microcontroller automatically sends the information about the water level to server. If the level exceeds a specified limit,

13 CHAPTER 2. BACKGROUND alert messages are broadcasted through ZigBee. For checking the speed of the water flow, flow sensors are used. If there is a change inthe flow rate, the server is notified. All these values are sent to theserver via ZigBee transceiver. The system was designed for monitoring of a flood occurrence on a dam and provides real time alerts in case ofa flooding event while operating on low power. However, the system does not include more data analysis for ahead of time prediction of a flooding event.

14 Chapter 3

Design and Implementation

This chapter presents the design and implementation of a flood prediction system as a solution to the problems presented in the Introduction chapter. The first section of this chapter provides an overview ofthe proposed system. In the second section, the IoT framework and the wireless communication technology used is discussed and motivated. In the third section, an outline of the ANN prediction method is given and motivated. The section also includes an overview of the dataset used to train and evaluate the ANN. In the forth section, the system flow is described. In the last section, information about the hardware and software tools used in this thesis is discussed and motivated.

3.1 Proposed System

In this study a system for on the fly ahead of time prediction of flood water levels is proposed. The system uses IoT sensing to collect environmental parameters in real time and makes a short term forecast of the water level using ANN while utilising edge computing. Similar to the system by Bande et al. [30], environmental parameters such as water level and rainfall are collected using IoT and used for prediction of flood water levels using ANN. Additional environment conditions that affect rainfall such as humidity, temperature, air pressure, etc. may improve prediction of floods when using ANN. However, rainfall and water level data has proven to be adequate in the prediction of flood water levels using time series ANN analysis with good performance [34][24]. Similar to the system by Abdullahi et al. [31], the proposed system is for monitoring sensor data in real time for short term flood prediction on the fly. Unlike both systems by Bande et al. [30] and Abdullahi et al. [31], the proposed flood prediction system utilises edge computing as the flood prediction is carried on a low power edge computing device which is

15 CHAPTER 3. DESIGN AND IMPLEMENTATION within the IoT WSN. This means the raw sensor data is not sent over the Internet at all times for the real time prediction of water levels but rather the output of the prediction at relevant intervals. Secondly, unlike both systems, the proposed system operates on low power as it uses low power devices for IoT sensing and edge computing, and utilises a ultra low power WSN communication between the sensing nodes and the computing edge platform. Thus, the proposed system can be deployed as a battery powered IoT flood prediction system where Internet access is provided to the edge computing platform and not all sensor nodes. Lastly, unlike both systems, the proposed system uses a different ANN analysis for better performance and the model has been evaluated on a real dataset.

System Design Overview Distance and rainfall sensors are used to collect water level and rainfall data respectively. The sensors are connected directly to a low power IoT BLE device, Arduino Nano 33 BLE [35]. The combination of the two sensors and the Arduino Nano 33 BLE makes a single IoT sensing node. The sensing node is connected to an edge device via BLE wireless communication. The edge computing platform used in this study is Raspberry Pi 3B+ [36]. Figure 3.1.1 shows the block diagram of a single IoT node and the edge device in the proposed system.

Figure 3.1.1: Block diagram of a single IoT node and edge computing platform for the proposed system.

3.2 IoT Framework

Multiple Arduino Nano 33 BLEs can be connected to Raspberry Pi through BLE connection as it can support multiple connections. The sensor data is processed on the Raspberry Pi. Depending on the output of the forecast, early warning messages can disseminated using the Internet, local networks or an alarm system can be connected directly to the edge

16 CHAPTER 3. DESIGN AND IMPLEMENTATION gateway. Figure 3.2.1 shows the proposed IoT framework for the flood prediction system.

Figure 3.2.1: IoT framework for the proposed system.

For this study, Internet connection is available on the Raspberry Pi that is used to send the forests output to a cloud based IoT systems monitoring platform, ThingSpeak [37]. ThingSpeak can be used for dissemination of early warning messages on a variety of social media platforms on the Internet such as Twitter, Facebook, etc. Other early warning messages dissemination techniques include short message service (SMS) [29] and local IoT WSN [33]. However, as the focus of this study is on the prediction of floods and the evaluation is carried out inalab setting, ThingSpeak is used for monitoring of results.

3.2.1 IoT Wireless Technologies Alternatives There are a number of wireless technologies for IoT systems. Due to the diverse nature of IoT, different wireless technologies may be suitable for different applications. The following are some of the most used IoT wireless technologies in early warning systems.

• ZigBee: Zigbee (based on IEEE 802.15.4) is a short-range, low- power, wireless standard , commonly deployed in mesh topology to extend coverage by relaying sensor data over multiple sensor nodes [38]. Zigbee provides medium data rates up to 250 kbps which makes the it suitable for numerous IoT applications that require short range communication (< 100m). However, Zigbee has much less power-efficiency due to mesh configuration. Zigbee is best- suited for medium-range IoT applications with an even distribution of nodes in close proximity such as home automation. Jayashree et al. [33], applied Zigbee in flood early warning system which involved motoring of water levels and water flow and sending the results over Zigbee to near areas using Zigbee transceivers.

17 CHAPTER 3. DESIGN AND IMPLEMENTATION

• Wi-Fi: Wi-Fi implements the IEEE 802.11 standard and offers wireless networking with very high data rates [38]. Wi-Fi is the dominant protocol being used today in various application that require high data rate such as multimedia applications. Imposing high energy requirements, Wi-Fi is often not a feasible solution for large networks of battery-operated IoT sensors such as those used in health and early warning systems. Bande et al. [30], used Wi-Fi technology in communication in the flood prediction system where sensor data from each IoT node was transferred via Wi-Fi to a cloud based analysis platform on the Internet. However, the system can be expensive to deploy and maintain as the wireless technology being used can hardly operate on battery power for a long period of time.

Motivation for Using BLE

BLE is a version Bluetooth technology that is suitable for most battery powered IoT applications due to it’s ultra-low power operation capability. BLE is a short range communication technology with range of 100 m and operates on medium data rates up to 1 mbs [12]. BLE devices can be configured to communicate with each other as the technology supports mesh networks. A mesh network allows a configuration where a large number of BLE devices can be connected over a wider area without a central gateway to pass all traffic. In this situation, all devices inthe same mesh are able to communicate with each other, either directly or via one or more intermediate nodes, as long as each node is close enough to at least two others. Figure 3.2.2 shows a sample BLE mesh network where multiple BLE devices are connected to each other and one node is connected to the Internet.

BLE technology is suitable for this system since both the IoT nodes and the edge device are low power devices and can be deployed on battery power. According to a study conducted by Siekkinen et al. [12], which compared the energy efficiency of Zigbee and BLE, BLE is very energy efficient in terms of number of bytes transferred per Joule spent than Zigbee. Thus, it can allow cost effective deployment of the flood prediction system as devices can run on battery power overalong period of time. Secondly, although BLE offer lower data rates than WiFi technology, it is adequate for the amount of data being sent from the sensors for flood prediction i.e. rainfall and water level data.

18 CHAPTER 3. DESIGN AND IMPLEMENTATION

Figure 3.2.2: BLE mesh network with multiple BLE nodes and an Internet gateway.

3.3 ANN Analysis

The data collected from the sensors is processed on the edge device using ANN. The ANN works upon the time-series data obtained from the sensors for prediction purpose in real time. In this study, the ANN model created for the system is trained and tested for performance on real data. The trained model is then modified and transferred to the Raspberry Pi where tests using real sensor data are carried out to record the performance of the system in real time forecasting of the flood water levels. The experimental setup for testing the performance of the whole system is done in such a way that the data collected by the sensors for demonstration purposes is scaled within the limits of the actual data set.

3.3.1 Dataset Description The dataset used in this thesis is made of hourly rainfall and water level data sourced from Melbourne Water website [39]. The data is in the form of a time series, represented by time-stamps with corresponding rainfall and water level values. The dataset consists of 78844 rows and was collected hourly between 2009-12-01 00:00:00 and 2018-12-02 18:00:00, representing approximately 9 years of hourly rainfall and water level data. According to Melbourne Water, the maximum safe water level is 1.5 m and any values above that may lead to flooding. Figure 3.3.1 shows the plot of the scaled hourly rainfall and water level data for the period between 2009-12-01 00:00:00 and 2018-12-02 18:00:00. Figure 3.3.2 shows the plot of the scaled hourly rainfall and water level data zoomed in on

19 CHAPTER 3. DESIGN AND IMPLEMENTATION the year 2010. The graphs shows that the rainfall and water level data is highly correlated as it is expected.

Figure 3.3.1: Scaled hourly rainfall and water level data for the period between 2009-12-01 00:00:00 and 2018-12-02 18:00:00.

3.3.2 Data Preparation During data processing, both rainfall and water level data was scaled to the interval [0,1]. Scaling is necessary to speed up the training process since the model converges faster when features are relatively smaller or closer to normal distribution [40]. Prior to model training, the data was prepared and transformed into a data frame suitable for training the ANN. At first, the time series were transformed into sequences of features and labels. The feature sequence represents values of rainfall and water level in the past, while the label sequence represents the water level value ahead, with the respect to the current time t. The data is divided in a ratio of 70% for training, 15% for validation and 15% for testing. Training data is used for calculating errors during the training process. Validation data is used for having the generalization under control and stopping the training process when the loss reaches a predetermined value. Testing data has no connection to the training process at all and provides an independent check of performance during and after training.

20 CHAPTER 3. DESIGN AND IMPLEMENTATION

Figure 3.3.2: Scaled hourly rainfall and water level data for 2010

3.3.3 Short-Term Flood Prediction Using LSTM

Short-term flood prediction involves prediction of a flooding event in real time mostly anywhere between few minutes and hours preceding the flood [41]. In contrast to long-term flood prediction, which is mostly used for policy analysis purposes, the aim of short-term flood prediction is to reduce damage and harm caused by a flood disaster [42]. Short-term flood prediction systems with lead time are considered important research challenges, particularly in highly populated areas for timely warnings to residences [42]. Despite several improvements in statistical weather prediction models, artificial intelligence and machine learning methods, short-term flood prediction remains a challenging43 task[ ][44]. Is this study, LSTM is utilised for short-term prediction of flood water levels. LSTM is mainly applied to input-output modelling of nonlinear dynamic systems such as time-series prediction [45]. By observing a multivariate time series of rainfall and water level, the model outputs a forecast of the water level ahead of time. The input to the model is ten time steps sequence of water level and rainfall data (i.e. ten hours) and the output is a forecast of the water level in ten hours. Figure 3.3.3 shows the pattern of LSTM prediction used in the forecasting of water levels. The input xt represents a vector of rainfall and water level values and the output yt represents water level values at time t.

21 CHAPTER 3. DESIGN AND IMPLEMENTATION

Figure 3.3.3: LSTM pattern for the proposed system.

Model Structure

The model is made of an LSTM layer, a dropout layer and an output dense layer. Figure 3.3.4 shows model layers and some properties. Rectified Linear Unit (ReLU) activation function is used in LSTM layer for activation. ReLU is a unit in neural networks that use the activation function max(0, x) and is used both as activation functions in more standard neural networks and as units in restricted Boltzmann machine. The main advantage of using the ReLU function over other activation functions is that it does not activate all the neurons at the same time [46]. Thus, the neurons will only be deactivated if the output of the linear transformation is less than 0. Since only a certain number of neurons are activated, the ReLU function is far more computationally efficient when compared to other activation functions such as sigmoid and tanh function. Besides having better performance than sigmoid and tanh activation function, ReLU activation function is a suitable choice for this system as our model will run on a resource constrained edge device where the model’s computational efficiency is relevant. The dropout layer was added in order to prevent overfitting during training. Dropout is a technique for improving the generalization error of neural networks [47]. Dropout prevents overfitting and produces far more robust models by adding noise during training without slowing down the learning process. Dropout does not occur during testing to allow all the trained units to contribute in the prediction process. The last layer in the neural network is the output dense layer. The model is compiled with Mean Squared Error (MSE) loss function. The loss function is used to optimize the parameter values in the model during training. This is done by mapping a set of parameter values for the network onto a scalar value that indicates how well those parameters accomplish in terms of performance. MSE is calculated as the average of the squared differences between the predicted and actual values as shown in equation (3.1). For regression problems, MSE is the

22 CHAPTER 3. DESIGN AND IMPLEMENTATION

Figure 3.3.4: Model architecture for the proposed system showing inner layers. mathematically preferred loss function under the inference framework of maximum likelihood [48].

1 ∑n MSE = ( ) (y − x )2 (3.1) n i i i=1

The model is compiled with Adaptive moment estimation (Adam) optimiser. Adam optimisation algorithm combines the heuristics of Adaptive Gradient Algorithm (AdaGrad) and Root Mean Square Propagation (RMSProp) [49]. Similar to AdaGrad, it keeps track of an exponentially decaying average of past gradients. Similar to RMSProp, it keeps track of an exponentially decaying average of past squared gradients. Adam computes individual adaptive learning rates for different parameters from estimates of first and second moments of the gradients.

23 CHAPTER 3. DESIGN AND IMPLEMENTATION

Adam works well in practice and compares favorably to other stochastic optimization methods [49].

Model Training

The training was conducted in mini batches of size 64 for 200 epochs. In mini batch training, a single mini batch is passed through the network which computes the loss of every sample in the batch and uses their average to update the parameters of the neural network. Mini batch training is preferred over training on the whole dataset as it is computationally efficient and can allow training with large dataset as smaller chunks of the dataset are loaded into memory at a time [50]. An early stopping callback was implemented to prevent the model from overfitting when training the model. During training, there is a point when the model will stop generalizing and start learning the statistical noise in the training dataset. This overfitting of the model on the training dataset will result in an increase in generalization error, making the model less useful at making predictions on new data. To overcome this challenge early stopping was introduced in neural networks. Early stopping works by monitoring the model performance during training and triggers a stop when a certain threshold is reached [51].

3.3.4 Alternative Methods for Flood Prediction FFNN is another type of ANN that can be used in flood forecasting. Feed Forward Neural Network (FFNN)s are made of at least three layers namely input, hidden and output layer. The number of neurons in each layer varies for each problem due to its complexity. In the input layer, the number of neurons corresponds to the number of input parameters, while the output layer is related to the output result. between the input and the output layer there can be one or more hidden layers with arbitrary numbers of neurons. Figure 3.3.5 shows the simple FFNN with the three layers. FFNN has been used to predict floods or water levels in different studies. One disadvantage of using FFNN in prediction of non linear events such as flood water levels is that FFNN does not take into account sequence information, since it does not have recurrent connections. According to a study by Hrnjica et al. [24], which compared the performance of LSTM and FFNN on long-term prediction of lake water levels using water level data only, LSTM had a better performance than FFNN. The comparison was based on one step ahead prediction of water level as FFNN can not predict for more steps ahead as it does not have memory.

24 CHAPTER 3. DESIGN AND IMPLEMENTATION

Figure 3.3.5: FFNN with three interconnected layers [24].

3.4 System Flow

The model is trained in a cloud based platform and transferred to the Raspberry Pi. The trained model is then used for the real-time prediction of flood water levels. Figure 3.4.1 shows a flowchart showing the short- term proposed flood prediction system. The sensor data is read via BLE wireless communication at intervals. The sensor data read within an hour is filtered by getting the mode of the values for both water level and rainfall. The data is then reframed and scaled to be used for ANN prediction. The scaled data is pushed at the top of the array. Time series data representing the last ten hours is read from the array by retrieving the most recent top ten values of water level and rainfall. The sequence data is then used for ahead of time prediction of the water levels using the LSTM network. The predicted water level values are then compared against the flood water level threshold. Depending on weather the predicted values exceed the threshold for safe water level, a warning message may be generated.

25 CHAPTER 3. DESIGN AND IMPLEMENTATION

Figure 3.4.1: Flowchart showing the short-term proposed flood prediction system.

3.5 System Setup

The edge computing platform used in this project is a Raspberry Pi 3B+ [36] and connects to IoT sensing nodes via BLE. For ANN analysis, TensorFlow Lite [52] platform is used on the Raspberry Pi to allow better performance. An IoT sending node is made up of an Arduino Nano 33 BLE [35] with the rain sensor and water level sensor.

3.5.1 TensorFlow Lite TensorFlow Lite is a platform for running TensorFlow models on mobile, embedded, and IoT devices. It enables on device machine learning

26 CHAPTER 3. DESIGN AND IMPLEMENTATION inference with low latency and a small binary size. TensorFlow Lite is designed to make it easy to perform machine learning on devices at the edge. TensorFlow Lite features include model optimization tools, including quantization, that can reduce size and increase performance of models without sacrificing accuracy. TensorFlow Lite has interpreter tuned for on-device ML, supporting a set of core operators that are optimized for on-device applications, and with a small binary size. This makes it suitable for running ANN on resource constrained devices and is therefore suitable for this system.

3.5.2 Raspberry Pi 3B+ Raspberry Pi 3 Model B+ is the final revision in the Raspberry Pi3. The board runs on Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC @ 1.4GHz processor and has 1GB LPDDR2 SDRAM. The board is equipped with 2.4GHz and 5GHz IEEE 802.11.b/g/n/ac wireless LAN, Bluetooth 4.2, BLE. The board operates on 5V/2.5A DC power input and has Power-over-Ethernet (PoE) support. This is suitable for our system as the board has BLE for communication with the IoT sensing nodes, can connect to the Internet via wireless LAN and can operate on battery power. Figure 3.5.1 shows a Raspberry Pi 3 Model B+.

Figure 3.5.1: Raspberry Pi 3B+ (edge computing platform) [36].

27 CHAPTER 3. DESIGN AND IMPLEMENTATION

3.5.3 Arduino Nano 33 BLE Arduino Nano 33 BLE is a low power arduino board operating at 3.3V and has dimensions 45x18 mm. The Nano 33 BLE has nRF52840 32- bit ARM Cortex M4 CPU running at 64 MHz. The processor includes features like Bluetooth pairing via NFC and ultra low power consumption modes. The communications chipset on the Nano 33 BLE can be both a BLE and Bluetooth client and host device. This is a very useful feature as it allows mesh networking among a number of Nano 33 BLE boards without the need of a central server and useful to this project. Figure 3.5.2 shows an Arduino Nano 33 BLE board.

Figure 3.5.2: Arduino Nano 33 BLE (IoT end device) [35].

3.5.4 Sensors • Water Level Sensor: HC-SR04 ultrasonic sensor [53] is used for measuring water level. A ultrasonic sensor is an instrument that measures the distance to an object using ultrasonic sound waves. A ultrasonic sensor uses a transducer to send and receive ultrasonic pulses that relay back information about an object’s proximity. The sensor provides 2 cm to 400 cm of non-contact measurement functionality with a ranging accuracy that can reach up to 3 mm. The sensor is directly connected to the Nano 33 BLE pins. Figure 3.5.3 shows a HC-SR04 ultrasonic sensor.

28 CHAPTER 3. DESIGN AND IMPLEMENTATION

Figure 3.5.3: HC-SR04 ultasonic sensor (water level sensor) [53].

• Rain Sensor: Octopus rain sensor [54] is used to measure the amount of ran in this project. The Pi Supply Octopus Rain/Steam Sensor is connected to the Arduino IO Expansion shield directly. The output voltage will increase when the humidity of the sensor surface goes up. The sensor can operate on 3.3v or 5v.

Figure 3.5.4: Octopus rain sensor [54].

29 Chapter 4

Evaluation

In this chapter, the proposed flood prediction system is evaluated. The evaluation consists of two main parts: evaluation of the correctness of the predictions produced by the model on unseen test data and an evaluation of the performance of the flood prediction system prototype. For each part of evaluation, the results are given and discussed. The last part of this chapter contains a comparison of different design approaches that were considered for this system.

4.1 Forecast Accuracy

We study the accuracy of the forecasts produced by the LSTM model and how it is impacted by the number of time steps between the observed time series and the predicted water level. We expect a higher accuracy when predicting the water level for few time steps ahead and reduction in accuracy as the number of time steps increases. Performance of a regression model, such as flood water level prediction model, can be evaluated using different statistical error measures. The statistical error measures inlude Mean Absolute Error (MAE), RMSE, and R.

• MAE: The MAE measures the average of the absolute difference between each ground truth and the predictions. MAE can be interpreted as the standard deviation of the unexplained variance, and has the useful property of being in the same units as the response variable.

1 ∑n MAE = ( ) |y − x | (4.1) n i i i=1

• RMSE: The RMSE measures the square root of the average of the

30 CHAPTER 4. EVALUATION

squared difference between the predictions and the ground truth. Ã 1 ∑n RMSE = ( ) (y − x )2 (4.2) n i i i=1

• R: R is a statistical measure of the strength of the relationship between the relative movements of two variables. R values range between -1.0 and 1.0, where -1.0 shows a perfect negative correlation, 1.0 shows a perfect positive correlation. R value of 0.0 shows no linear relationship between the movement of the two variables. ∑ n (y − y¯ )2(ˆy − y¯ˆ )2 R = »∑i=1 i i i i (4.3) n − 2 − ˆ 2 i=1(yi y¯) (ˆyi y¯)

The model is evaluated based on these metrics for predictions of water levels at different time steps ahead on unseen test data. The testdata is extracted from the most recent part of the dataset before data pre- processing and is not used during the training and validation of the model. MAE, RMSE and R for predictions at different time steps ahead can be seen from Table 4.1.1.

Table 4.1.1: MAE, RMSE and R values for the forecasts at different number of hours ahead of time.

time steps ahead MAE RMSE R 1 0.021 0.041 0.971 2 0.027 0.051 0.956 3 0.035 0.059 0.941 4 0.045 0.069 0.918 5 0.060 0.082 0.882 6 0.063 0.078 0.869 7 0.075 0.098 0.829 8 0.082 0.101 0.800 9 0.091 0.115 0.752 10 0.102 0.127 0.700

Figure 4.1.1 and Figure 4.1.2 illustrate the forecasts produced by the model for the water level one time step ahead and ten time steps ahead respectively plotted together with true water levels.

31 CHAPTER 4. EVALUATION

Figure 4.1.1: 1 hour ahead of time forecasts of water levels plotted together with true water levels.

Figure 4.1.2: 10 hours ahead of time forecast of water levels plotted together with true water levels.

By visually inspecting both Figure 4.1.1 and Figure 4.1.2, we see that the best performance is seen when predicting one time step ahead

32 CHAPTER 4. EVALUATION where the predicted data points almost overlapping with the true data point at all times. The result of the evaluation for each prediction at different time steps is plotted to visualise how well the model performs for variable number of time steps ahead for the prediction. Figure 4.1.3 and Figure 4.1.4 show the R and RMSE values respectively for the model performance at different time steps ahead prediction of water levels.

Figure 4.1.3: R values at different time steps ahead prediction of water levels.

Figure 4.1.4: RMSE values at different time steps ahead prediction of water levels.

The highest R value is 0.971 obtained for predictions of one time step ahead and the lowest value of is 0.7 obtained for predictions of ten time

33 CHAPTER 4. EVALUATION steps ahead. The values of R for water level forecasts at different time steps ahead, between one and ten can also be seen from Table 4.1.1. The lowest MAE and RMSE values are 0.041 and 0.021 respectively obtained for predictions of one time step ahead and the highest values are 0.127 and 0.102 respectively obtained for predictions of ten time steps ahead. The relation between RMSE and R values, and the number of time steps ahead in the predictions is visualised in Figure 4.1.3 and Figure 4.1.4 respectively. The R values decrease gradually each time when the number of time step ahead in the predictions increase as shown in Figure 4.1.3. The RMSE values increase gradually each time when the number of time step ahead in the predictions increase as shown in Figure 4.1.4. This is as expected since the chronological connection between the observed time series and the predictions is weaker when the number of time step between them increases. To further analyse the correlation between the predicted and target water levels, scatter graphs are plotted for the predictions with the highest and lowest R value. Figure 4.1.5 shows a scatter graph of the true water levels (target) and water level forecasts one time step ahead (predictions). Figure 4.1.6 shows a scatter graph of the true water levels and water level forecasts ten time steps ahead.

Figure 4.1.5: Scatter graph of prediction and target values of one time step ahead forecast of water level.

34 CHAPTER 4. EVALUATION

Figure 4.1.6: Scatter graph of prediction and target values of 10 time steps ahead forecast of water level.

The graphs include X = Y plot which indicates a line where the predicted water levels perfectly matches the true water levels. The graphs also include a regression line plotted as a best fit on the data points. The closeness of the regression line to the X = Y plot indicates the similarity between the target and the predicted output, which depicts how well the model describes the test data during different time steps ahead prediction of water levels. For an ideal prediction case, the solid regression line should copy the X = Y dotted line and the R parameter value would have to be 1. That means a perfect correlation between the predictions and the target. In Figure 4.1.5, the result of the correlation for predictions of one time step ahead is 97.1% which means there is 97.1% similarity between the target and the predicted output. This can also be seen from the graph as more data points are very close to the X = Y dotted line and so is the regression line. This indicates the suitability of this model to be used in real flood prediction, by observing rainfall and water level time series. The R values for predictions of water levels 5 time steps ahead is 88.2% while that for 10 time steps ahead is 70%. In Figure 4.1.6, the data points are slightly scattered with the regression line slightly bending away from the X = Y dotted line as compared to Figure 4.1.5, thus indicating a lower R value for water level predictions ten time steps ahead.

35 CHAPTER 4. EVALUATION

4.2 Performance of the Prototype

This part involves testing a prototype of the proposed system to check if it works as intended and measuring the response time. To measure the response time, Python timeit [55] is utilised to mark the time from just before making a BLE connection between the Raspberry Pi and the Nano 33 BLE to read the sensor data, through data pre-processing and making prediction using the model, until making a decision on the threat level based on the forecasts. To visualise the real time sensor values and output of the forecasts and flood alerts created by the system, ThingSpeak [37] is utilised. If the output of the forecast is critical, a tweet is created using ThingTweet with a flood alert message. ThingTweet is part of the ThingSpeak platform which is used for visualisation and testing alerts for IoT early warning systems. The platform can also be used in deployment settings, where the alert messages can be seen by the target audience. A visualisation of the real time data from the sensors, flood alert level and a sample flood early warning message in form of a tweet is shown in Appendix A.

4.2.1 Response Time The response time of the proposed system consists of two parts. Firstly, the time taken for the Raspberry Pi to establish a BLE connection to a Nano 33 BLE and read sensor data over the connection. Secondly, the time taken to prepare the raw sensor data for ANN prediction, making predictions using the LSTM model, and comparisons to thresholds to determine the flood alert status.

Table 4.2.1: Response time for reading sensor data over BLE connection.

Observation BLE connection (s) 1 4.8468 2 5.3903 3 4.8051 4 4.8546 5 5.0253 6 5.0480 7 4.9322 8 4.9220 9 4.8505 10 4.8451

36 CHAPTER 4. EVALUATION

Table 4.2.2: Response time for data preparation and forecasting.

Observation Flood forecasting (s) 1 1.3819 2 1.1527 3 1.1990 4 1.4271 5 1.2275 6 1.3508 7 1.5212 8 1.4761 9 1.1500 10 1.3880

Table 4.2.1 shows the response times for establishing connection and reading sensor data over BLE connection. Table 4.2.2 shows the response times for data preparation, making predictions using the LSTM model, and comparisons to thresholds to determine the flood alert status. The average time for establishing a BLE connection and reading sensor data over the connection is 5 seconds and the average time for data preparation and forecasting is 1.3 seconds. Thus, the flood prediction system completes the process in less than 7 seconds. This is a reasonable response time considering that the shortest time span for a prediction using this model is one hour ahead of time. Computation time is a key factor to consider when choosing an edge computing platform [19]. This shows that the edge computing platform in this proposed system can be able to handle the computation requirements of the application without compromising the integrity of the outcome and therefore suitable.

4.3 Comparison of Alternative Design Approaches

This part of evaluation involves the comparisons of design alternatives considered for the proposed system and measurements carried out. The results were considered during design decisions. The size of the model when compiled by Tensorflow and Tensorflow Lite was measured togain insight on the model size reduction. The perfomance of the model when using different activation functions and optimizers was also compared.

37 CHAPTER 4. EVALUATION

4.3.1 Model Size Reduction by Tensorflow Lite Figure 4.3.1 shows the model sizes obtained by compiling the model using Tensorflow and Tensorflow Lite, before and after training. As visualised, there is almost a 60% decrease in model size when using Tensorflow Lite. This is a necessary optimisation as the proposed system is running on a resource constrained low power device.

Figure 4.3.1: Model sizes for Tensorflow and Tensorflow Lite.

4.3.2 Performance Comparison of ReLU, Sigmoid and Tanh Activation Functions

Figure 4.3.2: Performance comparison of ReLU, sigmoid and tanh activation functions.

38 CHAPTER 4. EVALUATION

The model was tested for performance with ReLU, sigmoid and tanh activation functions. Figure 4.3.2 shows the performance comparison of ReLU, sigmoid and tanh activation functions at different time steps ahead predictions. As visualised, the model performed better when using ReLU activation function as compared to using sigmoid and tanh consistently for predictions at different time steps ahead.

4.3.3 Performance Comparison of Adam and SGD Optimizers The model was tested for performance with Adam and Stochastic Gradient Descent (SGD) optimizers. Figure 4.3.1 shows the performance comparison of Adam and SGD optimizers at different time steps ahead predictions. As visualised, the model performed better when using Adam optimizer as compared to using SGD consistently for predictions at different time steps ahead

Figure 4.3.3: Performance comparison of Adam and SGD optimizers.

39 Chapter 5

Conclusions and Future Work

Conclusions from the design, implementation, and evaluation of the proposed flood prediction system are presented in this chapter together with future work.

5.1 Conclusions

In this thesis, a system for short-term flood prediction is proposed. The prediction of flood water levels is carried by LSTM using rainfall and water level data that is obtained by IoT sensors in real time. The model is evaluated to have a minimum RMSE of 0.041, with a correlation of 97.1% between the predicted water levels and true water levels, for prediction of water levels one time step (one hour) ahead. This is a better performance compared to a similar short-term flood prediction system [30] which uses NARX for flood prediction one time step ahead, with a correlation of 88.12%. Our model was also evaluated for predictions of water levels at different time steps ahead, from one to ten, and the lowest observed correlation is 70% for predictions at ten time steps ahead. This is as expected since the chronological connection between the observed time series and the predictions is weaker when the number of time step between them increases. The most distinct feature about the proposed system is that the predictions are carried out on a low power edge computing platform. This means the raw sensor data is not sent over the Internet all the time but rather the result of the prediction when necessary. To achieve this efficiently and without delay, low computationally demanding deep learning platform, Tensorflow Lite, and low power IoT wireless communication technology, BLE, are utilised. This means that the proposed flood prediction system can be deployed as a battery powered IoT system with low deployment and maintenance costs. The application

40 CHAPTER 5. CONCLUSIONS AND FUTURE WORK of ANN with edge computing will help improve the efficiency of flood early warning systems by bringing the prediction computation close to where data is collected and improve reliability of the systems.

5.2 Future Work

There are many other aspects of flood prediction using ANN at the edge which would be interesting to investigate. The first aspect is on the possibility of observing more futures for predictions, in addition to water level and rainfall values, to improve the performance of the model when predicting floods further in time, for short-term (e.g. 10 to 15hours ahead). Environmental conditions that affect rainfall such as humidity, air pressure, temperature, etc., could be observed by sensors to improve the performance of the model when forecasting. The second aspect is on the techniques for verifying the practicalities of edge computing in flood prediction systems and early warning system in general. Since the computation is being carried out at the edge, there is a need for techniques of monitoring the system and detecting discrepancies in its behaviours. Such techniques, if deployed on the edge, would have to be low computationally intensive to suit the low power edge devices. The third aspect is on ways for power management on the edge computing platform. This includes understanding how much power it takes to run the neural network on the Raspberry Pi compared to it’s normal operation or when sending all the sensor data over the Internet. Finally, the efficient techniques for disseminating the flood alert messages when the prediction is done at the edge, which this thesis did not focus much on.

41 References

[1] Ghapar, Azimah Abdul, Yussof, Salman, and Bakar, Asmidar Abu. “Internet of Things (IoT) architecture for flood data management”. In: International Journal of Future Generation Communication and Networking 11.1 (2018), pp. 55–62. [2] Shah, Wahidah Md, Arif, F, Shahrin, AA, and Hassan, Aslinda. “The Implementation of an IoT-Based Flood Alert System”. In: INTERNATIONAL JOURNAL OF ADVANCED COMPUTER SCIENCE AND APPLICATIONS 9.11 (2018), pp. 620–623. [3] Ward, Patrick J, Pauw, WP, Van Buuren, MW, and Marfai, Muh Aris. “Governance of flood risk management in a time of climate change: the cases of Jakarta and Rotterdam”. In: Environmental Politics 22.3 (2013), pp. 518–536. [4] Maspo, Nur-adib, Harun, Aizul Nahar, Goto, Masafumi, Nawi, Mohd Nasrun Mohd, and Haron, Nuzul Azam. “Development of Internet of Thing (IoT) Technology for flood Prediction and Early Warning System (EWS)”. In: (). [5] Brouwers, Lisa and Boman, Magnus. “A computational agent model of flood management strategies”. In: Regional Development: Concepts, Methodologies, Tools, and Applications. IGI Global, 2012, pp. 522–534. [6] Pengel, BE, Krzhizhanovskaya, VV, Melnikova, NB, Shirshov, GS, Koelewijn, AR, Pyayt, AL, Mokhov, II, et al. “Flood early warning system: sensors and internet”. In: IAHS Red Book 357 (2013), pp. 445–453. [7] Mach, Pavel and Becvar, Zdenek. “Mobile edge computing: A survey on architecture and computation offloading”. In: IEEE Communications Surveys & Tutorials 19.3 (2017), pp. 1628–1656. [8] Krueger, Richard A. Focus groups: A practical guide for applied research. Sage publications, 2014.

42 REFERENCES

[9] Vijai, Praveen and Sivakumar, P Bagavathi. “Design of IoT systems and analytics in the context of smart city initiatives in India”. In: Procedia Computer Science 92 (2016), pp. 583–588. [10] Gangopadhyay, Shreedeep and Mondal, Molay Kumar. “A wireless framework for environmental monitoring and instant response alert”. In: 2016 International Conference on Microelectronics, Computing and Communications (MicroCom). IEEE. 2016, pp. 1– 6. [11] Poslad, Stefan. Ubiquitous computing: smart devices, environments and interactions. John Wiley & Sons, 2011. [12] Siekkinen, Matti, Hiienkari, Markus, Nurminen, Jukka K, and Nieminen, Johanna. “How low energy is bluetooth low energy? comparative measurements with zigbee/802.15. 4”. In: 2012 IEEE wireless communications and networking conference workshops (WCNCW). IEEE. 2012, pp. 232–237. [13] Shi, Weisong, Cao, Jie, Zhang, Quan, Li, Youhuizi, and Xu, Lanyu. “Edge computing: Vision and challenges”. In: IEEE Internet of Things Journal 3.5 (2016), pp. 637–646. [14] Sun, Xiang and Ansari, Nirwan. “EdgeIoT: Mobile edge computing for the Internet of Things”. In: IEEE Communications Magazine 54.12 (2016), pp. 22–29. [15] Truong, Hong-Linh and Dustdar, Schahram. “Principles for engineering IoT cloud systems”. In: IEEE Cloud Computing 2.2 (2015), pp. 68–76. [16] Vesselinova, Natalia, Steinert, Rebecca, Perez-Ramirez, Daniel F, and Boman, Magnus. “Learning Combinatorial Optimization on Graphs: A Survey with Applications to Networking”. In: arXiv preprint arXiv:2005.11081 (2020). [17] Li, He, Ota, Kaoru, and Dong, Mianxiong. “Learning IoT in edge: Deep learning for the Internet of Things with edge computing”. In: IEEE network 32.1 (2018), pp. 96–101. [18] Zhao, Zhiwei, Min, Geyong, Gao, Weifeng, Wu, Yulei, Duan, Hancong, and Ni, Qiang. “Deploying edge computing nodes for large-scale IoT: A diversity aware approach”. In: IEEE Internet of Things Journal 5.5 (2018), pp. 3606–3614. [19] Dolui, Koustabh and Datta, Soumya Kanti. “Comparison of edge computing implementations: computing, cloudlet and mobile edge computing”. In: 2017 Global Internet of Things Summit (GIoTS). IEEE. 2017, pp. 1–6.

43 REFERENCES

[20] Rodriguez, Paul, Wiles, Janet, and Elman, Jeffrey L. “A recurrent neural network that learns to count”. In: Connection Science 11.1 (1999), pp. 5–40. [21] Mou, Lichao, Ghamisi, Pedram, and Zhu, Xiao Xiang. “Deep recurrent neural networks for hyperspectral image classification”. In: IEEE Transactions on Geoscience and Remote Sensing 55.7 (2017), pp. 3639–3655. [22] 1. Introduction to RNN: Accessed: 2020-05-05. url: https://www. programmersought.com/article/1483827749/. [23] Hochreiter, Sepp and Schmidhuber, Jürgen. “Long short-term memory”. In: Neural computation 9.8 (1997), pp. 1735–1780. [24] Hrnjica, Bahrudin and Bonacci, Ognjen. “Lake Level Prediction using Feed Forward and Recurrent Neural Networks”. In: Water Resources Management 33.7 (2019), pp. 2471–2484. [25] Hu, Caihong, Wu, Qiang, Li, Hui, Jian, Shengqi, Li, Nan, and Lou, Zhengzheng. “Deep learning with a long short-term memory networks approach for rainfall-runoff simulation”. In: Water 10.11 (2018), p. 1543. [26] Haykin, Simon. Neural networks: a comprehensive foundation. Prentice Hall PTR, 1994. [27] Jaikumar, Rohit, Nagendra, SM Shiva, and Sivanandan, R. “Development of NARX Based Neural Network Model for Predicting Air Quality Near Busy Urban Corridors”. In: Recent Developments and the New Direction in Soft-Computing Foundations and Applications. Springer, 2018, pp. 581–593. [28] Abbas, Ghulam, Nawaz, Menaa, and Kamran, Farrukh. “Performance comparison of NARX & RNN-LSTM neural networks for LiFePO4 battery state of charge estimation”. In: 2019 16th International Bhurban Conference on Applied Sciences and Technology (IBCAST). IEEE. 2019, pp. 463–468. [29] Satria, Dedi, Yana, Syaifuddin, Munadi, Rizal, and Syahreza, Saumi. “Design of Information Monitoring System Flood Based Internet of Things (IoT)’”. In: Proceedings of MICoMS (2017), pp. 337–342. [30] Bande, Swapnil and Shete, Virendra V. “Smart flood disaster prediction system using IoT & neural networks”. In: 2017 International Conference On Smart Technologies For Smart Nation (SmartTechCon). Ieee. 2017, pp. 189–194.

44 REFERENCES

[31] Abdullahi, Salami Ifedapo, Habaebi, Mohamed Hadi, and Abd Malik, Noreha. “Intelligent flood disaster warning on the fly: developing IoT-based management platform and using 2-class neural network to predict flood status”. In: Bulletin of Electrical Engineering and Informatics 8.2 (2019), pp. 706–717. [32] Maspo, Nur-adib, Harun, Aizul Nahar, Goto, Masafumi, Nawi, Mohd Nasrun Mohd, and Haron, Nuzul Azam. “Development of Internet of Thing (IoT) technology for flood prediction and Early Warning System (EWS)”. In: International Journal of Innovative Technology and Exploring Engineering (IJITEE) 8.4S (2018), pp. 219–228. [33] Jayashree, S, Sarika, S, Solai, AL, and Prathibha, Soma. “A novel approach for early using android and IoT”. In: 2017 2nd International Conference on Computing and Communications Technologies (ICCCT). IEEE. 2017, pp. 339–343. [34] Ruslan, Fazlina Ahmat, Samad, Abd Manan, Zain, Zainazlan Md, and Adnan, Ramli. “Flood water level modeling and prediction using NARX neural network: Case study at Kelang river”. In: 2014 IEEE 10th International Colloquium on Signal Processing and its Applications. IEEE. 2014, pp. 204–207. [35] Arduino Nano 33 BLE. Accessed: 2020-05-05. url: https : / / store.arduino.cc/arduino-nano-33-ble. [36] Buy a Raspberry Pi 3 Model B – Raspberry Pi. Accessed: 2020-05- 05. url: https://www.raspberrypi.org/products/raspberry- pi-3-model-b-plus/. [37] ThingSpeak for IoT Projects. Accessed: 2020-05-05. url: https: //thingspeak.com/. [38] Gill, Khusvinder, Yang, Shuang-Hua, Yao, Fang, and Lu, Xin. “A zigbee-based home automation system”. In: IEEE Transactions on consumer Electronics 55.2 (2009), pp. 422–430. [39] Home: Melbourne Water. Accessed: 2020-05-06. May 2020. url: https://www.melbournewater.com.au/. [40] Kotsiantis, SB, Kanellopoulos, Dimitris, and Pintelas, PE. “Data preprocessing for supervised leaning”. In: International Journal of Computer Science 1.2 (2006), pp. 111–117. [41] Mosavi, Amir, Ozturk, Pinar, and Chau, Kwok-wing. “Flood prediction using machine learning models: Literature review”. In: Water 10.11 (2018), p. 1536.

45 REFERENCES

[42] Zhang, Jianwei, Hou, Ge, Ma, Bin, and Hua, Weiwei. “Operating characteristic information extraction of flood discharge structure based on complete ensemble empirical mode decomposition with adaptive noise and permutation entropy”. In: Journal of Vibration and Control 24.22 (2018), pp. 5291–5301. [43] Badrzadeh, Honey, Sarukkalige, Ranjan, and Jayawardena, AW. “Hourly runoff forecasting for flood risk management: Application of various computational intelligence models”. In: Journal of Hydrology 529 (2015), pp. 1633–1643. [44] Saghafian, Bahram, Haghnegahdar, Amin, and Dehghani, Majid. “Effect of ENSO on annual maximum floods and volume over threshold in the southwestern region of Iran”. In: Hydrological sciences journal 62.7 (2017), pp. 1039–1049. [45] Kong, Weicong, Dong, Zhao Yang, Jia, Youwei, Hill, David J, Xu, Yan, and Zhang, Yuan. “Short-term residential load forecasting based on LSTM recurrent neural network”. In: IEEE Transactions on Smart Grid 10.1 (2017), pp. 841–851. [46] Talathi, Sachin S and Vartak, Aniket. “Improving performance of recurrent neural network with relu nonlinearity”. In: arXiv preprint arXiv:1511.03771 (2015). [47] Dahl, George E, Sainath, Tara N, and Hinton, Geoffrey E. “Improving deep neural networks for LVCSR using rectified linear units and dropout”. In: 2013 IEEE international conference on acoustics, speech and signal processing. IEEE. 2013, pp. 8609–8613. [48] Brownlee, Jason. Better Deep Learning: Train Faster, Reduce Overfitting, and Make Better Predictions. Machine Learning Mastery, 2018. [49] Kingma, Diederik P and Ba, Jimmy. “Adam: A method for stochastic optimization”. In: arXiv preprint arXiv:1412.6980 (2014). [50] Li, Mu, Zhang, Tong, Chen, Yuqiang, and Smola, Alexander J. “Efficient mini-batch training for stochastic optimization”. In: Proceedings of the 20th ACM SIGKDD international conference on Knowledge discovery and data mining. 2014, pp. 661–670. [51] Caruana, Rich, Lawrence, Steve, and Giles, C Lee. “Overfitting in neural nets: Backpropagation, conjugate gradient, and early stopping”. In: Advances in neural information processing systems. 2001, pp. 402–408.

46 REFERENCES

[52] TensorFlow Lite: ML for Mobile and Edge Devices. Accessed: 2020- 05-09. url: https://www.tensorflow.org/lite. [53] Ultrasonic Distance Sensor (HC-SR04). Accessed: 2020-05-05. url: https://www.piborg.org/sensors-1136/hc-sr04. [54] Octopus Rain/Steam Sensor. Accessed: 2020-05-05. url: https: //uk.pi-supply.com/products/octopus-rain-steam-sensor. [55] 26.6. timeit - Measure execution time of small code snippets. Accessed: 2020-05-15. url: https : / / docs . python . org / 2 / library/timeit.html.

47 Appendix A

Prototype Demo

A.1 Sensor Data Visualisation

During part of demo testing of the prototype of the proposed flood prediction system, the raw sensor data was visualised in real time using ThingSpeak platform. For the demo, the sensor data was scaled within the limits of the dataset that was used in training the model for the system, for both rainfall and water level time series. Figure A.1.1 shows rainfall sensor values uploaded to ThingSpeak for visualisation. Figure A.1.2 shows water level sensor values uploaded to ThingSpeak for visualisation.

Figure A.1.1: Rainfall sensor values uploaded to ThingSpeak for visualisation.

48 APPENDIX A. PROTOTYPE DEMO

Figure A.1.2: Water level sensor values uploaded to ThingSpeak for visualisation.

A.2 Flood Alert in the Form of ThingTweet

Figure A.2.1 shows flood alert status based on the water level forecasts computed on the edge device using the demo rainfall and water level sensor data uploaded to ThingSpeak for visualisation. Figure A.2.2 shows a flood alert sent by the flood prediction system in the form of tweetwhich is sent using ThingTweet.

Figure A.2.1: Flood alert status uploaded to ThingSpeak for visualisation,

49 APPENDIX A. PROTOTYPE DEMO

Figure A.2.2: Flood alert tweet sent over ThingTweet.

50 TRITA-EECS-EX-2020:483

www.kth.se