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

ga_instance.best_solution() does not return the solution that minimizes my fitness function #281

Open
Labels
questionFurther information is requested
@24spiders

Description

As mentioned, I have constructed an instance of PyGAD along with a custom fitness function. However, PyGAD does not return the best solution - that is, I have modified my fitness function to print the loss value every time it is called. While it iterates, I can see it return values such as follows:

Solution 8, value [16. 0.24717325 0.4 ], dist 75884.1558043205

Where 'dist' is what should be minimized. These 3 parameters result in a fairly low value of dist. However, once PyGAD completes and exits, the result is output:

Optimized Parameters: [27. 0.24717325 0.4 ]
Loss Value: 5777062.193619523

This loss value is obviously larger than the one it found with solution 8 - I am wondering why it is returning an answer with such a large loss value?

Initialization:

# Execute GA
import pygad
num_generations = 10
num_parents_mating = 4
mutation_rate = 0.1
num_genes = 3 # Number of parameters to optimize
sol_per_pop = 10 # Population size
initial_population = [ [np.random.uniform(low=3, high=40), 
 np.random.uniform(low=0.1, high=0.4),
 np.random.uniform(low=0, high=1),] for i in range(num_generations)]
ga_instance = pygad.GA(num_generations=num_generations,
 num_parents_mating=num_parents_mating,
 initial_population=initial_population,
 fitness_func=calc_loss,
 mutation_percent_genes=mutation_rate,
 gene_space = [range(3,40), [0.1,0.2,0.3,0.4], [0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]],
 parallel_processing = 16,)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

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