Mining sensor data in a smart environment: a study of control algorithms and microgrid testbed for temporal forecasting and patterns of failure

The generation of active power in renewable energy is dependent on several factors. These variables are related to the areas of weather, physical structure, control, and load behavior. Estimating the future value of the active power to be generated is difficult due to their unpredictable character. However, because of the higher precision required of the estimation, this problem becomes more complex if we examine a short-term temporal prediction. This study presents a method for converting stochastic behavior into a stable pattern, which can subsequently be used in a short-term estimator. For this conversion, K-means clustering is employed, followed by Long-Short-Term Memory (LSTM) and Gated Recurrent Unit (GRU) algorithms to perform the Short-term estimate. The environment, the operation, and the generated (normal or faulty) signal are all simulated using mathematical models. Weather parameters and load samples have been collected as part of a dataset. Monte-Carlo simulation using MATLAB programming has been realized to conduct an experiment. In addition, the LSTM and the GRU are compared to see how well they perform in this system. The proposed method's end findings outperform the current state-of-the-art.


Introduction
A smart grid is an electricity network enabling a two-way flow of electricity and data with digital communications technology. This gives the ability of monitoring, managing, and automatic decision-making. Besides, smart grid uses a wide range of resources based on information technology techniques to enable new and existing guidelines in minimizing energy costs and reducing electricity wastes. According to Ali et al. (2013), the smart grid is one of the most complicated and largest systems considering the design and building processes, although it is one of the easiest to use. It uses all kinds of power plants (including hydro, solar, coal, nuclear, wind turbine, and natural gas, among others), substations, transformers, and high-voltage transmission lines (Hasan et al. 2019), therefore, there is the need for a demand-responsive electrical grid with high efficiency of energy use. The traditional grid uses a oneway limited interaction, in which power flows to the consumers from the power plant. In contrast, the smart grid introduces a two-way interchange in which involve the exchange both information and electricity, in both directions (between consumer and power utilities). The growing network of computers, automation, control, and communications are instrumental in making the grid ''greener'', more reliable, more secure and more efficient (Hasan et al. 2019).
These grids could provide a rich dataset that could be used for analyzing and monitoring their activities, but these could also be used to provide an opportunity to use this data in different applications as well, such as using them for sensor data (Jakkula and Cook 2007).
This data could be useful when being set to work with different aspects or dimensions of SmartGrid such as integration with renewable energy sources, management of intermittent power supplies, real-time data responses as well as the energy pricing strategies among others (Jakkula and Cook 2007). As such, it becomes a necessity that we would develop the right tools and methods which could help in conserving the energy by gathering the data from the smart grid using sensors which could then be used to recognize patterns from previous data and forecast or predict in order to conserve energy in the smart grids.
Some of the algorithm that could be used for prediction which are related to deep learning algorithms like Longshort term memory (LSTM), Recurrent Neural Network (RNN), Gated Recurrent Unit (GRU). In this work, the used predictor is the most efficient one of them, in terms of accuracy and delay.
LSTM is an RNN variant that is meant specifically for time series data. The LSTM is used in addressing this problem in addition to empowering RNNs algorithms using internal memory cells .
RNNs are a form of neural networks that adopt the feedback connections in various nodes in remembering the previous time steps values. As such, they can capture the time series data's temporal behaviour. (Tealab 2018).
GRU is a kind of gated RNN which is largely used in mitigating the gradient vanishing problem of RNNs using gating mechanism in addition to making the structure simpler without interfering with the effect of LSTM neural network (Luo et al. 2021).
GRU addresses the vanishing gradient problem, which are the values used in updating network weights. According to (Agarap 2018), GRU can solve this problem using two gates, the rest gate and the update gate. The gates are instrumental in deciding the information that is allowed to pass to the output in addition to having the ability to be trained for retaining information from farther back, thus allowing it to pass relevant information through a variety of events for making better predictions.
However, since these prediction methods are based on regression techniques, which tries to find a common pattern for the historical samples to use it to predict the future values. Considering our application, the historical samples from the energy generators and also the load of the smart city, may not have a constant pattern. This is due to the stochasticity behavior of the environment. Therefore, in order to convert this dynamicity to a static pattern, in this work, K-Means clustering algorithm is used.
K-means clustering algorithm refers to a simple unsupervised learning algorithm used in solving clustering problems which is useful in clustering analysis. According to (Xu et al. 2020), the algorithm is applied using certain procedures that classify a certain set of data into clusters defined by the letter ''K.' ' Although several works have tackled the problem of the prediction in the SmartGrid context, most of these works focus only on the long-term prediction. The advantage of the long-term prediction is in bringing long-term strategy and planning, However, the methods that are currently used for this task provides in accurate predictions. On the other hands, short and very shorts terms predictions are important for the real-time control of the SmartGrid which requires real-time information from the real load and the natural resources in addition to the physical structure of the solar panels. Moreover, providing an accurate short-term prediction for the generated energy is also a challenging problem. This is due to the fact, that the amount of generated energy depends on several parameters, from the physical components of the unit to the weather conditions. All these parameters are totally stochastic and do not follow any accurate pattern.
Our methodology in this work is to convert the stochastic behavior of the attributes into an accurate pattern using a clustering algorithm (i.e., K-Means). This allows us to be able to identify their fitting curve and use a suitable regression-based algorithm (i.e., LSTM and GRU) for an accurate short-term prediction.
The main objective of this work is to propose a method that allows enhancing the accuracy of the short-term generated power prediction for the SmartGrid environment.
The main contributions to the existing body of knowledge that this study will make include: 1. Identify the most useful factors that affects the accuracy of the Smart Grid short term prediction process. 2. Implement a model (or a combination of already existing models) for recognizing patterns of failure in the Smart Grid. 3. Identification of the best deep learning algorithm to mine data from a synthetic testbed. 4. Proposing a solution to provide a comparatively enhanced prediction results using unpattern-able (highly dynamic and stochastic) data. 5. Providing a solution that enhances the protection level for smart grid dynamic environment against failures. 6. Providing an accurate future value for the short-term prediction in a relatively faster processing time.

