Improving the Distillate Prediction of a Membrane Distillation Unit in a Trigeneration Scheme by Using Artiﬁcial Neural Networks

: An Artiﬁcial Neural Network (ANN) has been developed to predict the distillate produced in a permeate gap membrane distillation (PGMD) module with process operating conditions (temperatures at the condenser and evaporator inlets, and feed seawater ﬂow). Real data obtained from experimental tests were used for the ANN training and further validation and testing. This PGMD module constitutes part of an isolated trigeneration pilot unit fully supplied by solar and wind energy, which also provides power and sanitary hot water (SHW) for a typical single family home. PGMD production was previously estimated with published data from the MD module manufacturer by means of a new type in the framework of Trnsys ® simulation within the design of the complete trigeneration scheme. The performance of the ANN model was studied and improved through a parametric study varying the number of neurons in the hidden layer, the number of experimental datasets and by using different activation functions. The ANN obtained can be easily exported to be used in simulation, control or process analysis and optimization. Here, the ANN was ﬁnally used to implement a new type to estimate the PGMD production of the unit by using the inlet parameters obtained by the complete simulation model of the trigeneration unit based on Renewable Energy Sources (RES). The module comprises part of one of the main subsystems of a hybrid pilot trigeneration unit which is fueled by solar and wind energy and produces power, desalted water by means of the PGMD and an RO module, and Sanitary Hot Water (SHW). The pilot unit designed to cover the typical water and energy demands of a single family home isolated from the grid. There are 4 main subsystems in the plant, as in Figure 1. The solar loop is composed of four photovoltaic thermal (PVT) collectors and one evacuated tube collector (ETC). The power loop consists of the supply of photovoltaic arrays aided with a micro-wind turbine and the storage on batteries to manage power demand. Solar energy is collected in a storage tank which feeds both the SHW demand and the PGMD unit (SHW loop). Finally, the fresh water loop includes the PGMD and the RO units, with the RO as an additional power demand. Details of the design simulation can be found in [7], where a complete sensitivity analysis was presented. The project was simulated with weather data from Zaragoza city, located in the northeast of Spain. The simulation was carried out for a complete year having a time step of 12 min (43,800 iterations).


Introduction
Fresh water and energy are closely related issues. Both are critical and mutually dependent resources, especially in dry and/or isolated areas. Freshwater scarcity is a major challenge facing modern societies [1], as well as the sustainable management of the water cycle by using RES [2] Desalination of seawater and brackish water is maybe the unique solution to alleviate freshwater scarcity nowadays [3]. However, it is an energy intensive process, since distillation processes such as Multi-Stage Flash (MSF), Multi-Effect Distillation (MED) and Membrane Distillation could consume about 50-70, 40-60 and 120-1700 kWh of thermal energy per cubic meter of distillate respectively, whereas membrane techniques such as Reverse Osmosis (RO) consume about 3 to 6 kWh of electricity per cubic meter of permeate [4]. This close relationship has been dealt with, even in oil rich countries, in which RES are also planned to cover the 100% of the energy demand, including desalination [5]. Despite its energy consumption, membrane distillation (MD) can help to reduce the water-energy stress that societies are facing, especially at a reduced scale and when waste heat from other thermal processes or solar energy is freely available.
Membrane distillation (MD) is a low-heat grade energy consumer and non-isothermal method for water treatment and desalination. Feed water does not need any kind of chemical pre-treatments permeability constant of the RO process that could be used for different membranes across a wide range of pressures. Khayet et al. [34] used both, a response surface methodology (RSM) and ANN, to predict the performance index of an RO system as well as to achieve optimal experimental conditions. The inlet ANN parameter corresponds to feed properties (concentration, temperature, feed flow and pressure) under controlled conditions.
Regarding the use of ANN models in MD, their application to a vacuum membrane distillation (VMD) was first presented in [15]. The model was based on experimental input data such as feed temperature, flow rate and concentration as well as the vacuum pressure to predict the distillate flux. Khayet and Cojocaru [35,36] presented two different ANN models to simulate the production of two MD configurations. In [35], they studied an air gap membrane distillation process (AGMD) to describe the distillate flow depending on the air gap thickness, condensation temperature, and the inlet temperature and flow rate of the feed. In [36], a sweeping gas membrane distillation process (SGMD) to predict the distillate flux and the salt rejection was studied in depth. Here, the three considered input parameters were inlet temperature and the velocities of water and air.
The combination of ANN with existing simulation software has been also extensively used, specifically in the field of energy efficiency in buildings and solar energy. The idea is to improve the predictions given by the software with the help of an ANN made from experimental results or running of the software. In this context, Trnsys ® is software that has been widely linked with ANNs. For instance, Magnier and Haghighat [37] developed an ANN model based on a validated simulation for the optimization of thermal comfort and energy consumption in a residential house. They found that integrating ANN into optimization could considerably reduce the simulation time compared with classical optimization methods. In [38], a multi-objective optimization model using genetic algorithms and ANNs to improve energy consumption and to reduce thermal discomfort and costs in a school building was presented. Training data sets were also obtained from parametric runs. Buratti et al. [39] compared the different approaches of ANN and the simulator of the energy performance of buildings in Perugia, Italy. They found that the ANN model results were closer to the measured data than the results from simulation. Furthermore, Souliotis et al. [40] combined the use of an ANN model trained with experimental uncontrolled data from a solar collector with the simulator to improve the results of that integrated collector storage. To sum up, an extent review of the ANN and simulation is available in [41].
As far as the authors' know, this study is the first implementation of an ANN to a PGMD module. In this paper, the ANN is devoted to improve the prediction results of the permeate flux of this module, which is fully integrated in a trigeneration unit based on the hybrid production of desalted water by consuming heat (PGMD) or power (RO) coming from RES. In this manner, a more accurate prediction of the three plant products (desalted seawater, SHW and power) could then be done. A first attempt to include the PGMD in the integrated scheme was based on a simple regression model that accounted for a reduced band of incoming operating parameters. Thus, higher distillate rates were estimated and therefore fewer energy resources were derived to supply the PGMD, with the alternate productions of SHW and power also affected.
On the other hand, the ANN has been constructed using several experimental data sets under different conditions and does not depend on the energy source applied, as will be explained in Section 3.1.2. Those data have been precisely the key to provide a better performance of the ANN model. Most of the datasets belong to a quasi-static process condition, which is typical in a module immersed in a rather complex unit fully supplied by two aleatory RES sources (solar and wind energy): in the case of the PGMD module, the heat supply is smoothed out by the existence of the hot water tank [40]. To sum up, the ANN contributes to the validation of the integrated simulation model, which is being tested with the final aim of scaling up those trigeneration schemes fully supplied by RES for small remote settlements. Nevertheless, this ANN model can be freely exported to any kind of simulation tool or to a control system, in order to predict the performance of any other PGMD module with similar characteristics.

