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

Different Solutions Sizes Every Generation #321

Unanswered
Christian-Nordentoft asked this question in Q&A
Discussion options

Hello, I am using PyGAD for my University project, and I encountered a problem today that I did not find earlier. If anyone can help me figure out the problem, thanks in advance :)

The problem I have is that the number of solutions, in each generation is different. When printing the solutions, I can see I am getting 18 solutions shown one generation, 17 in a different generation etc. Furthermore, it repeats the solutions within the generation.

The parameters I have chosen are based on wanting a convergence for two design variables within a search space, where parents are kept for the next generation and selecting parents based on which ones have the best fitness evaluation results. The code that I have used to decide the parameters of PyGAD:

num_generations = 100
sol_per_pop = 12
num_parents_mating = 4
mutation_probability = 0.5
keep_parents = 2
num_genes = 2
parent_selection_type = "sss"
crossover_type = "uniform"
mutation_type = "random"
initial_population = np.array([
[10, 1],
[100, 2],
[200, 3],
[300, 4],
[400, 5],
[500, 1],
[570, 2],
[250, 3],
[150, 4],
[350, 5],
[450, 2],
[550, 3],
])
gene_space=[range(10, 571), range(1, 6)]

def fitness_func(ga_instance, solution, solution_idx):
Objective_Function = User_Definition(Inputs)
solution_fitness = Objective_Function
print(ga_instance.generations_completed, solution_idx, solution_fitness, solution)
return solution_fitness

def callback_generation(ga_instance):
solution, solution_fitness, solution_idx = ga_instance.best_solution()
print(' ---> End of generation', ga_instance.generations_completed, ":", solution_fitness)
print(' ---> End of generation', ga_instance.generations_completed, ":", solution)

ga_instance = pygad.GA(num_generations=num_generations,
num_parents_mating=num_parents_mating,
fitness_func=fitness_func,
sol_per_pop=sol_per_pop,
num_genes=num_genes,
parent_selection_type=parent_selection_type,
crossover_type=crossover_type,
mutation_type=mutation_type,
mutation_probability=mutation_probability,
on_generation=callback_generation,
initial_population=initial_population,
gene_space=gene_space)

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

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