Literature review
Efficient delivery of energy resources to the smart grid requires a balanced energy demand and supply by developing energy resource management strategies. However, the significant fluctuations in energy demand and supply enhance the challenges in the development of these energy resource management schemes. This problem has been tackled using different approaches.
For instance, this work (Yu et al. 2015) developed several approaches to predict energy supply and demand effectively. The study then develops machine learningbased methods for accurate energy consumption and generation forecasts. Lastly, the study used the prediction results to establish energy consumption upper and lower bounds realizing optimal demand and anomaly detections.
The problem is the smart meters acquire large amounts of data through sophisticated signal processing algorithms. The methodology will be applied in the study for it will the first develops a new classification scheme that categorizes users based on their consumption patterns. The study will then test the proposed and benchmarked models. Additionally, this research uses semi-Markov models to generate more extensive and more realistic test data due to insufficient power consumption data. (Tornai et al. 2016).
The problem is electrical load prediction is a fundamental factor in the planning, operations, and resource management within the grid system. The numerous restructurings of the grid and the integration of new devices to the grid heighten the need for forecasting to better plan for energy supply and demand. The methodology will be applied in the study for it will the first proposes a prediction model capable of predicting load data. Additionally, the study assesses the prediction model's performance and effectiveness against several metrics. (Chemetova et al. 2017).
The problem is difficulty in harvesting various renewable energy forms led to the use of the smart grids integrated with photovoltaic (PV) power. However, various atmospheric conditions, for instance, rain, affect solar irradiance occurrence. This solution proposes the adoption of wavelet transform and Elman Neural Network (WT-ENN) for short-term solar energy production and irradiance forecasting. The methodology, the first decomposed the original solar irradiance data into consecutive stable wavelet sub-series. Additionally, the study used ENN to optimize the new wavelet coefficients. Lastly, the study reconstructed solar irradiance using the prediction model and the new coefficients. The prediction model's performance was then assessed using two real-world data solar irradiance datasets. (Huang et al. 2019).
The problem is Smart grid systems allow consumers to use more energy from the grid or vend it back to the grid for other consumers. Smart homes with photovoltaic systems can establish the daily energy yield. This solution recommends the use of multi-layer perceptron based on photovoltaic forecasting on rooftop PV systems. The methodology will be applied, the first suggests the use of multi-layer perceptron-based PV forecasting. The study then trains its historical data, conducts cross-validation, and tests the model using real-world PV data. (Parvez et al. 2020).
The problem is emergence of smart grids offers better integration of power systems between energy producers and consumers. The bidirectional nature of these smart grids calls energy consumption optimization measures to maintain the grid's reliability and supply-demand balance. The solution evaluates the available short-term energy consumption prediction models to determine next-day energy consumption forecasts at one-hour intervals realizing a 24-point forecast. This methodology conducted a thorough assessment of various high-level machine algorithms adopted to forecast and evaluate the various model instances to determine the most appropriate algorithm for energy consumption forecasting. (Petrican et al. 2018).
The problem is Efficient energy delivery in the smart grid requires adopting energy resource management strategies that balance energy supply and demand. This solution proposes several techniques that accurately model and predict energy production and demand over time. Similarly, the study recommends modeling analyses that statistical output models of energy consumption and machine learning approaches improve prediction accuracy. The methodology, the first the statistical distribution of real-world meter reading data of several houses for over 200 days acquired from Stanford University. (Yu et al. 2014).
The problem is several countries continue to record an increase in their solar power capacity connections to the distribution grids. Adopting the smart grid concept has since contributed to this increase. The solution study suggests a new forecasting model that uses autoregressive models and gradient boosting algorithms. Such promote the alleviation of these constraints and result in point and probabilistic solar power forecasts for medium voltage and low voltage distribution stations. The methodology, the first proposes a model that overcomes the information and communication technology (ICT) limitations to promote solar energy forecasts at secondary substation levels. It then combined the values obtained from various distributed sensors. (Bessa 2014).
The problem is various new technology appliances that consumers currently use in their households overwhelm the existing smart grid infrastructure as they were initially not developed to support these devices. This solution proposes the implementation of various methods energy providers can improve their energy consumption forecasts for households despite their variability in electrical appliance usage. The methodology, the first assesses the existing prediction models ad their significance. It then describes various modeling techniques that assess the existing statistical approaches and machine learning algorithms. (Lauer et al. 2019).