Trigeneration Unit Based on RES
The PGMD module comprises part of one of the main subsystems of a hybrid pilot trigeneration unit which is fueled by solar and wind energy and produces power, desalted water by means of the PGMD and an RO module, and Sanitary Hot Water (SHW). The pilot unit was designed to cover the typical water and energy demands of a single family home isolated from the grid. There are 4 main subsystems in the plant, as shown in Figure 1. The solar loop is composed of four photovoltaic thermal (PVT) collectors and one evacuated tube collector (ETC). The power loop consists of the supply of photovoltaic arrays aided with a micro-wind turbine and the storage on batteries to manage power demand. Solar energy is collected in a storage tank which feeds both the SHW demand and the PGMD unit (SHW loop). Finally, the fresh water loop includes the PGMD and the RO units, with the RO as an additional power demand. Details of the design simulation can be found in [7], where a complete sensitivity analysis was presented. The project was simulated with weather data from Zaragoza city, located in the northeast of Spain. The simulation was carried out for a complete year having a time step of 12 min (43,800 iterations).

Trigeneration Unit Based on RES
The PGMD module comprises part of one of the main subsystems of a hybrid pilot trigeneration unit which is fueled by solar and wind energy and produces power, desalted water by means of the PGMD and an RO module, and Sanitary Hot Water (SHW). The pilot unit was designed to cover the typical water and energy demands of a single family home isolated from the grid. There are 4 main subsystems in the plant, as shown in Figure 1. The solar loop is composed of four photovoltaic thermal (PVT) collectors and one evacuated tube collector (ETC). The power loop consists of the supply of photovoltaic arrays aided with a micro-wind turbine and the storage on batteries to manage power demand. Solar energy is collected in a storage tank which feeds both the SHW demand and the PGMD unit (SHW loop). Finally, the fresh water loop includes the PGMD and the RO units, with the RO as an additional power demand. Details of the design simulation can be found in [7], where a complete sensitivity analysis was presented. The project was simulated with weather data from Zaragoza city, located in the northeast of Spain. The simulation was carried out for a complete year having a time step of 12 min (43,800 iterations).
The complete system simulation was later expanded by studying the effects of the battery capacity and electric load [42]. Exergy analysis has also been implemented to reduce local irreversibilities [43,44]. The trigeneration pilot plant was fully erected during the year 2016 in Zaragoza, Spain [45]. In the experimental facility, thermal energy is stored in a 325 L water tank that feds the PGMD through a heat exchanger (HX Tank-MD in Figure 1). The control system number 1 presented in the same figure allows obtaining stable temperatures inside the tank due to hysteresis between solar collectors and tank temperature. Tank stratification permits hot water delivery at almost constant temperatures to HX Tank-MD to feed the membrane system. The PGMD is a commercial module and contains a spiral wound desalination membrane with a maximum capacity of 20 L/h with a very pure distillate (<2 ppm of salinity). It has a total exchange area of 10 m 2 , with the corresponding condenser, distillate and evaporator channels as explained in [13]. Usually, the set-up temperature to feed the PGMD was 70 °C, but lower temperatures could activate the PGMD. The pilot unit included a sophisticated control and monitoring system. Five temperatures were measured at the PGMD inlet/outlets. Inlet and return flow rates from the HX Tank-MD were also measured to estimate the PGMD thermal energy consumption. Seawater tank and outside temperatures are measured as well. All The complete system simulation was later expanded by studying the effects of the battery capacity and electric load [42]. Exergy analysis has also been implemented to reduce local irreversibilities [43,44].
The trigeneration pilot plant was fully erected during the year 2016 in Zaragoza, Spain [45]. In the experimental facility, thermal energy is stored in a 325 L water tank that feds the PGMD through a heat exchanger (HX Tank-MD in Figure 1). The control system number 1 presented in the same figure allows obtaining stable temperatures inside the tank due to hysteresis between solar collectors and tank temperature. Tank stratification permits hot water delivery at almost constant temperatures to HX Tank-MD to feed the membrane system. The PGMD is a commercial module and contains a spiral wound desalination membrane with a maximum capacity of 20 L/h with a very pure distillate (<2 ppm of salinity). It has a total exchange area of 10 m 2 , with the corresponding condenser, distillate and evaporator channels as explained in [13]. Usually, the set-up temperature to feed the PGMD was 70 • C, but lower temperatures could activate the PGMD. The pilot unit included a sophisticated control and monitoring system. Five temperatures were measured at the PGMD inlet/outlets. Inlet and return flow rates from the HX Tank-MD were also measured to estimate the PGMD thermal energy consumption. Seawater tank and outside temperatures are measured as well. All temperatures were measured by PT-100 sensors (±0.2 • C) and gathered every minute by an automata, which also controls valves, pumps and any other safety systems. The PGMD production rate and SHW flow rate to the PGMD (via the HX Tank-MD) and SHW demand were visually measured by three flowmeters, with an accuracy estimated in a range of ±2% after calibration. Finally, conductivity of the seawater tank, PGMD distillate and RO permeate are measured by different conductivity meters, but only the distillate quality is recorded by the automata. Distillate flow will be then be a varying function of the heat supplied to the PGMD module, which provokes a temperature drop between the evaporator and condenser channels of the PGMD. These temperature variations occur gradually, so the system can be considered a quasi-static process and data can be recorded for different temperatures scenarios. Figure 2 shows a sketch of the PGMD where feed water (flow 3) enters into the condenser, takes energy and then increments its temperature due to the heat transfer from the evaporator and distillate channels (flow 4). Feed water is then reheated by an external heat source by means of the HX Tank-MD (flows 1 and 2). Then, hot feed water enters the evaporator (flow 5) where some vapor is produced and the remaining liquid transfers the heat to the condenser side. Finally, vapor passes through the membrane and then it is condensed to obtain distillate (flow 7). The salinity of the remaining brine is then slightly increased (flow 6). three flowmeters, with an accuracy estimated in a range of ±2% after calibration. Finally, conductivity of the seawater tank, PGMD distillate and RO permeate are measured by different conductivity meters, but only the distillate quality is recorded by the automata. Distillate flow will be then be a varying function of the heat supplied to the PGMD module, which provokes a temperature drop between the evaporator and condenser channels of the PGMD. These temperature variations occur gradually, so the system can be considered a quasi-static process and data can be recorded for different temperatures scenarios. Figure 2 shows a sketch of the PGMD where feed water (flow 3) enters into the condenser, takes energy and then increments its temperature due to the heat transfer from the evaporator and distillate channels (flow 4). Feed water is then reheated by an external heat source by means of the HX Tank-MD (flows 1 and 2). Then, hot feed water enters the evaporator (flow 5) where some vapor is produced and the remaining liquid transfers the heat to the condenser side. Finally, vapor passes through the membrane and then it is condensed to obtain distillate (flow 7). The salinity of the remaining brine is then slightly increased (flow 6). In [7], the PGMD production was estimated by a linear correlation based on experimental results from Winter et al. [13]. The regression parameters were chosen in such a way that everyone can compute the product of a PGMD independently from the heat source type. As already explained, the distillate depends on the different temperatures and pressures on both sides of the membrane. Since the purpose of this investigation is to create a model that does not depend on external sources, evaporator and condenser inlets (the hottest and coldest zones inside the membrane, respectively) only the thermal inputs, as well as the feed water flow, must be considered. By taking into account those variables, the model can forecast the fresh water production. The mathematical linear regression model obtained was:

