While I was learning how to adjust the weights of the mutations, my Python kernel was dying due to a segmentation fault. This pull request fixes that and also has some minor fixes and comments as well.
The segmentation fault was occurring in get_op_with_arg. The function takes the argument and return type to match, and returns a compatible operator to be inserted in the tree.
However, in the previous implementation (code above), the max_size restriction that I added would ignore all operators in rare cases, making the select_random iterate over an empty collection (this was hard to find :sweat_smile: ). For example, if max_arg_count=1, and the compatible nodes have node.get_arg_count()>1, then no node would be selected, and select_randomly would create a segmentation fault.
To fix that, I made the insert mutation behave like PTC2 by relaxing the size limit control of the programs. Now the get_op_with_arg will avoid creating an empty collection, and the insert_mutation can create a program that exceeds the maximum size by the highest arity among the operators.
Other improvements:
improved how mutation handles the max_depth restriction;
rename weight_map to node_weights, so it is more similar to the way we refer to terminal weights;
While I was learning how to adjust the weights of the mutations, my Python kernel was dying due to a segmentation fault. This pull request fixes that and also has some minor fixes and comments as well.
The segmentation fault was occurring in
get_op_with_arg
. The function takes the argument and return type to match, and returns a compatible operator to be inserted in the tree.https://github.com/cavalab/brush/blob/546c2a792c9bdfc8358dbb84e6bb2f90a3f71ee6/src/search_space.h#L382-L430
However, in the previous implementation (code above), the
max_size
restriction that I added would ignore all operators in rare cases, making theselect_random
iterate over an empty collection (this was hard to find :sweat_smile: ). For example, ifmax_arg_count=1
, and the compatible nodes havenode.get_arg_count()>1
, then no node would be selected, andselect_randomly
would create a segmentation fault.To fix that, I made the insert mutation behave like PTC2 by relaxing the size limit control of the programs. Now the
get_op_with_arg
will avoid creating an empty collection, and theinsert_mutation
can create a program that exceeds the maximum size by the highest arity among the operators.Other improvements:
max_depth
restriction;weight_map
tonode_weights
, so it is more similar to the way we refer to terminal weights;