Analytical analysis
To realizes our proposed solution, we need first to identify the environment model, which in this case includes a photovoltaic grid. Then the process of generating the energy depending on the physical structure and the weather conditions in addition to the generated signal need to be modelled and then simulated. After this, the generated data are clustered using the K-means clustering algorithm. Finally, LSTM and GRU are used to provide the short-term predictions.

Environment and PV model
The earth rotates around the sun approximately 8766 h about 365.242 days. Earth is closest to the Sun (147 million km) on January 2, and this point is called perihelion.
Specific point on earth aligned with sun position. It's determined by two angels; they are altitude angle (a) and azimuth angle h s The altitude angle is the angular height of the Sun is measured from the horizontal. The altitude angle can be given by: where, L: attitude of the location d: Angle of declination x: Hour angle. The declination angle is between Earth Sun vector and equatorial plane its calculated degree, arguments to trig function noted in radian mode.

ð2Þ
Noted hour angel x is the angular displacement of the sun local point is given by: AST the true daily motion of solar time is given by a daily apparent solar motion of true observed sun. AST is constructed on the actual solar day. The two interval falls between two consecutive returns of local meridian and the sun. Solar time is illustrious as, The LSTM is a reference meridian used for a particular time zone, used for Greenwich Mean Time.
LSTM is given by: The E 0 T is the difference between apparent and mean solar times, both taken at a given longitude at the same real instant of time.
E 0 T is given by: where, B can be given by; where, N: Day number defined as the number of days elapsed in a given year up to a particular date.
Angular displacement of the Sun reference line from the source axis. The azimuth angle can be given by: The solar source model is to estimate the emitted radiation from the Sun. The function of the temperature is described as radiant energy of emitting objects.
We associate radiating energy to the blackbody. A blackbody is defined as a perfect absorber and emitter. A perfect absorber can absorb all of the received energy with any reflections.
Planck's law describes the wavelengths emitted by a blackbody at a specific temperature as follows: E k : Total emissive per unit area of blackbody emission rate (W/m2 lm) T: Absolute temperature of the blackbody (K) k: Wavelength (lm). Solar radiation value outside the atmosphere varies as the Earth orbits the Sun. Therefore, the distance between the Sun and the Earth must be considered in modeling the extraterrestrial solar radiation. Thus, the (G ex ) is given by: where. G ex : Extraterrestrial solar radiation. G 0 : Solar constant R av : Mean distance between the Sun and the Earth R: Instantaneous distance between the Sun and the Earth depends on the day of the year or day number.
There are different approximations for the factor (R av =RÞ in the literature. A recommended approximation can be given by: By substituting Eqs. (11, 10) The extraterrestrial solar radiation unit of time falling at a right on square meter of a surface can be given by: Once the surface faces the Sun (normal to a central ray), the solar irradiance falling on, is G ex , utilizes maximum solar radiation at that distance. If the surface is not normal to the Sun, the solar radiation drops on it will be decrease by cosine of the angle between the surface normal and a central ray from the Sun.
Thus, the extraterrestrial solar radiation on a horizontal surface located in a specific location (G exH ) can be calculated by: where. u: Solar zenith angle. The solar zenith angle value is equal to the altitude value, and thus Eq. (13) can be rewritten as follows: Finally, the total extraterrestrial solar energy E ex (Wh/ m2) is calculated as follows: There are several components of a solar radiation on a tilted surface are in addition to the direct (G B:b Þ and diffuse (G D:b ) solar radiation, reflected solar radiation (G R Þ is added to form the global solar radiation incident on a tilted surface.
The solar energy components on a horizontal surface as follows: where, RB, RD, and R R :are coefficients. q: Ground Aledo. R B : Ratio between global solar energy on a horizontal surface and global solar energy on a tilted surface. R D : Ratio between diffuse solar energy on a horizontal surface and diffuse solar energy on a tilted surface, R R : Factor of reflected solar energy on a tilted surface. The finding of solar energy components on a tilted surface is to estimate the coefficients R B ,R D , and R R . Used model for calculating R B is the Liu and Jordan model [Liu, B.Y. and Jordan, R.C., 1963] The surfaces in the southern hemisphere, the slope toward the equator R B is given as: The most recommended formula R R is: R D Have been classified into isotropic and anisotropic models.
Isotropic radiation has the same intensity regardless of the direction of measurement. Isotropic radiator is a uniform radiation from given point.
Model used of the Liu and Jordan an isotropic diffuse with R D been expressed: The behavior of isotropy and anisotropy radiation. Isotropy indicates identical properties in all direction moreover measure aligned different axes of materials physical property (absorbance, refractive index, density). On the other hands Anisotropy model is based on anisotropic radiation measurements varies in direction because of radiates nonuniformly in all direction. Anisotropic moles are noted R D : The circuit of a solar cell is a current source connected in parallel with a diode as shown in Figure. The output of the current source is directly related to the light emitted on the cell. Nor current or voltages are produced during darkness of solar cell. During light falls over solar cell it generates diode current Fig. 1.
The diode, D, determines the I-V characteristics of the cell. A series resistance, R s , while the shunt resistance, R SH Assumed that R s = 0 and R SH = infinity. The net current of the cell is the difference between the photocurrent, I L , and the normal diode current is: The photocurrent, I L , depends on reference first and second temperatures, T 1 and T 2 , respectively, illustrated by: where, where, G: Present solar radiation G nom : Solar radiation at the reference test. The saturation current of the diode, I 0 , is given by: where, The series resistance of a solar cell is given by: where,

Operations modelling
A typical V-I characteristic of a solar cell at a certain ambient irradiation, G, and fixed cell temperature. For a resistive load, the load characteristic is a straight line with slope I/V = 1/R.
If the load is small, the cell operates in the regions M-N of the curve; cell behaves as a constant current source that is almost equal to the short circuit current. When we have high load, the cell function in the P-S zone of the curve and the cell behaves as a constant voltage source that is almost equal to the open circuit voltage.
The short circuit current, I sc , is the greatest value of current generated by a solar cell. When V = 0 the short circuit condition produced. When the photocurrent is zero, the open circuit voltage corresponds to the voltage drop across the diode. It reflects the voltage of the cell at no light conditions, and it can be expressed as: where (V t ¼ mkT c =q): is known as the thermal voltage. T: absolute cell temperature. Cells are connected together in series to increase the voltage. Several of these series strings of cells may be connected together in parallel to increase the current as well. This package is called as a PV module or PV panel.
The relations between a PV module panel, the cell's voltage (V c ) and current (I c ) and the module's voltage (V m ) and current (I m ) are given by the following equations: where, N sM : Number of series cells. N pM : Number of parallel cells. R sM : Equivalent series resistance of the PV module. Most PV manufacturers provide temperature elements for their crystalline PV modules based on the NOCT as the cell temperature (T c ), which has a standard equation of where, T c : Cell temperature. T a : Ambient temperature. G: Instant solar radiation.
NOCT: nominal operating cell temperature is defined as the temperature reached by the open circuit cells in a photovoltaic module under conditions of 800 W/m2 irradiance on the cell surface, 20°C air temperature, and 1 m/s wind velocity.
As mentioned in Eq. (28), the characteristic of a PV cell is expressed by its relationship between current and voltage (I-V) and power and voltage (P-V) at specific solar radiation and temperature levels. Assuming the R p in Eq. (27) is too large, and then the I-V a solar cell expressed as: In addition to that, in order to simplify the characterization of a solar cell, assume that Based on this, Eq. (27) can be rewritten as follows: Solving Equation for V results: The light-generated current, I ph , is linearly proportional to the global solar radiation and is also logarithmically dependent on the operating temperature of cell, T c . Therefore, I ph can be expressed: Finally, the diode saturation current depends on the operating temperature of cell T c : as follows: Four statistic errors are used, which are.
The general accuracy of a neural network can be highlighted by MAPE. MAPE can be defined as follows: where, M: Measured data. P: Predicted data. The information of long-term performance of the neural network model can also be evaluated by MBE. MBE can be calculated as follows: The mean absolute error ðMAEÞ: is a measure of errors between paired observations expressing the same phenomenon. Examples of Y versus X include comparisons of predicted versus observed, subsequent time versus initial time, and one technique of measurement versus an alternative technique of measurement. MAE is calculated as: where, y i : Prediction x i : True value n: Total number of data points The final statistic error is RMSE; it represents the measurement of the variation of the predicted data around the measured data.
The short-term performance information of the model can be evaluated by RMSE:

Fault modelling
Photovoltaics (PV) component/module, which involves solar cells connected in series. The equation below illustrates the PV voltage as well as current features.
whereby voltage of the PV is denotated by V while the photovoltaics current (output) is denotated by I. Therefore, V ¼ N cell V cell ;N cell as well asI ¼ I cell ; this refers to the solar cell's quantity connected in series. The produced PVphotocurrent is represented byIPH:I PH ¼ I PH ; cellI 0 ;. Also, the thermal voltage is represented by V t ¼ N cell KT q whereas the diode's reverse saturated I is represented by I 0 ¼ I 0 ; cellV t : The parallel as well as series equal or correspondent resistance(s) is denoted by R sh as well as R s ; respetcively : R s ¼ N cell R s;cell Whereas R sh ¼ N cell R sh;cell (Villalva et al. 2009).

Strategy used to identify faults
This study focuses on detecting photovoltaics system's faults, which are associated with the degraded photovoltaics array and photovoltaics array's partial shading, short circuits, as well as open circuits. Silvestre et al. (2014) formulate Eqs. (55, 56) for defining the photovoltaics system's indicators of current and voltage, as well as describing it using defect feature quantity. The Eqs. (55, 56) are shown below: where R V À voltageindcator, whereasR I À indicatorofcurrent=I in a photovoltaics module. Similarly, I-is current and V-is voltage of the photovoltaics module in its maximum power point. The photovoltaics array's shortcircuit current is-I sc whereas the voltage open-circuit is represented as V oc : According to (Silvestre et al. 2014), Eqs. 57 and 58 below represents theV oc ,I sc In which: N s -refers to the number of the photovoltaic modules of a photovoltaic string N P -refer to the number of the photovoltaic array's photovoltaic string V t -implies the photovoltaics's thermal voltage.
whereby at normal testing conditions: R s : Photovoltaics component's series equal resistance. I mm STC : The current at the maximum power point of the photovoltaics module at Standard Test Conditions.

A. Open-circuit fault
Yahyaoui and Segatto (2017) stated that the faulty string's I tend to be equivalent with the photovoltaics array's output current's decreased percentage, which usually occurs whenever there is a faulty open circuit. Therefore, the I-indicators in this condition is represented in Eq. 63 below: where R IO -refers to the current indicator when there's an existence of an open circuit fault in a photovoltaics array where a tend to be: Therefore, the fault detection threshold of open circuit faults is be defined by Eq. 65 (Yahyaoui and Segatto 2017).
T IO -refers to an open circuit fault's threshold. Silvestre et al. (2014) argued that T IO Value should be above the R I À value (see Eq. 56), particularly if one or more the photovoltaics strings given has an open circuit fault.
B) Short-Circuits fault Likewise, if there is an occurrence of short-circuit photovoltaics module in any photovoltaic strings, the shortcircuit voltage of the photovoltaics module is equal to the decreased portion of the output voltage of the photovoltaics array. Therefore, the following equation (Eq. 66) is used to calculate voltage indicator Yahyaoui and Segatto (2017).
where: R VS -refers to an indicator of voltage in presence of a short-circuit in the photovoltaics occurring within photovoltaics string(s). Equation 67 show b, illustrated below: Therefore, the fault detection threshold of short-circuit faults are be defined by (Yahyaoui and Segatto 2017).
R V À value (Provided in Eq. 55) should be lower than T VS values.
T VS -refers to short-circuit fault's threshold whenever one/more photovoltaic module string offered with a short circuit fault.
C) Partial shading fault Partly shading of photovoltaics array causes drastic decrease in the current output since part of the array receives solar irradiation. Therefore, Eqs. 69 and 70 below are used to calculate the indicators of current and voltage in an event of partly or incomplete shading where: I mp refers to a photovoltaics array's current output at a maximum power point V mp refers to a photovoltaics array's voltage output maximum power point R IP refers to fractional shading fault's the indicators of current R VP refers to partly shading fault's the indicators of voltage Equation 71 and 72 are used to calculate photovoltaics array's I mp aswellasV mp whenever there is a partly shading, where the photovoltaics array receives maximum irradiance in unshaded side.
where G P -gets photovoltaics optimum irradiance in partial-shading states. Thus, Eq. 73 below is instrumental in detecting and identifying the threshold of faults during a partly-shading.
where T IP -refers to the partial-shading fault's thresholds.
T IP values should be higher than the R I Values (provided in Eq. 56) whenever all or partial shaded for the photovoltaics array.
where T IP is the threshold of partial shading faults, and when partial or all shaded for the PV array, the value of R I (given as Eq. (56) must be below the value of T IP Table 1.

Problem definition and proposed Model
Having identified the models for the environment, the operation, and the generated signals, now the problem of the accurate generated power prediction can be formulated as below.

Q S
The above definition is a min-max-optimization problem, where, P: PV power output (LSTM and GRU Final Comparative Results) Table 3.
g: Is conversion efficiency of PV module (Maximum efficiency for GRU and LSTM algorithms) (Durisch et al. 2007) Table 4. Q S : Respects the thermal energy losses through radiation and convection heat transfer from modules (Castillejo-Cuberos and Escobar 2020; Lave et al. 2015;Van Haaren et al. 2014) Figs. 16, 17. While the optimization variables can be defined as: A ¼ S; b; c; h r ; h c ; l; G T ; V WS ; u; f h, , , £, <, a, l; n; #; -; , } However, a problem with all these variables can be defined as an NP-Hard problem. And cannot be solved using tradition optimization techniques. Therefore, to solve this problem we will follow the below methodology Table 2.
After having modelled the environment, the operation and the signals to generate the patterns that is like the real patterns of the physical instruments, this pattern is clustered using k-mean clustering algorithm.
After that, we implement a monte-carlo simulation with the identification of all the bounds of the remained stochastic variables, and the optimization outputs, as mentioned in the above table. Inside the iterations of this simulation, Particle Swarm Optimization (PSO) algorithm, which is a metaheuristic stochastic-based algorithm is applied in order to identify the optimal values of the selected optimization variables.
After finding the optimal values of the parameters, these parameters as well as the output values, will be used in addition to the current and previous loads in order to produce the short-term prediction, for example, LSTM or GRU algorithms will be used in this phase. The below figure shows the block diagram of our proposed solution. The below figure summarizes this proposed method Fig. 2.
In the prediction phase,initially LSTM, see Fig. 3a, has been selected with training input is the output of the clustering phase with size of 1400 9 34and then this and 300 hidden layers with three output signals, representing the next or the future temporal values of n; p and the Qs in the LSTM we have used look up in order to use only the most useful or the most related samples in building that pattern. Moreover, GRU, see Fig. 3b, followed the same structure to compare both algorithms using the same benchmark in order to be able to figure out which one provides us with the most accurate future temporal value, and which one provides us with a most with the fastest processing time.

Datasets
Regarding the load, we have acquired it from a with shortterm slots of a frequency of 5 min which is very useful for our application in short-term prediction. This dataset (Dataset employed by this research can be retrieved from UK Smart Grid Industry 2021-2024) contains 371 samples each sample is 5 min separated from the other sample from the period of the first of January to the second of January in the year in the previous year 2020.This dataset was  Heat transfer coefficient of convection 2.5 to 5 W/(m2 9 K) Patil and Vijay (

Implementation and results
The modeling of the sun position for the selected location in London city in the UK, according to the location of the site from which we obtained the datasets which contains the temperature and solar radiation is shown below. Figure 4 shows, the first plot which is the alpha angle of the sun position from day 0 to day 350. So, for entire year according to the position of the coordinate of London city UK. Where the second plot is the Theta for the period time for the same position for the same location. Figure 5, below chooses the hourly extraterrestrial solar radiation profile for 16 days of January, each plots of this 16 plots for a specific date is shown that the plots almost similar to each other but the related plot for corresponding days increase with the increase of that day which means the peak value of each day as increasing according to the day number for example day 1 we have the value around 350 for day 2 its around 360 and so on the big value.the x-axis here is LMT ð Þ and y -axis the GextH ð Þ.While Fig. 6 shows five minutes step for only one day Fig. 7. Figure 7a shows the solar radiation for one day in January for 5 min step. And 7b the diffuse solar radiation for the same period of time also the step time 5 min. Figure 8 shows sample of the global solar radiation and diffuse solar radiation for sample days, the first day, day number 50, 100, 180, 250, and 360, which choose the variation of the solar radiation in this day. In this result we have used 60 min step so hourly based solar radiation for each day this value helps us to predict the next solar radiation for following minutes. Figure 9 shows the 5 min step solar radiation for the same days which also helps us to predict the short-term solar radiation for each 5 min, as we can see the pattern is almost similar, it looks smoother than the previous figure. Figure 10a shows the sun position for 5 min of one day in January the sun position alpha angle and theta angle.
it shows corresponding voltage, current and power for each sun position Fig. 10. between the sun position and generated power.
It appears from the above figures, that the sun position for the same day in different years is not the same. This is a physical fact that applies on all the natural resources and factors, such as wind, dust, shading, etc. Consequently, and as clearly shown in the figures above, the behavior of the natural factors is totally stochastic and cannot be predicted. Since the generation of the electricity is based and affected by these resources and factors. This leads to the fact, that the prediction of the generated energy based on renewable resources is a challenging problem. Therefore, this work GextH Five minutes step extraterrestrial solar radiation profile for one day Fig. 6 The hourly extraterrestrial solar radiation contributes to this field by developing a methodology to allow the process of short-term prediction for the shortterm future generated energy that is based on and affected by renewable resources and factors. Figure 11 shows the generated signals that contains1000 normal and 1000 faulty signals, each of which contains 34 features. However, these signals have been also generated using the stochastic features of the Montecarlo simulation.

Data Generation and Montecarlo simulation
To test the Prediction model Fig. 12.
In This phase we need to know the status of the pattern. Weather this signal is normal or a fault signal. However, in our problem we don't have target. There is no data set with a target. Also, the behavior of the normal traffic and that the behavior faulty traffic in the real life is a little bit of stochastic that does not follow a stable pattern. Therefore, we will not be able to identify the exact features of the input pattern and the target for them. Therefore, our problem can be defined as a clustering problem, In order to solve this clustering problem, We have used k-mean clustering algorithm the previously generated sample traffic have been sent to k-mean clustering algorithm then trained on it after that the clustering algorithm showed as a very clear recognition for the statues of traffic as shown in A B Fig. 10 The sun position alpha angle and theta angle and Sun position and generated power this figure, the given pattern is found in the first column of the table and then the predicted pattern have been output by k-mean clustering algorithm and as we see here both of them are identical with no any missing values. Therefore, we calculate the loss we have found it very, close to 0 which means that the accuracy is almost 100% (Loss K-means Testing = 2.2204e-16).

Prediction final results (for LSTM)
the below Fig. 13 shows the plots of the input training and target training, input testing and targeted testing for the prediction process (LSTM). It also shows the output prediction process which is almost exactly as the target testing this also can be improved by showing accuracy, which is almost near to 99.5%. the below Figs. 14 show the prediction finally this classified, or cluster recognized pattern should be sent to the prediction algorithm in order to prediction the Future traffic. For this we have used long short-term memory, which is best reignition technique and we have identified parameters using train and error as shown is this table, however, the training validation and testing process as shown in the figure, after the completion of the training validation and testing process is seen in this figure and as shown, the root mean square error is almost 0.71%.
While in the below Fig. 15, GRU is used to do the same prediction task, using the same inputs. This phase is made for a comparison purpose. Where it is clearly noticed that the GRU is slightly faster than the LSTM. But with higher error rate (1%) Table 3.

Identify Qs value
This section illustrates how to identify the Q S value. However, in (Castillejo-Cuberos and Escobar 0.2020) it was determined that the overall specific static and dynamic characteristics of solar irradiance for a determined time period, or state, are summarized by the clearness index (K t ), the diffuse fraction (K) and the variability of the solar Fig. 13 The input training and target training input testing and targeted testing for the prediction process (LSTM) 123 resource. By defining a variable termed the solar resource quality score (Q S ), irradiance patterns can be classified in an explicit scheme comparable to clustering techniques but providing a straightforward approach and a simple analytical expression on which to perform the classification, easily translatable across studies, overcoming the issue of data specificity previously discussed. The only variables needed are the global horizontal irradiance (GHI). The Q S is a measure of how close a particular state is from the ideal of full atmospheric clearness (K t = 1), no attenuation (K = 0) and constant irradiance (variability = 0). Lave et al. (2015) was used, defined as the probability that a particular ramp rate (RR = l GHI GesinðaÞ ! 0:03) exceeds a given threshold ramp (RR 0 ¼ 1000W=m 2 during an evaluation period, andðe ¼ 0:02Þ. The Variability Score (CDF based) ðVS cdf Þ uses the normalized, which is the result of linearly mapping the VS cdf from the range 0.002-0.4054 to 0-1 (Castillejo-Cuberos and Escobar 2020), Dt ð Þ temporal resolution timestep where, Dt ð Þ ¼ 5mints.   The quality score (Q S ): Van Haaren et al. (2014), the Daily Average Ramp Rate (DARR) is calculated as the sum of the absolute value of the changes in irradiance on a minute basis, normalized with an irradiance (G) of 1000 W/m2.
where, The maximum power point is given by: The maximum efficiency of a solar cell is expressed as: where, A: Area of the PV module,G a : Radiation. After implementation maximum efficiency for the GRU and LSTM algorithms value are determine as shown in the below Table 4: After implementing the optimization algorithm, we have obtained the optimal below values for using LSTM and GRU algorithms. The below tables Illustrate the exact optimal values for the future predicted values of the P, QS, and the efficiency Table 5.

Conclusions and future work
This work addresses the problem of future value estimation based on data with stochastic behaviour. The dependent variables used are the future active generated power, Qs, and the efficiency for the PV grid. While the independent variables are represented with the weather conditions and load behaviour. In this work we proposed a solution based on K-means clustering that converts the stochastic behaviour of the independent variables into a known pattern. Then it becomes easier for either the LSTM or the GRU to use it for the short-term future estimation of the dependant variable. A mathematical model in addition to dataset are  Fig. 17 Qs values using LSTM used to build a complete environment, with its operation and signals. And mote-Carlo method is used for simulation. As outcomes of a comparative study, we can confirm that although GRU is a fast algorithm, LSTM provides more accurate short-term predictions. Moreover, it's been concluded that stochasticity is an important factor to be considered in any future estimation process. However, the method proposed in this work shows clear outcomes in solving the stochasticity issue and enhancing the performance of the prediction. Uncertainty in this dynamic environment is an important factor that could be considered in future perspectives.
Acknowledgements The authors thank the anonymous reviewers forgiving their valuable comments and helping us to improve the quality of the paper.
Funding The funding is provided by Anglia Ruskin University.
Data Availability Dataset employed by this research can be retrieved from UK Smart Grid Industry 2021-2024. reportlinker.com/reportsummary/Electric-Power/88256/UK-Smart-Grid-Industry.html.

Declarations
Conflict of interest The authors declare that they have no conflicts of interest.
Ethical approval All procedures performed in studies involving human participants were in accordance with the ethical standards of the institutional and/or national research committee and with the 1964 Helsinki declaration and its later amendments or comparable ethical standards. All applicable international, national, and/or institutional guidelines for the care and use of animals were followed.
Informed consent Informed consent was obtained from all individual participants included in the study.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons. org/licenses/by/4.0/.