PGMD Preliminary Distillate Prediction
This linear model produces acceptable results mainly when it is applied to a spiral wound membrane unit with 10 m 2 with temperature drops of about 55 °C between the inlets of the evaporator (Tei) and condenser (Tci), and feed water (mfeed) of 35 g/kg of salinity with a flow range from 200 L/h to 500 L/h. As stated in [7], this model can give a first estimation even if temperature differences are lower than 55 °C; then, it can be used as a first approach during the first design stage of the trigeneration plant. In [7], the PGMD production was estimated by a linear correlation based on experimental results from Winter et al. [13]. The regression parameters were chosen in such a way that everyone can compute the product of a PGMD independently from the heat source type. As already explained, the distillate depends on the different temperatures and pressures on both sides of the membrane. Since the purpose of this investigation is to create a model that does not depend on external sources, evaporator and condenser inlets (the hottest and coldest zones inside the membrane, respectively) only the thermal inputs, as well as the feed water flow, must be considered. By taking into account those variables, the model can forecast the fresh water production. The mathematical linear regression model obtained was:

PGMD Experimental Validation
This linear model produces acceptable results mainly when it is applied to a spiral wound membrane unit with 10 m 2 with temperature drops of about 55 • C between the inlets of the evaporator (T ei ) and condenser (T ci ), and feed water (m feed ) of 35 g/kg of salinity with a flow range from 200 L/h to 500 L/h. As stated in [7], this model can give a first estimation even if temperature differences are lower than 55 • C; then, it can be used as a first approach during the first design stage of the trigeneration plant.

