1 Introduction

Air pollution is a serious environmental problem that attracts worldwide attention due to its adverse effects on human health and sustainable development [1]. With the rapid development of industrialization, urbanization, and the economy, many developing countries suffer from heavy air pollution [2]. The main sources of air pollution are particulate matters (PM2.5 and PM10) and pollutant gases (O3, NO2, SO2, CO) [3]. A remarkable and constant increase in concentrations of these substances directly reduces air quality and causes the air pollution problem. It also poses a major threat to health, economy, ecology, and climate in the long run [4]. According to the World Health Organization (WHO), seven million people die every year from air pollution. These deaths are largely due to many acute and chronic health issues caused by air pollution such as strokes, heart disease, asthma, obstructive pulmonary disease, lung cancer, and respiratory infection [5]. Air pollution is divided into three categories: indoor, outdoor, and general. It means that the air pollutants can be found at home, in the workplace, and also outdoors [6]. We face increasing levels of air pollution that can be a challenging issue to solve for governments. The limits of the air pollutant gases are exceeded in many megacities that have emerged as a problem and have to be managed by authorities in urban management. To prevent air pollution in cities, many urban managers use predictive system to inform and supply the right information about air pollution to the citizens [7]. This predictive system not only provides air pollution information to citizens but also enables measurements to be made to prevent air pollution.

This information shows that air pollution is one of the major challenges for governments and decision-makers to protect human health and the environment. Therefore, it is necessary to predict the pollutant gas concentrations and keep the air quality at an appropriate level in order to take precautions against air pollution [8].

Air pollution prediction has attracted the attention of researchers for years. Traditional methods are applied to solve the air pollution prediction problem. The traditional methods use statistical and mathematical methods. However, it has some deficiencies as limited accuracy, cut-offs and complex mathematical calculations [9]. On the other hand, the conventional methods use data mining algorithms for predicting air pollutants that use regression, classification, clustering and association mining algorithms [6]. There is a huge attention to artificial intelligence by researchers that use these algorithms to predict air pollutants. AI models use artificial neural networks, support vector machines and other deep learning algorithms. Due to the limitations of these algorithms, hybrid approaches are proposed to solve the problem of air pollutant prediction. [10]. Moreover, big data analytics models are used for air pollutant prediction with better accuracy results [9].

Complex Event Processing (CEP) is a framework that is used for detecting complex events from atomic events in real time. With the help of real-time operations, CEP is capable of detecting emerging issues about the given rules from the CEP framework. The atomic events can be represented as a stream of sensors that come together to form complex events. The complex events are detected via predefined rules which are mostly defined by domain experts [11].

However, both predicting pollutant gas concentrations and evaluating prediction results are complex processes. The complexity of the process arises from the real-time processing, analysis and correlation of data streams from different gas sensors [12]. Therefore, there is a need for a sophisticated system to detect complex events in real-time data streams [13, 14]. At this point, Event-Driven Architectures (EDAs), which enable the processing of events in the data stream at the time they are received and with minimum delay, have an effective solution potential [15]. CEP system that lies under EDAs allows us to process and analyze a large number of heterogeneous data streams to detect relevant or critical situations for a particular domain. In this way, it becomes possible to extract events in real-time and evaluate their consequences. On the other hand, CEP systems lack the predictive power of machine learning and statistical data analysis methods [16]. For this reason, the CEP system alone is insufficient in developing a predictive environmental impact assessment system and early warning system that can be a solution to air pollution [17, 18].

In this context, the main motivation of this paper is to present a conceptual CEP system model for air pollution early warning system combining Deep Learning (DL) and traditional machine learning methods. In this system model, we synthesize the predictive power of DL models and the effective data and event processing power of the CEP system. Herein, we design a system structure consisting of the prediction unit, the rule engine, the CEP engine and the decision unit components. Then, we deploy the designed system in accordance with the fog computing concept. With its aforementioned innovative features, the proposed system is the first study to jointly address DL and CEP concepts in solving the air pollution problem.

The main contributions of this paper are summarized as follows

  • We propose a novel predictive CEP system (CepAIr) that detects air pollution events by predicting the future values of air pollutants real time. In CepAIr, each pollutant concentration is predicted separately, and simple/complex pollution events are determined by jointly evaluating the future concentration levels.

  • We propose LSTM, RNN, and CNN-based DL models to predict the future concentration levels of six air pollutants (PM2.5, PM10, O3, NO2, SO2, CO) in the predictive unit of the CepAIr.

  • We present a system structure that detects comprehensive future air pollution events by combining the strengths of the proposed DL models and the proposed CEP engine. The system conveys the alarm level of detected events to decision-makers in an understandable format.

