Skip to content

Bug Report In _evaluate_fitness function #3

@gxlover0625

Description

@gxlover0625

Hello, thanks to your wonderful work PromptBreeder in prompt-optimization area.
When I ran the code, I felt confused about the _evaluate_fitness function. After carefully reviewing the code, I found that the following part has issues.

if unit.fitness > elite_fitness:
# I am copying this bc I don't know how it might get manipulated by future mutations.
unit = population.units[unit_index]
current_elite = unit.model_copy()
elite_fitness = unit.fitness

I found others' questions about this part in the issue and submitted a PR. #1
However, I noticed that the change is incorrect, since unit, being a local variable, is referenced before declaration. It first appears in the for loop on line 102.

for unit in population.units:

To obtain the best elites, all instances of unit should be replaced with population.units[unit_index].
Here is my code:

if population.units[unit_index].fitness > elite_fitness:
    current_elite = population.units[unit_index].model_copy()
    elite_fitness = population.units[unit_index].fitness

I believe my changes may address the issue correctly and follow the original paper’s design. If you agree, I’d be happy to submit a PR. Your feedback is greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions