@@ -535,7 +535,7 @@ value (i.e. accuracy) of 100 is reached after around 180 generations.
535
535
536
536
ga_instance.plot_fitness()
537
537
538
- .. figure :: https://user-images.githubusercontent.com/16560492/82078638-c11e0700-96e1-11ea-8aa9-c36761c5e9c7.png
538
+ .. image :: https://user-images.githubusercontent.com/16560492/82078638-c11e0700-96e1-11ea-8aa9-c36761c5e9c7.png
539
539
:alt:
540
540
541
541
By running the code again, a different initial population is created and
@@ -930,7 +930,7 @@ The number of wrong classifications is only 1 and the accuracy is
930
930
931
931
The next figure shows how fitness value evolves by generation.
932
932
933
- .. figure :: https://user-images.githubusercontent.com/16560492/82152993-21898180-9865-11ea-8387-b995f88b83f7.png
933
+ .. image :: https://user-images.githubusercontent.com/16560492/82152993-21898180-9865-11ea-8387-b995f88b83f7.png
934
934
:alt:
935
935
936
936
Regression Example 1
@@ -998,10 +998,10 @@ for regression.
998
998
GANN_instance .update_population_trained_weights(population_trained_weights = population_matrices)
999
999
1000
1000
print (" Generation = {generation} " .format(generation = ga_instance.generations_completed))
1001
- print (" Fitness = {fitness} " .format(fitness = ga_instance.best_solution()[1 ]))
1002
- print (" Change = {change} " .format(change = ga_instance.best_solution()[1 ] - last_fitness))
1001
+ print (" Fitness = {fitness} " .format(fitness = ga_instance.best_solution(pop_fitness = ga_instance.last_generation_fitness )[1 ]))
1002
+ print (" Change = {change} " .format(change = ga_instance.best_solution(pop_fitness = ga_instance.last_generation_fitness )[1 ] - last_fitness))
1003
1003
1004
- last_fitness = ga_instance.best_solution()[1 ].copy()
1004
+ last_fitness = ga_instance.best_solution(pop_fitness = ga_instance.last_generation_fitness )[1 ].copy()
1005
1005
1006
1006
# Holds the fitness value of the previous generation.
1007
1007
last_fitness = 0
@@ -1011,8 +1011,8 @@ for regression.
1011
1011
[8 , 15 , 20 , 13 ]])
1012
1012
1013
1013
# Preparing the NumPy array of the outputs.
1014
- data_outputs = numpy.array([0.1 ,
1015
- 1.5 ])
1014
+ data_outputs = numpy.array([[ 0.1 , 0.2 ],
1015
+ [ 1.8 , 1.5 ] ])
1016
1016
1017
1017
# The length of the input vector for each sample (i.e. number of neurons in the input layer).
1018
1018
num_inputs = data_inputs.shape[1 ]
@@ -1022,7 +1022,7 @@ for regression.
1022
1022
GANN_instance = pygad.gann.GANN(num_solutions = num_solutions,
1023
1023
num_neurons_input = num_inputs,
1024
1024
num_neurons_hidden_layers = [2 ],
1025
- num_neurons_output = 1 ,
1025
+ num_neurons_output = 2 ,
1026
1026
hidden_activations = [" relu" ],
1027
1027
output_activation = " None" )
1028
1028
@@ -1071,7 +1071,7 @@ for regression.
1071
1071
ga_instance.plot_fitness()
1072
1072
1073
1073
# Returning the details of the best solution.
1074
- solution, solution_fitness, solution_idx = ga_instance.best_solution()
1074
+ solution, solution_fitness, solution_idx = ga_instance.best_solution(pop_fitness = ga_instance.last_generation_fitness )
1075
1075
print (" Parameters of the best solution : {solution} " .format(solution = solution))
1076
1076
print (" Fitness value of the best solution = {solution_fitness} " .format(solution_fitness = solution_fitness))
1077
1077
print (" Index of the best solution : {solution_idx} " .format(solution_idx = solution_idx))
@@ -1092,7 +1092,7 @@ for regression.
1092
1092
The next figure shows how the fitness value changes for the generations
1093
1093
used.
1094
1094
1095
- .. figure :: https://user-images.githubusercontent.com/16560492/92948154-3cf24b00-f459-11ea-94ea-952b66ab2145.png
1095
+ .. image :: https://user-images.githubusercontent.com/16560492/92948154-3cf24b00-f459-11ea-94ea-952b66ab2145.png
1096
1096
:alt:
1097
1097
1098
1098
Regression Example 2 - Fish Weight Prediction
@@ -1164,15 +1164,15 @@ Here is the complete code.
1164
1164
GANN_instance .update_population_trained_weights(population_trained_weights = population_matrices)
1165
1165
1166
1166
print (" Generation = {generation} " .format(generation = ga_instance.generations_completed))
1167
- print (" Fitness = {fitness} " .format(fitness = ga_instance.best_solution()[1 ]))
1168
- print (" Change = {change} " .format(change = ga_instance.best_solution()[1 ] - last_fitness))
1167
+ print (" Fitness = {fitness} " .format(fitness = ga_instance.best_solution(pop_fitness = ga_instance.last_generation_fitness )[1 ]))
1168
+ print (" Change = {change} " .format(change = ga_instance.best_solution(pop_fitness = ga_instance.last_generation_fitness )[1 ] - last_fitness))
1169
1169
1170
- last_fitness = ga_instance.best_solution()[1 ].copy()
1170
+ last_fitness = ga_instance.best_solution(pop_fitness = ga_instance.last_generation_fitness )[1 ].copy()
1171
1171
1172
1172
# Holds the fitness value of the previous generation.
1173
1173
last_fitness = 0
1174
1174
1175
- data = numpy.array(pandas.read_csv(" Fish.csv" ))
1175
+ data = numpy.array(pandas.read_csv(" ../data/ Fish.csv" ))
1176
1176
1177
1177
# Preparing the NumPy array of the inputs.
1178
1178
data_inputs = numpy.asarray(data[:, 2 :], dtype = numpy.float32)
@@ -1237,7 +1237,7 @@ Here is the complete code.
1237
1237
ga_instance.plot_fitness()
1238
1238
1239
1239
# Returning the details of the best solution.
1240
- solution, solution_fitness, solution_idx = ga_instance.best_solution()
1240
+ solution, solution_fitness, solution_idx = ga_instance.best_solution(pop_fitness = ga_instance.last_generation_fitness )
1241
1241
print (" Parameters of the best solution : {solution} " .format(solution = solution))
1242
1242
print (" Fitness value of the best solution = {solution_fitness} " .format(solution_fitness = solution_fitness))
1243
1243
print (" Index of the best solution : {solution_idx} " .format(solution_idx = solution_idx))
@@ -1258,5 +1258,5 @@ Here is the complete code.
1258
1258
The next figure shows how the fitness value changes for the 500
1259
1259
generations used.
1260
1260
1261
- .. figure :: https://user-images.githubusercontent.com/16560492/92948486-bbe78380-f459-11ea-9e31-0d4c7269d606.png
1261
+ .. image :: https://user-images.githubusercontent.com/16560492/92948486-bbe78380-f459-11ea-9e31-0d4c7269d606.png
1262
1262
:alt:
0 commit comments