The remainder of this paper is organized as follows. Section 2 briefly presents related works and background. Section 3 introduces the details of the proposed AI-powered and fog-based CEP (CepAIr) system. Section 4 presents the experimental results and performance evaluations. Finally, Sect. 5 concludes the paper.

2 Background and related works

In this subsection, we present related works, background information, and abbreviations (see Table 1) used in the paper.

2.1 Related works

In recent years, DL has drawn widespread attention in many domain-specific applications. In the literature, although many studies predict air quality based on DL and statistical methods, the issue of predictive CEP is not addressed in these studies. Therefore, in this section, we summarize current papers that examine traditional machine learning and CEP system together in different fields.

Fülöp et al. [19] propose a conceptual framework to show efficiency of the combining predictive analysis and the CEP system. The framework uses BFtree, decision tree and J48 for predictive analyses. Furthermore, the prediction performance is evaluated in terms of precision, recall, and F-measure metrics Schwegmann et al. [20] propose an architecture to combine predictive process analytics and CEP. The authors design a predictor unit that uses regression and classification algorithms. The prediction unit, which acts as an event producer, make prediction with the predictor metrics. They evaluate the architecture in terms of MSE and classification accuracy metrics. Cabanillas et al. [21] propose a framework that integrates predictive analysis with CEP in business process management. The authors employ the SVM algorithm on air flight data by integrating Esper CEP. Wang et al. [22] propose a method that uses the Bayesian network to predict future events by integrating probabilistic complex event processing components into architecture. Similarly, Wang et al.[23] propose a predictive event processing agent to send predictive complex events to decision support systems. They employ the Bayesian model to predict future events. The proposed model shows that accuracy values increase when the window size increases in the road traffic domain. Nechifor et al. [24] propose a framework that predicts the temperature of parcels in the supply chains. In the framework, the authors use time series prediction in the CEP system with a multilayer perceptron model. However, the evaluation of the prediction step is not clearly given in the paper. Christ et al.[25] present an architecture to integrate predictive analysis component within the CEP system. In this study, the predictive component feeds the CEP engine using Conditional Density Estimation algorithms. However, the prediction performance is not evaluated. Akbar et al. [12] present an architecture that performs accurate predictions in CEP system for IoT data. In this study, they combine the power of real-time and historical data processing using CEP and ML. Furthermore, they use an adaptive moving window regression algorithm called (AMWR) for prediction. The architecture provides early warnings for traffic events with high accuracy on traffic dataset. In [26], the authors employ Logistic Regression and Naive Bayes to predict the network fault in CEP-PA system. They evaluate the model in terms of prediction metrics. Xing et al. [27] propose a framework that integrates the concepts of deep learning models with complex event processing engines. Furthermore, the authors use DL to tag the primitive events which provide semantic meaning on a video stream.

Table 1 List of abbreviations

Yadav et al. [28] propose a framework to predict traffic using deep learning techniques on camera video streams. Furthermore, the framework is evaluated in terms of real-time latency and F-score metrics. The results show that multidimensional analyses are made by integrating the DL methods to CEP architecture.

Diaz et al. [29] propose an Intelligent Transportation System model based on Complex Event Processing and Colored Petri Nets (CPNs) to make decisions about traffic regulations to reduce air pollution levels in large cities. In the same context, the authors in another study [30] propose an approach, MEdit4CEP-CPN, which extends the Prioritized Colored Petri Net (PCPN) formalism to support the modeling, simulation, analysis, and both syntactic and semantic validation of complex event-based systems. The suggested approach has been validated through a case study on air quality level detection to demonstrate its benefits in the modeling, simulation, analysis, and semantic validation of complex event-based systems. Semsali et al. [31] have developed a software architecture called SAT-CEP-Monitor that supports decision-makers by performing complex event processing on remote sensing data based on satellite sensors. The architecture has been validated on several regions of Morocco and Spain based on ground station and satellite data. Brazález et al. [32] have proposed a decision support system named FUME that can provide daily recommendations based on reference air pollution standards. FUME aims to improve the decision-making process by suggesting actions for pollution sources in traffic, industrial, domestic, and agricultural areas, utilizing fuzzy logic and CEP technologies. In FUME, CEP conducts real-time analysis based on information collected from different stations and weather forecast data, providing notifications accordingly. Fuzzy logic, on the other hand, has facilitated working with linguistic variables and uncertain data by relying on the knowledge of the domain expert. In a similar study, Macia et al. [33] have proposed a methodology supporting the action plan for air pollution in cities based on Complex Event Processing (CEP) and Fuzzy Logic. Liu et al. [34] have introduced a new CEP rule auto-extraction framework named LAD, which combines a two-layer LSTM with attention mechanism and decision tree data mining approach. In this framework, the authors leverage deep learning in two phases: filtering and labeling abnormal data, and focusing on the extraction of pattern rules with high accuracy. Experimental results showed that the framework effectively extracts meaningful CEP rules, supports real-time air quality monitoring, and contributes to air pollution prediction and regulatory strategies. Yemson et al. [35] proposed a CEP framework for indoor air quality prediction based on ontologies in the semantic web domain. The proposed framework takes inputs of particulate matter, carbon dioxide, humidity and temperature and provides notification and warning for complex event and anomaly detection. In the study, a rule-based approach is used for complex event and anomaly detection.

In the existing literature, predictive CEP has found applications in various fields, but there is a noticeable gap in its exploration in the IoT environmental monitoring domain. Moreover, widespread studies are predominantly based on traditional ML models. In this context, it becomes necessary to incorporate advanced deep learning models to achieve high accuracy levels in CEP systems. In addition, the architectural and computing aspects of the proposed CEP systems are largely unaddressed. This paper aims to address these shortcomings by presenting a novel CEP system based on DL models and utilizing a fog computing approach for air pollution monitoring. This study aims to contribute to the existing body of knowledge by reducing the identified gaps in the existing literature (Table 2).

Table 2 Summary of related works

2.2 Background

In this subsection, we provide background information on the DL models used in this study.

2.2.1 Recurrent neural network (RNN)

RNN has a simple structure including input, output and hidden layers. One of the prominent achievements of RNN is its superiority in time convergence [36]. Besides, it can easily learn the temporal dependencies with its simpler structure. The RNN structure can be mathematically formulated as follows:

$$\begin{aligned} h(t)&= f_H(W_{IH} x(t)+ W_{HH} h(t-1)) \end{aligned}$$
(1)
$$\begin{aligned} y(t)&= f_O(W_{HO} h(t)) \end{aligned}$$
(2)

where x(t) is a sequence of time series data. \(f_H\) and \(f_O\) are the hidden and output unit activation functions. h(t) is defined as a hidden layer. It is computed by input x and previous hidden layer \(h(t-1)\). \(W_{IH}\), \(W_{HH}\), and \(W_{HO}\) are the weight matrices. y is an output value which is calculated by Eq. 2.

2.2.2 Long short term memory (LSTM)

LSTM is a special Recurrent Neural Network (RNN) structure that was proposed for learning long-term dependencies by Hochreiter and Schmidhuber [37]. The main innovation of the LSTM is a memory cell that preserves the state of information in a hierarchical structure [38, 39]. Furthermore, the memory blocks contain input, output, and forget gates that regulate the flow of information from cell to cell [40]. The LSTM blocks can be formulated as follows:

$$\begin{aligned} f_t&=\sigma (W_f\cdot [h_{t-1},x_t]+b_f) \end{aligned}$$
(3)
$$\begin{aligned} i_t&=\sigma (W_i\cdot [h_{t-1},x_t]+b_i) \end{aligned}$$
(4)
$$\begin{aligned} \tilde{C}_t&=\tanh (W_c\cdot [h_{t-1},x_t]+b_c) \end{aligned}$$
(5)
$$\begin{aligned} C_t&= f_t * C_{t-1} + i_t * \tilde{C}_{t} \end{aligned}$$
(6)
$$\begin{aligned} o_t&=\sigma (W_o\cdot [h_{t-1},x_t]+b_o) \end{aligned}$$
(7)
$$\begin{aligned} h_t&=o_t * \tanh C_t \end{aligned}$$
(8)

