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

Wrong number of arguments exceptions for fitness functions with 2 required parameters #112

Open
Labels
bugSomething isn't working
@jack89roberts

Description

@jack89roberts

I'm tryingpygad (2.16.3) for the first time , and have found the check for the number of arguments of the fitness function to be overly sensitive, e.g. I would like to be able to pass fitness functions of the following types:

Class instance functions:

importpygadclassFitness:deffitness(self,x,idx):returnsum(x)foo=Fitness()ga_instance=pygad.GA(num_generations=10,num_parents_mating=5,fitness_func=foo.fitness,sol_per_pop=10,num_genes=5,)

Incorrectly triggers an error that fitness requires 3 parameters, sincef.fit.__code__.co_argcount returns 3 (includingself). Checking withsignature instead could be an alternative:

frominspectimportsignaturelen(signature(f.fit).parameters)>>>2

Functions with additional parameters that have default values:

importpygaddeffitness(x,idx,y=3):returnsum(x)ga_instance=pygad.GA(num_generations=10,num_parents_mating=5,fitness_func=fitness,sol_per_pop=10,num_genes=5,)

Also triggers an error, butfitness can be called with 2 parameters as required. Unsure of a workaround for this one.

Is there any reason whypygad couldn't use either of these fitness functions? I'd especially like to be able to use a function of a class instance for one of my projects.

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