PGMD Experimental Validation
In order to characterize the PGMD production, the abovementioned three measured parameters have been taken into consideration (inlet condenser and evaporator temperatures as well as seawater feed flow). Two kinds of data sets were obtained from the experimental facility. The first dataset was obtained by using a 3 kW heating resistance immersed in the hot water tank ("electric"). The hot water temperature in the tank was monitored with three PT-100 sensors, two inside the tank and one at the water outlet to control stratification and the temperature of the heat MD source, respectively. By using the heating resistance, the temperature in the MD heating source was kept constant at different values to perform the tests at a steady state. Those tests were carried out from December 2016 to February 2017 within the performance tests of the PGMD module. Thus, the second dataset ("solar") was obtained from the complete operation of the trigeneration facility by only using solar energy (heating resistance remained off); here, distillate mainly depended on the weather conditions and heat derived to supply the SHW demand. However, as explained before, the stratification inside the tank allows delivering hot water at an almost constant temperature during the characterization of the PGMD with solar energy, thus assuming that in those tests, a quasi-static process is occurring. Figure 3 shows the behavior of the system during a solar test in July. At the beginning of the day, the tank temperature was about 65 • C and the heating process due to hysteresis started; the temperature of the tank increased as the sun radiation intensity increased. When the temperature in the hot water outlet zone reached about 75 • C, the MD test started. It can be seen that due to the tank stratification, a constant temperature can be maintained during tests. Due to the high energy rate of the MD evaporator, the tank temperature and therefore that of the evaporator inlet went down; nevertheless, it can be observed that the system operated at almost constant temperature levels. Datasets for different temperatures and mass flow rates feeding the MD unit were gathered in the test bench. A solar dataset was obtained in a campaign from May to October 2017. Table 1 shows the operating range of the variables used during the data collection.
Water 2018, 10, x FOR PEER REVIEW 6 of 20 feed flow). Two kinds of data sets were obtained from the experimental facility. The first dataset was obtained by using a 3 kW heating resistance immersed in the hot water tank ("electric"). The hot water temperature in the tank was monitored with three PT-100 sensors, two inside the tank and one at the water outlet to control stratification and the temperature of the heat MD source, respectively. By using the heating resistance, the temperature in the MD heating source was kept constant at different values to perform the tests at a steady state. Those tests were carried out from December 2016 to February 2017 within the performance tests of the PGMD module. Thus, the second dataset ("solar") was obtained from the complete operation of the trigeneration facility by only using solar energy (heating resistance remained off); here, distillate mainly depended on the weather conditions and heat derived to supply the SHW demand. However, as explained before, the stratification inside the tank allows delivering hot water at an almost constant temperature during the characterization of the PGMD with solar energy, thus assuming that in those tests, a quasi-static process is occurring. Figure 3 shows the behavior of the system during a solar test in July. At the beginning of the day, the tank temperature was about 65 °C and the heating process due to hysteresis started; the temperature of the tank increased as the sun radiation intensity increased. When the temperature in the hot water outlet zone reached about 75 °C, the MD test started. It can be seen that due to the tank stratification, a constant temperature can be maintained during tests. Due to the high energy rate of the MD evaporator, the tank temperature and therefore that of the evaporator inlet went down; nevertheless, it can be observed that the system operated at almost constant temperature levels. Datasets for different temperatures and mass flow rates feeding the MD unit were gathered in the test bench. A solar dataset was obtained in a campaign from May to October 2017. Table 1 shows the operating range of the variables used during the data collection.    Once enough data were collected, results from simulations and real measured data could be compared. If experimental production of the PGMD and the one predicted by the simulation in their linear regression model from Equation (1) are balanced, a considerable deviation in the prediction is found. As an example, Figure 4 shows all the temperatures and permeate samples collected in one typical summer solar test (24 July 2017) and the product from the linear regression simulation, both with a seawater feed of 300 L/h. Figure 4 (below) shows that the temperature at the condenser inlet (blue lines) was very similar in both cases, but the temperature at the evaporator inlet (red lines) was slightly over predicted by the simulation. As that temperature difference is the driving force to produce distillate (green lines), and a deviation of 6 • C was found, a rather high estimation of the distillate was encountered. Although it is an acceptable value considering that the simulator uses standard weather conditions, constant efficiencies and time step approximations, from Figure 4 (above), we can conclude that the model previously presented in [7] must be strongly improved if PGMD production has to be finely predicted in the complete trigeneration scheme erected. with a seawater feed of 300 L/h. Figure 4 (below) shows that the temperature at the condenser inlet (blue lines) was very similar in both cases, but the temperature at the evaporator inlet (red lines) was slightly over predicted by the simulation. As that temperature difference is the driving force to produce distillate (green lines), and a deviation of 6 °C was found, a rather high estimation of the distillate was encountered. Although it is an acceptable value considering that the simulator uses standard weather conditions, constant efficiencies and time step approximations, from Figure 4 (above), we can conclude that the model previously presented in [7] must be strongly improved if PGMD production has to be finely predicted in the complete trigeneration scheme erected. On the other hand, ANN models do not require detailed information about the system, that is, a standard experimental design is not required to develop the model, and different experimental designs may be used [34]. They can learn the relationship between the input parameters and the test variable results, as non-linear regression might perform [40]. To conclude, ANN models are very flexible and it is not necessary that the variables follow a constant step of variation [35]. They are able On the other hand, ANN models do not require detailed information about the system, that is, a standard experimental design is not required to develop the model, and different experimental designs may be used [34]. They can learn the relationship between the input parameters and the test variable results, as non-linear regression might perform [40]. To conclude, ANN models are very flexible and it is not necessary that the variables follow a constant step of variation [35]. They are able to adequately learn the specific behavior of the entire system and to predict the production in the face of variations in any of its operating parameters [32].
Consequently, an ANN scheme has been proposed with data obtained from the electric tests, the solar tests and the combination of both datasets in order to improve the prediction of its distillate under any other operating conditions that could feed the PGMD module immersed in that trigeneration scheme. If temperature conditions are controlled, a recurrent neural network model is not necessary; this fact has already been proven in other types of ANN membrane models presented in [35,36]. Here, the ANN model was developed by using Matlab R2017b software (version 9.3.0.713579 (R2017b), MathWorks, Natick, MA, USA) and the standard functions included in the Neural Network Toolbox. In particular, the Levenber-Marquardt back-propagation algorithm was applied [46]. Levenberg-Marquardt is a curve-fitting method that improves the solution to problems by only adjusting the learning rate repeatedly. This algorithm combines two minimization methods such as the gradient decent and Gauss-Newton methods [17].

ANN Model
The definite structure of the selected ANN is shown in Figure 5. Measured inlet temperatures of the evaporator (T ei ) and condenser (T ci ) and seawater feed flow in the PGMD (m feed ) were used as the ANN inputs. The output of the ANN is the distillate produced (m dist ). The developed ANN-based correlation will be then adopted to replace the existing linear regression correlation in the previous simulation presented in [7]. Regardless, the mathematical model of this ANN for this PGMD can be extrapolated to any other software.
Water 2018, 10, x FOR PEER REVIEW 8 of 20

ANN Model
The definite structure of the selected ANN is shown in Figure 5. Measured inlet temperatures of the evaporator (Tei) and condenser (Tci) and seawater feed flow in the PGMD (mfeed) were used as the ANN inputs. The output of the ANN is the distillate produced (mdist). The developed ANN-based correlation will be then adopted to replace the existing linear regression correlation in the previous simulation presented in [7]. Regardless, the mathematical model of this ANN for this PGMD can be extrapolated to any other software. The ANN modelling was performed using the following procedure: 1. Data preprocessing: Data from the automata were prepared. Some outliers in data were identified and eliminated. Inputs and outputs were carefully reviewed to provide valuable information, avoid noise and to assure the correct prediction of the ANN. 2. Structure selection: The architecture of the ANN model includes three inputs, one hidden layer and one output layer with a single neuron. A small sized ANN was preferred in order to facilitate exportation and therefore to consume fewer computational resources. 3. Inputs and targets are normalized following this equation: where x represents finite and real values to normalize, y represents the normalized values, ymin and The ANN modelling was performed using the following procedure: 1.
Data preprocessing: Data from the automata were prepared. Some outliers in data were identified and eliminated. Inputs and outputs were carefully reviewed to provide valuable information, avoid noise and to assure the correct prediction of the ANN.

2.
Structure selection: The architecture of the ANN model includes three inputs, one hidden layer and one output layer with a single neuron. A small sized ANN was preferred in order to facilitate exportation and therefore to consume fewer computational resources. 3. Inputs and targets are normalized following this equation: where x represents finite and real values to normalize, y represents the normalized values, y min and y max define the limits of the normalization (−1 to 1 in case of Tanh, and 0 to 1 for Log-Sigmoid).

4.
Training: The training phase is performed by constantly updating weights and biases to achieve a certain Mean Square Error (MSE, at least 0.5) and Coefficient of Determination R (at least 0.95).
In this phase, 90% of the available samples were taken.