where \(x_{t}\) is input vector and \(h_{t}\) output vector. t is expressed as a time. \(\tilde{C}_t\) and \(C_t\) are the old and new cell state. \(i_{t}, f_{t}\) and \(o_{t}\) are the input, forge,t and output gates respectively, respectively. \(W_{f}, W_{i}, W_{c}, W_{o}\) are the input weights matrices, \(b_{f}, b_{i}, b_{c}, b_{o}\) are the bias vectors. \(\sigma {(\cdot )}\) is a the logistic sigmoid function, i.e \(\sigma {(x)}=\frac{\textrm{1} }{\textrm{1} + e^{-x} }\) and \(\tanh {(\cdot )}\) are the hyperbolic tangent function.

2.2.3 Convolutional neural network (CNN)

CNN is popular with image recognition and is used as a powerful technique in spatial data processing [41]. There are three types of dimensionality in CNN architecture including one, two, and three-dimensional. CNN one-dimensional is mostly used in time series data. Because the vector of the time series can be represented as one-dimensional. On the other hand, CNN two and three-dimensional are used image or video data because the image has two or three-dimensional [42]. CNN has two layers including pooling and convolutional. In the pooling layer, the input or out of the previous layer dimensions is reduced which is called subsampling. In the convolutional layer, smaller feature maps are inferred from the input data with the help of the sliding process of convolutional matrix [43, 44].

The calculation methods of the CNN are represented as follows [45].

$$\begin{aligned}&w_{out} = (W_in-F)/s+1 \end{aligned}$$
(9)
$$\begin{aligned}&w_{out} = (W_in+2*p-F)/s+1 \end{aligned}$$
(10)
$$\begin{aligned}&Sigmoid function: f(z) = 1/(1+e^{-z}) \end{aligned}$$
(11)

where \(w_{in}\) and \(w_{out}\) are input and output feature map, F is the convolution kernel size, s represents the convolution step size, and p is expressed as a the number of pixels.

2.2.4 Support vector regression (SVR)

SVR is a special type of support vector classification [46]. It is used as a regression technique in many problems[47] that the algorithm is used as predicting intervals. Furthermore, it uses statistical learning theory to minimize error [48]. The regression formula is formulated as follows [49].

$$\begin{aligned} f(x) = (W,O(x))+b \end{aligned}$$
(12)

where w and b are regression parameters, x is represented as a vector of input, O is the kernel operator.

3 Proposed AI-powered and fog-based predictive CEP system (CepAIr)

In this section, we explain our network model and formulation. Then, we present our AI-powered and Fog-based Predictive CEP system (CepAIr), the proposed DL models, and optimization parameters.

3.1 Network model and formulation

As shown in Fig 1, we consider a fog-based IoT network that consists of physical devices (pollution sensing sensors, clients, end devices, etc.), fog server and cloud servers. We assume that the sensors in the physical layer are placed in groups in different geographic regions. In network model, P is the set of n pollutant sensors for each region (R), where \(P=\left\{ p_1,p_2,.......,p_n \right\}\), \(R=\left\{ r_1,r_2,.......,r_n \right\}\). \(l_{ef}^{up}\), \(l_{fc}^{up}\) are the uplinks and \(l_{cf}^{down}\), \(l_{fe}^{down}\) are the downlinks between the layers, where e is physical device, f is fog device. We use \(D_r^{down}\) to denote the input data size that is transmitted from fog/cloud servers to the physical devices. We use \(D_r^{up}\) to denote the output data size of n pollutant sensors. In addition \(B^{up}\) and \(B^{down}\) denote the total uplink bandwidth and downlink bandwidth respectively.

Fig. 1
figure 1

Overall Network model (Left) and CepAIr Process Flow (Right)

Based on the notations above, we formulate the computational delay and transmission delays below to evaluate the performance of the CepAIr in the network model. Therefore, uplink and downlink transmission delays can be given as shown in Eqs. 13 and 14.

$$\begin{aligned} T_{l_{ef}/l_{fc}}^{up}&=\frac{D_r^{up}}{B^{up}} \end{aligned}$$
(13)
$$\begin{aligned} T_{l_{cf}/l_{fe}}^{down}&=\frac{D_r^{down}}{B^{down}} \end{aligned}$$
(14)

Thus, we can get an approximate end-to-end transmission delay (\(T_{e2e}^{trans}\)) for each packet by summing all uplink and downlink transmission delays.

$$\begin{aligned} T_{e2e}^{trans}= T_{l_{e,f}}^{up} + T_{l_{f,c}}^{up} + T_{l_{e,f}}^{down} + T_{l_{f,c}}^{down} \end{aligned}$$
(15)

Next, we model the CepAIr processing delay (\(T_{CepAIr}^{proc}\)). Herein, we assume the delay times in the prediction unit, CEP engine, and decision unit as \(T_{pu}^{pred}\), \(T_{ce}^{proc}\) and \(T_{du}^{proc}\), respectively. Specifically, the prediction delay of the prediction unit can be given by

$$\begin{aligned} T_{pu}^{pred} =\frac{D_r^{up}}{f^{cc}} \end{aligned}$$
(16)

where \(f^{cc}\)is the computing capability of fog server. Thus, we obtain the CepAIr processing delay by summing up the prediction and processing delays in all system units.

$$\begin{aligned} T_{CepAIr}^{proc}=T_{pu}^{pred} + T_{ce}^{proc} + T_{du}^{proc} \end{aligned}$$
(17)

Finally, the total network delay for N packets transmitted to the network from each region can be given as follows.

$$T_{total}^{network} = \sum _{n=1}^{N} (T_{CepAIr}^{proc} + T_{e2e}^{trans})$$

3.2 Proposed CepAIr system

In this paper, we address the air pollution problem that threatens human health as a major problem worldwide. It is known that this problem varies according to the country, city and even specific location. Therefore, potential solutions to this problem should be location-based and distributed due to the nature of the problem. Based on this information, we perform air pollution monitoring, analysis and prediction processes based on fog computing approach, which provides the opportunity to perform distributed, fast and effective. Therefore, we propose a system called CepAIr, which includes a prediction unit, a rule engine, a CEP engine, and a decision unit. Then, we explain the functions of these units and the position of the system in the IoT architecture in detail below.

Specifically, CepAIr provides an architectural concept for dealing with air pollution in smart cities using CEP. This system concept is designed according to the fog computing approach in a three-tiered IoT architecture. In the physical layer, the concentration values of ozone, particulate matter, carbon monoxide, sulfur dioxide, and nitrogen dioxide gases that cause air pollution are detected and sent to the closest fog server in the coverage area. In the fog layer, the proposed CepAIr system is distributed over fog servers. Fog servers process the incoming data and put it into the CepAIr system. CepAIr performs future prediction of local air quality by using the prediction values of each pollutant gas. Then it sends the results to the clients directly or via the cloud in interpretable form. As shown in Fig. 1, the proposed CepAIr consists of four major components, namely the prediction unit, CEP engine, rule engine, and decision unit. These components are comprehensively explained below.

  • Prediction Unit: This unit predicts future pollution concentrations for each gas using developed DL models and SVR. The models take each gas value and predict the next gas values. Then, it sends the predicted pollution values to the CEP engine. In this unit, future values of pollutant gases are predicted through the developed RNN, LSTM, CNN, and SVR models. The best algorithm is selected after evaluating by prediction performance in each other.

  • Rule Engine: The rule engine determines the class rules used in the detection of events according to the expert guides or referenced standards and sends them to the CEP engine. In our case, the rule engine creates many simple and complex rules regarding air pollution according to the US Environmental Protection Agency (EPA) reference AQI values and classes [50] shown in Fig 2.

Fig. 2
figure 2

EPA air quality index levels [50]

Based on this reference AQI values, our rule engine provides the rules for the three main health concern levels shown in Table 3. More specifically, the rule engine considers 0-50, 51-100, and 101-500 AQI values for good, moderate, and unhealthy levels, respectively. The rules as named normal, warning, and critical are deployed to the CEP engine to detect complex events.

Table 3 Used AQI levels and rule formats
  • CEP Engine: CEP engine processes and analyzes large amounts of pollutant gas data by using the rules created by rule engine to detect simple, complex, and composite events. Specifically, the CEP engine in CepAIr provides the detection of simple and complex events for future air pollution by taking the pollutant gas values predicted by DL models and predefined rules in the rule engine. Then it sends the detected events to the decision unit. To perform all these operations, we use the ESPER framework [51] that you can build CEP engine with Java coding and it can be embedded into Java applications.

  • Decision Unit: The decision unit evaluates all events and functions as an early warning system. It categorizes and labels the alarm level of all events as Normal, Warning, and Critical in advance and sends it to decision-makers in an understandable format.

To better understand the process flow of the proposed system and the functions of the units given above, we present the whole process flow of DeepFog CEP step by step in Algorithm 1. To explain in detail, the first step is collecting data from sources. In particular, the data is air pollution data which can be deployed in different areas in the urban area. After the data collection step, the pollutant gases next point is predicted via the selected best algorithm comparison to each other. The next step is expressed as getting rules from Rule Engines which is defined as taking care of the level of health concern. Next, The CEP engine detects the complex events via predefined rules and sends the complex events to the decision unit. Lastly, Future alarm levels are determined and sent to the decision-makers to take precautions or inform to the citizens in smart cities.

Algorithm 1
figure a

CepAIr process flow

3.3 Proposed DL models, optimization and parameters

We tuned the all used models with different parameters to get more accurate results. Numerous experiments are conducted to get the best prediction performance. In deep learning algorithms, we adopt many to one strategy to predict the ozone, particulate matter, sulfur dioxide, and nitrogen dioxide. The model takes sensor values as inputs and predicts the next sensor value. We have tested the RNN and LSTM models under different numbers of layers as 1,2,3 and hidden units as 128, 256, and 512. We have also tested different numbers of epochs sizes as 50, 100, 200, 300, 400, 500. We adopt the dropout regularization technique to strengthen the prediction accuracy of the models. In CNN, we have tested different numbers of filters as 128, 256, and 512, and different numbers of epochs size as 50, 100, 200, 300, 400, 500. Similarly, SVR takes each sensor’s values to predict the next value. We adopt the grid search technique to find the optimum hyper-parameters. Therefore, the hyper-parameters which are shown in Table 4 are obtained from numerous experiments to build the best structure.

Table 4 Model hyper-parameters

In the prediction unit, we used the TensorFlow [52], Keras framework [53], and Sklearn [54] to implement all algorithms. In the CEP engine, We use the eclipse platform to use ESPER CEP library [55] which is written in Java. Thanks to these frameworks, the models are trained offline on a desktop computer equipped with an Intel i7-7700HQ CPU, 16-GB RAM, and GTX 1060TI GPU with 6 GB RAM.

4 Experimental results

4.1 Dataset

In this study, we use the air pollution gases collected in the City Pulse EU FP7 Project [56]. The dataset consists of eight features including nitrogen dioxide, ozone, particulate matter, sulfur dioxide, carbon monoxide, longitude, latitude, and timestamp [57]. Furthermore, the data stream of each gas is continuous and timely annotated and collected at five-minute intervals for 60 days. Table 5 presents the descriptive statistics of the polluted gases.

Table 5 Statistical description of the Dataset

Additionally, some information on the pollutant gases used in this data set and their effects on human health are presented below [58].

4.1.1 Ozone (O\(_3\))

O\(_3\) is a pollutant that increases as a result of chemical reactions between sunlight, nitrogen oxides from vehicle emissions and volatile organic compounds. High ozone levels can irritate the respiratory tract, increase asthma symptoms, adversely affect lung function, affect the cardiovascular system and contribute to general health problems.

4.1.2 Particule matter (PM)

PM consists mainly of primary pollutants from smokestacks, construction sites, fires, or volcanoes and secondary pollutants from power plants, factories, and vehicles. PM is respirable and can accumulate in the lungs, blocking the airways, increasing respiratory problems and increasing the risk of heart disease.

4.1.3 Carbon monoxide(CO)

CO is an odorless, invisible gas produced by incomplete combustion. The most important sources of this gas are automobile emissions, fires, and industrial processes. Exposure to carbon monoxide in high concentrations and for long periods can lead to serious health problems such as chest pain, vision problems, and reduced physical and mental abilities.

4.1.4 Sulfur dioxide(SO\(_2\))

SO\(_2\) is a colorless pollutant gas with a suffocating odor emitted from sources such as electricity generation, fossil fuel combustion, industrial processes, and automobile emissions. In terms of health effects, SO\(_2\) can cause inflammation in the respiratory tract, increasing respiratory problems and damaging the cardiovascular system.

4.1.5 Nitrogen dioxide(NO\(_2\))

