Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a3e1219

Browse files
Regression examples
1 parent c4aa825 commit a3e1219

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

‎docs/source/gann.rst

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ value (i.e. accuracy) of 100 is reached after around 180 generations.
535535
536536
ga_instance.plot_fitness()
537537
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
539539
:alt:
540540

541541
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
930930
931931
The next figure shows how fitness value evolves by generation.
932932

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
934934
:alt:
935935

936936
Regression Example 1
@@ -998,10 +998,10 @@ for regression.
998998
GANN_instance.update_population_trained_weights(population_trained_weights=population_matrices)
999999
10001000
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))
10031003
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()
10051005
10061006
# Holds the fitness value of the previous generation.
10071007
last_fitness = 0
@@ -1011,8 +1011,8 @@ for regression.
10111011
[8, 15, 20, 13]])
10121012
10131013
# 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]])
10161016
10171017
# The length of the input vector for each sample (i.e. number of neurons in the input layer).
10181018
num_inputs = data_inputs.shape[1]
@@ -1022,7 +1022,7 @@ for regression.
10221022
GANN_instance = pygad.gann.GANN(num_solutions=num_solutions,
10231023
num_neurons_input=num_inputs,
10241024
num_neurons_hidden_layers=[2],
1025-
num_neurons_output=1,
1025+
num_neurons_output=2,
10261026
hidden_activations=["relu"],
10271027
output_activation="None")
10281028
@@ -1071,7 +1071,7 @@ for regression.
10711071
ga_instance.plot_fitness()
10721072
10731073
# 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)
10751075
print("Parameters of the best solution : {solution}".format(solution=solution))
10761076
print("Fitness value of the best solution = {solution_fitness}".format(solution_fitness=solution_fitness))
10771077
print("Index of the best solution : {solution_idx}".format(solution_idx=solution_idx))
@@ -1092,7 +1092,7 @@ for regression.
10921092
The next figure shows how the fitness value changes for the generations
10931093
used.
10941094

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
10961096
:alt:
10971097

10981098
Regression Example 2 - Fish Weight Prediction
@@ -1164,15 +1164,15 @@ Here is the complete code.
11641164
GANN_instance.update_population_trained_weights(population_trained_weights=population_matrices)
11651165
11661166
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))
11691169
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()
11711171
11721172
# Holds the fitness value of the previous generation.
11731173
last_fitness = 0
11741174
1175-
data = numpy.array(pandas.read_csv("Fish.csv"))
1175+
data = numpy.array(pandas.read_csv("../data/Fish.csv"))
11761176
11771177
# Preparing the NumPy array of the inputs.
11781178
data_inputs = numpy.asarray(data[:, 2:], dtype=numpy.float32)
@@ -1237,7 +1237,7 @@ Here is the complete code.
12371237
ga_instance.plot_fitness()
12381238
12391239
# 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)
12411241
print("Parameters of the best solution : {solution}".format(solution=solution))
12421242
print("Fitness value of the best solution = {solution_fitness}".format(solution_fitness=solution_fitness))
12431243
print("Index of the best solution : {solution_idx}".format(solution_idx=solution_idx))
@@ -1258,5 +1258,5 @@ Here is the complete code.
12581258
The next figure shows how the fitness value changes for the 500
12591259
generations used.
12601260

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
12621262
:alt:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /