4.3. GA-BP Algorithm Model
The training process of the BP neural network is susceptible to the problem of becoming trapped in local minima. This paper proposes integrating GA with the neural network to optimize the BP neural network. The objective is to establish a prediction model for SOFC output power based on GA-BP. This method utilizes the global search capability of GA to optimize the initial weights and thresholds, thereby overcoming these limitations. The flowchart depicting the GA-BP algorithm is presented in
Figure 5 The specific steps are as follows [
36]:
For GA, there are two common types of encoding, namely real number encoding and binary encoding. The binary encoding method is computationally intensive as it requires frequent encoding and decoding operations. It also has the significant disadvantage of being prone to the Hamming Cliff, which makes the cross and mutation operation difficult. Therefore, the real number encoding method is selected for the GA of the SOFC system output power prediction model.
- 2.
Population initialization
Population initialization is the process of creating an initial group of individuals that serve as the initial population for an algorithm prior to its execution. This procedure involves the establishment of the size of the population, the determination of the evolution times, the determination of the generation gap between the parent strings and their offspring strings, and the determination of the probabilities of both crossover and mutation at the individual level. Individuals are potential solutions for a given problem. In this experiment, the individuals are represented by chromosome strings in real coding form and can undergo operations such as crossover, mutation, and selection. By calculating the fitness value of individuals, individuals with smaller errors can be found. Subsequently, the weights and thresholds are assigned to the BP neural network.
- 3.
Initialize the BP neural network model
This paper utilizes a neural network model comprising three layers. The selection of the number of neurons in each layer is determined through an analysis of the training data set from the SOFC system. Empirical Equation (1) determines the number of neurons in the hidden layer:
In the Equation, k denotes the quantity of neurons present in the hidden layer. m represents the quantity of neurons in the input layer, that is, the number of parameters considered as input parameters in the SOFC system data. Similarly, n represents the quantity of neurons in the output layer, that is, the number of parameters considered as output parameters in the SOFC system data. Additionally, the variable l is a constant value that is constrained within the range [0, 1].
- 4.
Designing the Fitness Function
The GA relies on fitness functions to optimize and assess data. Consequently, the efficacy of GA is intricately linked to the construction of the fitness function. Since the probability of survival is determined by the fitness function, it is imperative that its value is positive, thereby promoting competition among individuals. Typically, the fitness value function is designed based on the optimization objective function. Since the SOFC output power prediction model requires the prediction output to have high accuracy, the objective function chosen for this experiment is the MSE between the predicted values and the true values. The MSE function is represented by Equation (2):
In the Equation, the variable n is the number of training samples. The variables yi and oi represent the actual value of the neurons and the predicted output of the neurons, respectively. In the output power prediction model of the SOFC system, yi is the true value of SOFC system output power, and oi is the predicted value of the output power. Additionally, the coefficient k is defined as 1/n.
Since the GA selects individuals with higher fitness function values, the fitness value function uses the reciprocal of the mean square error. This is shown in Equation (3):
In this way, individuals with higher fitness values are those with smaller mean square error functions, so the population can evolve towards better values.
- 5.
Selection operation
The primary aim of the selection operation is to identify and select individuals with superior traits that can be transmitted to future generations through the operation of crossover and mutation, either directly or indirectly. In determining the selection operation, the fitness of individuals is a crucial factor in the output power prediction model of the SOFC system. The likelihood of selection is positively correlated with a higher fitness. Individuals who possess lower fitness are more susceptible to being eliminated. The relative fitness is defined using the roulette wheel method. This is shown in Equation (4):
Among them, p(xi) is the relative fitness of individual xi, which indicates the probability of that individual being selected. Meanwhile, f(xi) is the original fitness of an individual, and is the cumulative fitness of the population.
According to the probability of each individual’s choice, denoted as
p(
xi), the roulette wheel is divided into
N sectors. Equation (5) represents the central angle of the
i-th sector:
Then, a pointer is set on the roulette wheel. When a selection is made, one can envision a spinning roulette wheel. If the pointer points to the nth sector after the wheel stops, the individual is selected as shown in
Figure 6.
- 6.
Cross operation
Cross operation is a process in which two individuals are randomly chosen from a given population, and their chromosomes are exchanged and combined. This procedure facilitates the transmission of the favorable attributes of the parent strings to the offspring strings, resulting in the production of new individuals with superior traits. The process of performing a cross operation between the
i chromosome
ai and the
j chromosome
aj at position
r, is illustrated by Equation (6):
The equation includes a random number, represented as b, that takes on values ranging from 0 to 1.
- 7.
Mutation operation
To mitigate the risk of GA converging to a suboptimal solution within the optimization procedure, so as to improve the accuracy of SOFC system output power prediction, the incorporation of mutation is imperative to introduce variability among individuals throughout the search process. In this process,
i genes of individual
j are selected for mutation, resulting in a completely new individual, as shown in Equation (7):
In this Equation, amax and amin represent the maximum and minimum values of the gene aij, respectively. r2 represents a random number, with a value ranging between [0, 1]. g denotes the current iteration number, while Gmax represents the maximum number of evolutions. Additionally, r is another random number, with a value ranging between [0, 1].
- 8.
Calculate fitness
In order to evaluate the fitness of a new individual, it is necessary to substitute the original chromosome with a new chromosome. If the resulting fitness value satisfies the specified condition, proceed to step 9. If not, return to step 4 to continue the fitness calculation process.
- 9.
Termination criterion:
- a.
Reach the maximum number of iterations.
- b.
The current best solution has either remained unchanged or changed very little for several consecutive steps.
- c.
The algorithm has found an acceptable best solution, achieving the performance goal.
- 10.
Train
When one of the conditions in step 9 is met, the BP neural network is assigned optimized weights and thresholds. Subsequently, the network undergoes training using the training set until the set error is achieved.