NO\(_2\) is a pungent and irritating pollutant gas that is produced by automobile emissions, electricity generation and industrial processes. Prolonged exposure to NO\(_2\) can cause respiratory symptoms (such as coughing, wheezing or difficulty breathing).

4.2 Performance evaluation of the prediction models

In the prediction unit, we employ four algorithms including SVR, LSTM, RNN, and CNN. We evaluate these prediction models that were developed for use in the prediction unit in terms of mean square error(MSE), root mean square error (RMSE), mean absolute error (MAE), mean absolute percentage error (MAPE), and R-squared (\(R^2\)) metrics[59]. The mathematical formulas for the evaluation metrics are given The mathematical formulations of RMSE and MAE metrics are given in Eqs. 1822.

$$\begin{aligned} MSE&= \frac{1}{n} \sum _{i=1}^{n} (y_i - \hat{y}_i)^2 \end{aligned}$$
(18)
$$\begin{aligned} RMSE&= \sqrt{\frac{1}{n} \sum _{i=1}^{n} (y_i - \hat{y}_i)^2} \end{aligned}$$
(19)
$$\begin{aligned} MAE&= \frac{1}{n} \sum _{i=1}^{n} |y_i - \hat{y}_i| \end{aligned}$$
(20)
$$\begin{aligned} MAPE&= \frac{1}{n} \sum _{i=1}^{n} \left| \frac{y_i - \hat{y}_i}{y_i} \right| \times 100 \end{aligned}$$
(21)
$$\begin{aligned} R^2&= 1 - \frac{\sum _{i=1}^{n} (y_i - \hat{y}_i)^2}{\sum _{i=1}^{n} (y_i - \bar{y})^2} \end{aligned}$$
(22)

In these equations, n represents the number of data points, \(y_i\) represents the true value, and \(\hat{y}_i\) represents the predicted value. The overall average results of the prediction performance are presented in Table 6.

Table 6 Performance comparisons of the prediction models

The prediction results of the NO\(_2\), CNN is slightly better than the LSTM, RNN models. On the other hand, SVR in test evaluation shows worse prediction performance in comparison to the other models. According to the O\(_3\) prediction results, CNN, LSTM, and RNN models show similar prediction results when evaluating R\(^2\). The other RMSE, MAE, and MAPE metrics results show the CNN performed better in predicting in compare to the other models. When we evaluate the PM prediction results, it is observed that CNN gives better results, when we evaluate all metrics. The SVR model showed lower prediction performance compared to other models. When we consider to the SO\(_2\) prediction results, CNN outperforms the other models. But, RNN and LSTM models show very close performance in the prediction results. On the other hand, SVR model shows the worst performance in comparison to the other models. Lastly, when evaluating CO prediction results in terms of all metrics given in Table, CNN performs better, followed by LSTM, RNN and SVR models.

As seen in Table, the most successful models in terms of all evaluation metrics are CNN, LSTM, RNN, and SVR, respectively. Here, it is seen that CNN models stand out significantly from the other models. This is because CNN can create higher-level representations of sequence data and capture spatial feature dimensions. Based on these results, we use the predicted data obtained by CNN algorithms for detecting future complex events in the CEP engine.

4.3 Classification results of the prediction models for each pollutant gas

In this subsection, we present the classification results of alarm levels in terms of prediction metrics according to the prediction results of the prediction unit. Thus, we demonstrate the success of the decisions made regarding air pollution in the decision unit. The comparative classification results for all gases are presented in Tables 7, 8, 9, 10 and 11. From the comparison of all algorithms in Table 7, we can see that CNN outperforms the other algorithms in comparison to all rule types.

According to Table 7, these scoresshown that CNN-based model outputs have a very good performance in detecting complex events for all rule types as normal, warning, and critical. Then, LSTM, RNN, and SVR models follow the CNN model in order of success.

According to Table 8, experimental results reveal that the CNN algorithm shows above 90% classification performance, except normal rule types, in terms of F1-score and accuracy metrics. However, the SVR algorithm shows underperformance when compared to the other algorithms.

Next, we give the results of the particulate matter gases in Table 9, according to this table, it is seen that all algorithms achieve more than 90% classification performance for critical rule types. However, the CNN model performed better for normal and warning rule types. This result shows that the predicted values of the CNN model achieve a higher classification result in the CEP engine.

