Skip to content
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

Refactor mutation probabilities #140

Merged
merged 18 commits into from
Oct 24, 2022
Merged

Conversation

MilesCranmer
Copy link
Owner

@MilesCranmer MilesCranmer commented Oct 11, 2022

Right now one specifies the mutation probabilities by passing in a long vector of floats. This is super uninterpretable, so this change fixes this. This will also be helpful for adding new mutations, like for the shared-node-utils branch.

With this change, there is now a MutationWeights struct which you can specify as, e.g.,

mutation_weights = MutationWeights(;
    mutate_constant=0.048,
    mutate_operator=0.47,
    add_node=0.79,
    insert_node=5.1,
    delete_node=1.7,
    simplify=0.0020,
    randomize=0.00023,
    do_nothing=0.21,
)

Where these numbers are the relative probability of each mutation (will be normalized afterward). This also makes the code more readable. Now, instead of doing a cumulative sum on the weights manually, and comparing to rand(), a method has been added of type rand(::MutationWeights). This will return a Symbol specifying the mutation chosen. For example:

choice = rand(mutation_weights)
# e.g., :mutate_operator, :add_node

Right now, the parameter is passed in as mutationWeights rather than mutation_weights. I'm planning to refactor all of those in the future to be consistently snake_case at some point, but not now.

@johanbluecreek or @CharFox1 would one of you be willing to take a look?
Thanks!
Miles

Copy link
Contributor

@johanbluecreek johanbluecreek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. It is nice to have a struct for the mutation probabilities instead of having to keep track of the ordering in the vector. The selection of mutation operator is now also much easier to see compared to the cumulative sum approach. I just left some comments.

src/OptionsStruct.jl Outdated Show resolved Hide resolved
src/Options.jl Outdated Show resolved Hide resolved
@MilesCranmer
Copy link
Owner Author

I feel like sample(mutations; weights=options.mutation_weightings) might be more intuitive than rand(mutation_weightings).

src/OptionsStruct.jl Outdated Show resolved Hide resolved
@MilesCranmer MilesCranmer merged commit 643dea3 into master Oct 24, 2022
@MilesCranmer MilesCranmer deleted the mutation-weight-refactor branch October 24, 2022 07:12
@MilesCranmer
Copy link
Owner Author

Thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants