-
Notifications
You must be signed in to change notification settings - Fork 45
Pygad optimizer #616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Pygad optimizer #616
Conversation
for more information, see https://pre-commit.ci
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
|
| list[NonNegativeFloat] | ||
| tuple[NonNegativeFloat, NonNegativeFloat] | ||
| NDArray[np.float64] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the current documentation I don't understand the cases other than a scalar probability. How many entries would have to be in the list. What happens if I specify a tuple with two values? How long would the array have to be?
At the moment I am not sure if just the documentation is missing or we might need to simplify which cases are allowed.
The same comment applies to the next two options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The three parameters mutation_probability
, mutation_num_genes
, and mutation_percent_genes
support the following modes:
- Non-adaptive mutation (
mutation_type
other than"adaptive"
): Only scalar values are allowed. - Adaptive mutation (
mutation_type="adaptive"
): Only arrays/lists/tuples of length 2 are allowed.
All three parameters (mutation_probability
, mutation_num_genes
, mutation_percent_genes
) support only length-2 arrays/lists for adaptive mutation.
In the adaptive case:
- First element: Used for low-fitness solutions (fitness < average)
- Second element: Used for high-fitness solutions (fitness > average)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I think we should only support ProbabilityFloat
, None
and tuple[...]
; Not the array and list ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read your explanation a bit more carefully now: We want to avoid a situation like this where the value of one argument determines which type is valid for another one. We also want to avoid situations where the value of one argument determines whether another argument is used or ignored.
This is the same situation we solve here by introducing configured algorithms.
Since mutation_functions
can be callables, the same solution will work.
Concretely this means:
- For every mutation function supported by pygad we introduce a callable dataclass. The attributes of the class are the options supported by that mutation function. The
__call__
method just calls the corresponding function from pygad. - If a user wants to just select a mutation function but otherwise use default values they can pass a string (as now) or a class.
- If a user wants to configure the mutation further, they need to pass an instance of the mutation functions.
- If a user wants a completely customized mutation function they can either create a subclass or follow the protocol.
- The argument
mutation_type
should then be renamed tomutation
.
Usage example for a configured mutation function:
algo = om.algos.pygad(
mutation=om.pygad.AdaptiveMutation(
probability_bad=0.3, # for low fitness values
probability_good=0.1, # for high fitness values
)
)
Name wise, we need to avoid "high" and "low" because the algorithms can be used in maximize and minimize as well as "fitness" because optimagic users know this as "fun".
Let me know if this explanation was clear, otherwise we can have a short call again. A similar solution might also be necessary for parent selection functions etc.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
This pull request introduces a genetic algorithm optimizer based on the PyGAD library.