5.
Validation and testing: The 10% remaining available samples were chosen for validation and testing. In both stages of the ANN creation, a minimum value of 0.95 is required for R. 6.
Development: After the learning phase, the optimal values of the weights and biases are saved, and the ANN is developed 7.
Exportation: Once the ANN has proved to provide most accurate values of the PGMD production, the model is exported if it is going to be used in any other applications.
The ANN model can be exported in a matrix form as follows: Note that normalization and de-normalization may be needed, which implies the inclusion of one or more parameters in the above equation.

Parametric Modelization of the ANN Performance
The analysis of the main parameters describing the ANN performance is presented next. First, the number of neurons in the hidden layer is studied in depth. Second, the dataset gathered to create the ANN was analyzed. Third, the activation function used was also studied.

Number of Neurons in Hidden Layer
There is no common rule to apply to find out the optimum number of neurons in the hidden layer. Some authors suggest that at least it would be equal to the 75% of the numbers of neurons in the input layer [47]. On the other hand, others suggest that the simplest way is to identify that number by trial and error up to the minimum error on the validation dataset [17]. Thus, a parametric study was performed in this issue.
The first approach used was based on a relationship among the number of samples in the dataset, the neurons in the input layer (N) and neurons in hidden layer (n) as presented by Martín et al. in [47].
Based on this equation, the number of neurons in hidden layer for the case of the electric dataset was between 68 and 248, and for the case of solar dataset, was between 1878 and 7514. The trained ANN model took the form 3-68-1; the performance (MSE) was found to be 0.38 with an R value of 0.9599, which at first seemed to be an adequate model. However, when external data from [13] were tested, the model proved to be over fitted, and the number of neurons had to be decreased.
From the same reference [47], the classical Kolmogorov approach can also be used to estimate the minimum number of neurons in the hidden layer as: If the effect of the dataset size is neglected, the minimum number of neurons in the hidden layer is 7. Therefore, nine different ANN models were trained using inputs from the electrical and solar datasets, varying the number of neurons from 7 to 15. Figure 6 shows the parametric results of varying the number of neurons in the hidden layer.

Samples
Samples n N N < < (4) Based on this equation, the number of neurons in hidden layer for the case of the electric dataset was between 68 and 248, and for the case of solar dataset, was between 1878 and 7514. The trained ANN model took the form 3-68-1; the performance (MSE) was found to be 0.38 with an R value of 0.9599, which at first seemed to be an adequate model. However, when external data from [13] were tested, the model proved to be over fitted, and the number of neurons had to be decreased.
From the same reference [47], the classical Kolmogorov approach can also be used to estimate the minimum number of neurons in the hidden layer as: If the effect of the dataset size is neglected, the minimum number of neurons in the hidden layer is 7. Therefore, nine different ANN models were trained using inputs from the electrical and solar datasets, varying the number of neurons from 7 to 15. Figure 6 shows the parametric results of varying the number of neurons in the hidden layer.  In Figure 6, it can be seen that the MSE of the ANN model with 7 neurons is 25% higher than the case with 10 neurons and 26% higher than the case with 15 neurons. The MSE is decreased as the number of neurons is increased. However, it can be clearly observed that the difference among the models from 10 to 15 neurons is minimal, about 0.8%. The same trend can be observed with the coefficient of determination, R. The model with 7 neurons is 1.31% and 1.38% smaller than the cases with 10 and 15 neurons, respectively. The effect on the R value of the number of neurons in the hidden layer can be observed in Figure 7 for the case of 7, 9, 10 and 15 neurons. Once again, it can be seen that after 10 neurons, the performance of the ANN model remains at R values very close to a value of 0.95.
The optimum number of neurons in hidden layer was then established between 10 and 15. Considering that the model with 10 neurons in the hidden layer is easier to export to external systems, later analysis will be based on the 10 neuron case. The number of neurons in the hidden layer reported here coincides with other ANN models presented in [35,36] for similar membrane distillation systems. Nevertheless, the model with 15 neurons is alternatively presented as supplementary information at the end of the paper. models from 10 to 15 neurons is minimal, about 0.8%. The same trend can be observed with the coefficient of determination, R. The model with 7 neurons is 1.31% and 1.38% smaller than the cases with 10 and 15 neurons, respectively. The effect on the R value of the number of neurons in the hidden layer can be observed in Figure 7 for the case of 7, 9, 10 and 15 neurons. Once again, it can be seen that after 10 neurons, the performance of the ANN model remains at R values very close to a value of 0.95. The optimum number of neurons in hidden layer was then established between 10 and 15. Considering that the model with 10 neurons in the hidden layer is easier to export to external systems, later analysis will be based on the 10 neuron case. The number of neurons in the hidden layer reported here coincides with other ANN models presented in [35,36] for similar membrane distillation systems. Nevertheless, the model with 15 neurons is alternatively presented as supplementary information at the end of the paper.

Dataset Collection
Since the ANN model is independent of the heat source, it is possible to present, compare and combine experimental data under different conditions by only knowing the three abovementioned parameters. It was found that the performance of the ANN improved as the number of experimental data sets increased; thus, three data sets were consecutively analyzed to train the ANN. The first two datasets correspond to the electric and solar, the third one is the combination of both, electric and solar. The third data set was found to be the best solution in terms of the ANN accuracy. The overall

Dataset Collection
Since the ANN model is independent of the heat source, it is possible to present, compare and combine experimental data under different conditions by only knowing the three abovementioned parameters. It was found that the performance of the ANN improved as the number of experimental data sets increased; thus, three data sets were consecutively analyzed to train the ANN. The first two datasets correspond to the electric and solar, the third one is the combination of both, electric and solar. The third data set was found to be the best solution in terms of the ANN accuracy. The overall performance of the ANN based on the different experimental data sets (electric, solar and combined) is presented in Table 2. In detail, Figure 8 shows the performance of the ANN fed by the three data sets of experimental values and the linear regression previously presented in [7]. In detail, Figure 8 shows the performance of the ANN fed by the three data sets of experimental values and the linear regression previously presented in [7]. It can be seen that the linear regression presented in previous investigations is not very accurate; however, it gave us a first approximation to estimate the PGMD production under real conditions ( Figure 8, top left-hand corner). Alternatively, the ANN model fed by only electric data tests did not strongly improved the linear regression, since its MSE decreased from 30.61 to 10.45 and the R increased from 0.48 to 0.58 (Figure 8, top right-hand corner). Table 3 shows some typical inlet and outlet parameters of some selected samples from the electric dataset at different temperature levels as described in Section 2.3.  It can be seen that the linear regression presented in previous investigations is not very accurate; however, it gave us a first approximation to estimate the PGMD production under real conditions ( Figure 8, top left-hand corner). Alternatively, the ANN model fed by only electric data tests did not strongly improved the linear regression, since its MSE decreased from 30.61 to 10.45 and the R increased from 0.48 to 0.58 (Figure 8, top right-hand corner). Table 3 shows some typical inlet and outlet parameters of some selected samples from the electric dataset at different temperature levels as described in Section 2.3. However, significant progress was found when solar tests used the training information for the ANN: the MSE decreased to 0.86, and R increased to 0.91 (Figure 8, bottom left-hand corner). Table 4 shows some random samples taken from the solar conditions corresponding to the solar set at different temperature levels as described in Section 2.3. Finally, when all data were combined, the ANN model gave the most accurate results, with the lowest value of MSE (0.47) and highest R value (0.95) (Figure 8, bottom right-hand corner). Thus, this last set including the combined electric and solar test conditions was used for the definite ANN.

Parameter Linear Regression ANN (Electric) ANN (Solar) ANN (Both Datasets
Alternatively, Figure 9 presents the global comparison of the 11,643 experimental samples of distillate produced in the PGMD module (in blue) with those predicted by the linear regression and by the ANN models (with three different data sets, in red). However, significant progress was found when solar tests used the training information for the ANN: the MSE decreased to 0.86, and R increased to 0.91 (Figure 8, bottom left-hand corner). Table 4 shows some random samples taken from the solar conditions corresponding to the solar set at different temperature levels as described in Section 2.3. Table 4. Some selected samples from the solar experimental tests (11,272). Finally, when all data were combined, the ANN model gave the most accurate results, with the lowest value of MSE (0.47) and highest R value (0.95) (Figure 8, bottom right-hand corner). Thus, this last set including the combined electric and solar test conditions was used for the definite ANN.

Sample Tei (°C) Tci (°C) mfeed (L/h) mdist (L/h)
Alternatively, Figure 9 presents the global comparison of the 11,643 experimental samples of distillate produced in the PGMD module (in blue) with those predicted by the linear regression and by the ANN models (with three different data sets, in red).  As presented previously in Figure 4, the linear regression overestimates the production of the PGMD (first). This overestimation is clearly decreased with the use of the ANN model based on the electric data tests (second). The ANN based on the solar energy supply data tests (third) shows that the distillate prediction is accurate in the range between 5 L/h and 10 L/h but it fails at higher productions (about 15 L/h). This problem is solved (without over fitting) when all data, that is, coming from electric and solar data tests, are included in the definite ANN model (fourth).

Activation Function in the Hidden Layer
The back-propagation algorithm applied requires that the activation function has to be continuous and therefore derivable to obtain the error in the hidden and output neurons [47]. Here, three basic functions that comply with this condition are analyzed in the hidden layer: linear function and sigmoidal functions (log-sigmoid and Tanh). Figure 10 shows a comparison of the MSE and R performance with three different activation functions.
Water 2018, 10, x FOR PEER REVIEW 13 of 20 As presented previously in Figure 4, the linear regression overestimates the production of the PGMD (first). This overestimation is clearly decreased with the use of the ANN model based on the electric data tests (second). The ANN based on the solar energy supply data tests (third) shows that the distillate prediction is accurate in the range between 5 L/h and 10 L/h but it fails at higher productions (about 15 L/h). This problem is solved (without over fitting) when all data, that is, coming from electric and solar data tests, are included in the definite ANN model (fourth).

Activation Function in the Hidden Layer
The back-propagation algorithm applied requires that the activation function has to be continuous and therefore derivable to obtain the error in the hidden and output neurons [47]. Here, three basic functions that comply with this condition are analyzed in the hidden layer: linear function and sigmoidal functions (log-sigmoid and Tanh). Figure 10 shows a comparison of the MSE and R performance with three different activation functions. Linear activation function proved to have an MSE 56% higher than Tanh or log-sigmoid cases. On the other hand, a higher R value was found in the Tanh model, being 0.02% and 3% higher than log-sigmoid and linear models, respectively. Regarding the MSE difference between Tanh and logsigmoid models, it is only about 0.8%, but both functions showed a rather similar behavior. Thus, the ANN model with Tanh as activation function is presented in next sections. Regardless, the ANN model with log-sigmoid activation function will be also presented as supplementary information.

ANN Fitting Model to Compute PGMD Production
Based on the results discussed in Sections 3.1.1 to 3.1.3, the model presented here is an ANN with structure 3:10:1 trained with electric and solar data sets and Tanh as activation function in the hidden layer.
Equations below include in detail the ANN model parameters for a PGMD. It can be freely used for anyone who wants to estimate the production of this kind of MD. The model can be used during the design stages of new projects or to improve the operation and control in existing facilities. Linear activation function proved to have an MSE 56% higher than Tanh or log-sigmoid cases. On the other hand, a higher R value was found in the Tanh model, being 0.02% and 3% higher than log-sigmoid and linear models, respectively. Regarding the MSE difference between Tanh and log-sigmoid models, it is only about 0.8%, but both functions showed a rather similar behavior. Thus, the ANN model with Tanh as activation function is presented in next sections. Regardless, the ANN model with log-sigmoid activation function will be also presented as supplementary information.

ANN Fitting Model to Compute PGMD Production
Based on the results discussed in Sections 3.1.1-3.1.3, the model presented here is an ANN with structure 3:10:1 trained with electric and solar data sets and Tanh as activation function in the hidden layer.
Equations below include in detail the ANN model parameters for a PGMD. It can be freely used for anyone who wants to estimate the production of this kind of MD. The model can be used during the design stages of new projects or to improve the operation and control in existing facilities.

ANN Validation
The 3-D view (Figure 11) of the experimental and predicted production of the PGMD shows that the definite ANN model obtained is flexible, adaptable and is not over fitted. The detail in Figure 11 shows that the ANN accurately predicts the PGMD distillate independently from the feed flow rate or temperature gap between the condenser and evaporator inlets. Thus, the model can adumbrate the production in the range from 200 L/h to 500 L/h and with a temperature difference band from 10 • C to 60 • C between the inlets of the evaporator and condenser for a feed seawater of 35 g/kg of salinity. Note that a few samples are only taken in the range from 10 • C to 30 • C and the band of 200 L/h since the MD performance was rather low (a very high specific thermal energy consumption was found), and the major number of tests were located in the range of 300 L/h, which allowed the pilot unit to maintain the inlet temperature drop in the range of 30-50 • C under any sunny condition during the solar tests.

ANN Validation
The 3-D view (Figure 11) of the experimental and predicted production of the PGMD shows that the definite ANN model obtained is flexible, adaptable and is not over fitted. The detail in Figure 11 shows that the ANN accurately predicts the PGMD distillate independently from the feed flow rate or temperature gap between the condenser and evaporator inlets. Thus, the model can adumbrate the production in the range from 200 L/h to 500 L/h and with a temperature difference band from 10 °C to 60 °C between the inlets of the evaporator and condenser for a feed seawater of 35 g/kg of salinity. Note that a few samples are only taken in the range from 10 °C to 30 °C and the band of 200 L/h since the MD performance was rather low (a very high specific thermal energy consumption was found), and the major number of tests were located in the range of 300 L/h, which allowed the pilot unit to maintain the inlet temperature drop in the range of 30-50 °C under any sunny condition during the solar tests. To reinforce that this ANN model is not over fitted, results from Winter et al. [13] were also introduced and compared in Figure 12, which shows the same results as those presented in Figure  11, but in a 3-D surface view. The variation of the temperature difference (Tei − Tci) was constrained from 35 °C to 55 °C (with a step of 1 °C and 20 L/h). Note that in the reference the abovementioned temperature difference was maintained at 55 °C (80 °C in evaporator inlet and 25 °C in condenser inlet) in the tests. Although some deviations were found (green line), the ANN model predicts the PGMD production with rather good accuracy, especially in the range from 200 L/h to 400 L/h for that energy supply. Furthermore, the ANN model could enlarge the predictions within a wider range of temperature drops and mass flow rates, corresponding to the typical operation of a PGMD only supplied by solar energy. To reinforce that this ANN model is not over fitted, results from Winter et al. [13] were also introduced and compared in Figure 12, which shows the same results as those presented in Figure 11, but in a 3-D surface view. The variation of the temperature difference (T ei − T ci ) was constrained from 35 • C to 55 • C (with a step of 1 • C and 20 L/h). Note that in the reference the abovementioned temperature difference was maintained at 55 • C (80 • C in evaporator inlet and 25 • C in condenser inlet) in the tests. Although some deviations were found (green line), the ANN model predicts the PGMD production with rather good accuracy, especially in the range from 200 L/h to 400 L/h for that energy supply. Furthermore, the ANN model could enlarge the predictions within a wider range of temperature drops and mass flow rates, corresponding to the typical operation of a PGMD only supplied by solar energy.

ANN Application
In order to demonstrate that this ANN model could really improve simulation results, experimental data from 24 July 2017 were used again to compare the linear regression model previously studied, the new predictions from the ANN model, as well as the real production of that day. Figure 13 shows that the linear regression (red line) did not accurately forecast the measured production (blue line). The total fresh water production measured that day was 32.43 L, and the linear regression computed 51.06 L, which implies 58% error for the total production. On the other hand, it can be seen that the ANN model fits the real data better (grey line): total production computed was 31.42 L, having only a difference of 1.01 L (3% of error). Major differences were found at the start-up of the PGMD unit, in which the pilot unit is more sensitive than the ANN or regression models to physical phenomena of thermal inertia, being the only time that real values are lower than those predicted by the ANN. At this point, it is important to remember that the final aim of this paper is to improve the previous simulation model. A new PGMD model has been implemented in the simulation to give a PGMD forecast production, thus substituting the existing model based on the simple linear regression. Figure 14 shows the PGMD production (grey line) obtained by the PGMD model based on the ANN that uses as input parameters the internal values obtained by the simulation of the complete trigeneration unit. Of course, the new prediction is better than the first estimation based on the linear

ANN Application
In order to demonstrate that this ANN model could really improve simulation results, experimental data from 24 July 2017 were used again to compare the linear regression model previously studied, the new predictions from the ANN model, as well as the real production of that day. Figure 13 shows that the linear regression (red line) did not accurately forecast the measured production (blue line). The total fresh water production measured that day was 32.43 L, and the linear regression computed 51.06 L, which implies 58% error for the total production. On the other hand, it can be seen that the ANN model fits the real data better (grey line): total production computed was 31.42 L, having only a difference of 1.01 L (3% of error). Major differences were found at the start-up of the PGMD unit, in which the pilot unit is more sensitive than the ANN or regression models to physical phenomena of thermal inertia, being the only time that real values are lower than those predicted by the ANN.

ANN Application
In order to demonstrate that this ANN model could really improve simulation results, experimental data from 24 July 2017 were used again to compare the linear regression model previously studied, the new predictions from the ANN model, as well as the real production of that day. Figure 13 shows that the linear regression (red line) did not accurately forecast the measured production (blue line). The total fresh water production measured that day was 32.43 L, and the linear regression computed 51.06 L, which implies 58% error for the total production. On the other hand, it can be seen that the ANN model fits the real data better (grey line): total production computed was 31.42 L, having only a difference of 1.01 L (3% of error). Major differences were found at the start-up of the PGMD unit, in which the pilot unit is more sensitive than the ANN or regression models to physical phenomena of thermal inertia, being the only time that real values are lower than those predicted by the ANN. At this point, it is important to remember that the final aim of this paper is to improve the previous simulation model. A new PGMD model has been implemented in the simulation to give a PGMD forecast production, thus substituting the existing model based on the simple linear regression. Figure 14 shows the PGMD production (grey line) obtained by the PGMD model based on the ANN that uses as input parameters the internal values obtained by the simulation of the complete trigeneration unit. Of course, the new prediction is better than the first estimation based on the linear At this point, it is important to remember that the final aim of this paper is to improve the previous simulation model. A new PGMD model has been implemented in the simulation to give a PGMD forecast production, thus substituting the existing model based on the simple linear regression. Figure 14 shows the PGMD production (grey line) obtained by the PGMD model based on the ANN that uses as input parameters the internal values obtained by the simulation of the complete trigeneration unit. Of course, the new prediction is better than the first estimation based on the linear regression type (see Section 2.2), but it does not follow the same accuracy as that of the proper ANN fitting model ( Figure 13).
Water 2018, 10, x FOR PEER REVIEW 16 of 20 regression type (see Section 2.2), but it does not follow the same accuracy as that of the proper ANN fitting model ( Figure 13). At this point, it is important to remember that the simulation presented in [7] involved several subsystems (solar loop, Sanitary Hot Water (SHW) loop, electric package, and fresh water loop). The PGMD could be considered as the last subsystem of the trigeneration unit, thus thermal energy required to its activation hardly depends on the efficiency of solar energy transformation, the SHW demands and the heat transfer effectiveness in the storage tank and the HX Tank-MD. Nevertheless, the new type based on the ANN clearly improved the simulation results by estimating the production as 37.93 L for that day, which is a 17% error from the real measured data. Since the ANN model only presented a 3% error, it can be assumed that 14% error comes from simulator estimations (use of meteorological databases, assuming constant efficiency parameters in devices, time step approximation errors, etc.).
This means that by combining the use of the ANN model with a dynamic simulator, an improvement of 41% in the PGMD production could be obtained, that is, error in the PGMD prediction is reduced by more than 70% in the complete trigeneration scheme.

Discussion
The ANN model based in three measured parameters of the PGMD unit has been validated with data from the experimental facility as presented in Figure 9 (fourth graphic) and Figure 11. Another validation to demonstrate the wide inlet ranges to apply the ANN is presented in Figure 12, in which some partial comparison with results from [13] can also be seen. When compared with experimental data, the ANN model has proved to predict accurate results of the distillate produced: 3% was the average error found. For instance, only an underestimation of 1.01 liters per day has been found for a typical day test in the summer period (24 July 2017). This model has also been included in a simulation tool where the results have been improved if compared with the first attempt, i.e., a PGMD type based on the linear regression model extracted from the manufacturer [48]. This is a considerable improvement since the original linear regression model overestimated the production by more than 19 L that day. This means that simulations combined with ANN clearly increased the accuracy of the PGMD production by the software. The error of the simulation with respect to the PGMD production was decreased from 58% to 17%; thus, PGMD prediction in the simulator was reduced by up to 41% on the selected day for the analysis.

Conclusions
In this work, distillate provided by a PGMD was reproduced by means of an artificial neural network (ANN). As a black-box model, the ANN tried to improve the predictions first made by a linear regression model, which clearly were overestimated when compared with experimental data taken from the field tests. The ANN model is based on three inlet measured parameters of the PGMD At this point, it is important to remember that the simulation presented in [7] involved several subsystems (solar loop, Sanitary Hot Water (SHW) loop, electric package, and fresh water loop). The PGMD could be considered as the last subsystem of the trigeneration unit, thus thermal energy required to its activation hardly depends on the efficiency of solar energy transformation, the SHW demands and the heat transfer effectiveness in the storage tank and the HX Tank-MD. Nevertheless, the new type based on the ANN clearly improved the simulation results by estimating the production as 37.93 L for that day, which is a 17% error from the real measured data. Since the ANN model only presented a 3% error, it can be assumed that 14% error comes from simulator estimations (use of meteorological databases, assuming constant efficiency parameters in devices, time step approximation errors, etc.).
This means that by combining the use of the ANN model with a dynamic simulator, an improvement of 41% in the PGMD production could be obtained, that is, error in the PGMD prediction is reduced by more than 70% in the complete trigeneration scheme.

Discussion
The ANN model based in three measured parameters of the PGMD unit has been validated with data from the experimental facility as presented in Figure 9 (fourth graphic) and Figure 11. Another validation to demonstrate the wide inlet ranges to apply the ANN is presented in Figure 12, in which some partial comparison with results from [13] can also be seen. When compared with experimental data, the ANN model has proved to predict accurate results of the distillate produced: 3% was the average error found. For instance, only an underestimation of 1.01 liters per day has been found for a typical day test in the summer period (24 July 2017). This model has also been included in a simulation tool where the results have been improved if compared with the first attempt, i.e., a PGMD type based on the linear regression model extracted from the manufacturer [48]. This is a considerable improvement since the original linear regression model overestimated the production by more than 19 L that day. This means that simulations combined with ANN clearly increased the accuracy of the PGMD production by the software. The error of the simulation with respect to the PGMD production was decreased from 58% to 17%; thus, PGMD prediction in the simulator was reduced by up to 41% on the selected day for the analysis.

Conclusions
In this work, distillate provided by a PGMD was reproduced by means of an artificial neural network (ANN). As a black-box model, the ANN tried to improve the predictions first made by a linear regression model, which clearly were overestimated when compared with experimental data taken from the field tests. The ANN model is based on three inlet measured parameters of the PGMD unit, and it has been validated with data from the experimental facility. In the case of the electric tests, the PGMD worked alone under steady experimental conditions. In the case of solar tests, the complete trigeneration unit was operating by consuming solar and wind energy. It is obvious that experimental conditions hardly depend on weather conditions, but thermal energy was stored in a water tank and provided quasi-static conditions to the PGMD unit operation. Those different experimental datasets allowed us to consecutively improve the ANN model performance. Results from the ANN model presented were compared to experimental data of the real trigeneration facility. The performance of the ANN based on all data, that is, using both electric and solar data sets, was substantially better than conventional linear regression. Furthermore, since this ANN model does not depend on the heat supply conditions, that is, it does not use any parameter regarding the heat source (for instance, the flow rate or the temperature drop on the hot side of the HX feeding the PGMD), it can be used for predicting the production behavior for a wide range of operational conditions and energy resources.
To conclude, it is important to remark that its exportable matrix model makes the ANN an excellent option for accurate modelling and real-time optimization in complex systems. Here, the usefulness of the ANN was materialized by improving the complete simulation of a trigeneration scheme based on the unique supply of RES. In this manner, if the adequate prediction of PGMD is available, its fair contribution with respect to the RO production to cover the water demands in this scheme could be found. In this way, the scale-up of this trigeneration scheme with the simulator could be finely used in the search of sustainable management of the decentralized supply of water, electricity and SHW for larger communities in remote and water-scarce areas.