## 3 Methodology
### Genetic Algorithm for the Parameter Estimation  
A general block diagram of the proposed methodology is presented in Figure 1. First, a GA scheme is used for the active power forecasting of a PV inverter. This scheme requires the following inputs: sun irradiance, cell temperature, DC voltage, DC current, an active power signal, and the non-parameterized mathematical model, which works as the objective function. These descriptive parameters are selected considering that PV panels deliver energy in DC levels depending on the environmental factors. The objective function for this task is presented in (4). This mathematical model is selected because it is observed that the relationship between the solar irradiance and the active power tends to be proportional [31; 32]. \[P_{i}=w_{1}x_{1,i}+w_{2}x_{2,i}+w_{3}x_{3,i}+w_{4}x_{4,i}, \tag{4}\]  
where \(P_{i}\) is the \(i\)-th value of the estimated active power;  
\(x_{1,i}\) is the \(i\)-th value of the sun irradiance;  
\(x_{2,i}\) is the \(i\)-th value  
Every weight in (4) specifies the level of contribution of each variable in the description of the behavior at the response function. It must be said that the relationship between the descriptive parameters and the obtained result is not linear in all cases, but in this work, we propose to develop a model that linearizes this relationship in order to allow for a simple solution to the problem. It is clear that this situation introduces an error in the estimation; however, the GA must be able to find the weights that minimize this error in order to obtain accurate results. Once all the inputs have been defined, the next step consisted of the initialization of the GA. For this particular case, the parameters that must be defined by the GA are \(w_{1}\), \(w_{2}\), \(w_{3}\), and \(w_{4}\). Therefore, a random initial population of 50 individuals is generated for each weight, this way a good design space distribution is ensured. This is followed by an evaluation of the population, which consists of substituting the value of each individual on the objective function and determining the error with respect to the active power signal. Subsequently, a selection process is carried out. For this process, the obtained error for each individual is used to organize them from the best fitting (the individual with the least error) to the worst fitting (the individual with the highest error). At this point, it is necessary to evaluate if the stop criterion has been reached; hence, the best fitting individual is taken as the solution. Otherwise, it is necessary to generate a new population. In this work the stop criterion is a maximum number of epochs set as 500, because it is experimentally observed that this number ensures the best convergence of the model parameters. To generate the new population, the individual with the lowest error is preserved, in this manner, the convergence of the algorithm is granted. The rest of the individuals in the new population are obtained through two different genetic operations: the crossover and the mutation. The crossover operation consists of the average of the best fitting individual with the rest of the individuals, one at a time, as shown in (5):  
\[y_{i,new}=\frac{(y_{1}+y_{i,\ old})}{2}, \tag{5}\]  
where \(i=2,\ 3,\ \ldots,50\);  
\(y_{i,\ old}\) is the \(i\)-th individual of the old population;  
\(y_{1}\) is the best fitting individual; and  
\(y_{i,new}\) is the \(i\)-th individual of the new population. Figure 1: Block diagram of the proposed methodology. THD: Total Harmonic Distortion; \(P_{i:}\) i-th element of the Active Power; \(H_{i}\): i-th element of the harmonic distortion; \(x_{i}w_{i}\): Elements of Equation (4). The mutation operation implies a random substitution of a particular individual of the new population. The individual is substituted if a random value lies below the mutation probability (0.2 in this work) to maintain diversity in the population, but without losing valuable genetic information.