Table 7 The classification results of the nitrogen dioxide (NO2)
Table 8 The classification results of the ozone (O3)
Table 9 The classification results of the particulate matter (PM)
Table 10 The classification results of the sulfur dioxide (SO2)
Table 11 The classification results of the carbon monoxide (CO)

According to Table 10, all algorithms show above 94% classification performance for critical rule types. However, all algorithms show below 70% classification performance for normal and warning rule types. But CNN slightly outperforms the other algorithms for warning rule types.

We evaluate Table 11, CNN shows above 89% classification performance for warning and critical rules in the CEP engine. It is seen that the normal rule-type outputs are not as good as the others. But CNN outperforms the other algorithms in terms of F-score and accuracy metrics. We can clearly infer that the prediction output of the CNN shows great performance in the CEP engine of the models to detect complex events with given rules. The CNN model obtains more accurate results than other models in complex event detection according to the three rule types considered for all pollutant gases. To compare more clearly the obtained results, we present the average F1-scores of all pollutant gases in Fig. 3.

Fig. 3
figure 3

Average F1-Score of all models

4.4 Computational complexity evaluation of the CepAIr

The computational complexity of the CepAIr can be summarized by the cost of the prediction unit and CEP engine unit. In the prediction unit, different types of ML are used. In this step, the complexity of the ML changes according to the selected algorithm. The parameters of the model affect the cost of the selected algorithms. Therefore, we assume the worst case complexity which is defined as \(O(n^2+m*n)\) per execution for prediction step [37, 60]. In the complexity of the model, n is defined as the number of input samples, and m is defined as the number of input neurons/unit number of the hidden layer. In the CEP engine, detecting complex events takes O(n) times which can be seen in Algorithm 1. Consequently, the total computational cost of the model can be expressed as \(O(n^2+m*n+n)\).

4.5 End-to-end network delay performance of CepAIr

In this subsection, we evaluate the end-to-end delay performance of the proposed CepAIr on a real-time system based on our previous study [61]. Therefore, we use three widely used network metrics in literature: i) the transmission delay, ii) the CepAIr processing delay and iii) the end-to-end total network delay. At this point, we use the transmission delay times of our previous study to theoretically demonstrate the performance of the CepAIr system on the network. We then measure the processing time of the CepAIr separately according to all models and combine it with the transmission delays in our previous study. Thus, we theoretically obtain the network performance of the proposed system as shown in Table 12. In addition, we give all results according to 95% confidence interval to ensure the statistical soundness of the obtained results.

Table 12 End-to-end network delay comparison (ms)

From Table 12, we see that the average processing delay at each time step t of the proposed CepAIr is measured approximately as 2.8, 4.3, 2.9, and 1.7 ms for the CNN, LSTM, RNN, and SVR models, respectively. At this point, the SVR revealed the least processing delay as it is able to predict without depending on previous data dependencies. When considering the processing delays of CepAIr together with the transmission delays in [61], it can be seen that running CepAIr with LSTM and RNN models caused relatively less network delay. However, when CepAIr is run with CNN and SVR, it reveals higher total network delay compared to LSTM and RNN algorithms. To express in numbers, the total delay times of the network according to the LSTM, RNN, CNN and SVR models are measured as approximately 270, 267, 2,71 and 271 ms, respectively. Based on overall results, the proposed system increased the average network delay by only 1.1%.

5 Conclusion

In this paper, we propose a new fog-based predictive CEP system (CepAIr) that can be a solution to air pollution. The predictive system enables us to inform citizens in urban and rural areas. CepAIr aims to allow decision-makers to take proactive actions by predicting pollutant gas concentrations that cause air pollution. The placement and applicability of CepAIr is illustrated over the three-tiered IoT network model. CepAIr is tested separately in experiments with CNN LSTM, RNN, and SVR models, and the air pollution prediction success and network performance of the CepAIr are separately evaluated. The models takes each pollutant gas and predicts the next pollutant gas level. The experimental results showed that the CNN model has the highest prediction success among the prediction models used in the system. The CEP engine detects the complex events with a boost of prediction unit and sends to alarm label to the decision-makers. On the other hand, when CepAIr’s performance on the network is examined in terms of delay, it is seen that it adds only 1.1% additional load to the total network delay. Considering the success of the proposed system in air pollution prediction, the delay rate is considered to be tolerable. As a result, the proposed CepAIr offers a powerful alternative to decision-makers to solve the air pollution problem.