Movatterモバイル変換


[0]ホーム

URL:


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

Index error on running GA, looks like best match idx is looked in a zero size array, what can be the reason? #67

Open
Labels
bugSomething isn't working
@Rakesh-Raushan

Description

@Rakesh-Raushan

~/pypi_local/pygad/pygad.py in run(self)
1261 self.last_generation_fitness = self.cal_pop_fitness()
1262
-> 1263 best_solution, best_solution_fitness, best_match_idx = self.best_solution(pop_fitness=self.last_generation_fitness)
1264
1265 # Appending the best solution in the current generation to the best_solutions list.

~/pypi_local/pygad/pygad.py in best_solution(self, pop_fitness)
3115 pop_fitness = self.cal_pop_fitness()
3116 # Then return the index of that solution corresponding to the best fitness.
-> 3117 best_match_idx = numpy.where(pop_fitness == numpy.max(pop_fitness))[0][0]
3118
3119 best_solution = self.population[best_match_idx, :].copy()

IndexError: index 0 is out of bounds for axis 0 with size 0

This is how I have created my GA instance before run:

num_generations = 1500num_parents_mating = 20sol_per_pop = 50num_genes = num_customersgene_type = intinit_range_low = 0init_range_high = 6gene_space= np.arange(6)parent_selection_type = "sss"keep_parents = 20crossover_type = "single_point"mutation_type = "random"mutation_num_genes= [3, 1]mutation_probability = [0.25, 0.1]mutation_percent_genes = [20,10]# create an instance of the pygad.GA class global ga_instancega_instance = pygad.GA(num_generations=num_generations,                   fitness_func=fitness_func,                   num_parents_mating=4,                       gene_space = gene_space,                   sol_per_pop=50,                   num_genes=num_genes,                    gene_type = gene_type,                   mutation_type="adaptive",                   mutation_num_genes=(3, 1),                      save_solutions= True)ga_instance.run()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp