make requests for prim in gp.generate fall back to term if needed #53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Consider this simple gp example:
The multiplication primitive requires an int as the second argument, which can be easily satisfied by passing the EphemeralConstant 'an_int' as a terminal node. However, as currently implemented, Primitive instances expect to be able to sample randomly from either the primitives or terminals lists (depending on whether the condition check is satisfied). Because there is no Primitive that outputs an int in the above example, we then get the following exception:
This seems like undesirable behavior, in that it is possible to return a perfectly valid tree by inserting a terminal in place of a primitive (or vice versa). This can be trivially achieved with the minor change in the attached PR. The only potential downside I can see is that this will occasionally override the requested tree structure--e.g., if the user calls genFull(), it may be impossible to return a tree with equal depth at all terminal nodes while still respecting the requested data types. Still, it seems to me like it would be better to return a valid but imperfect tree (perhaps issuing a simultaneous warning) than to break down entirely under a potentially quite common use case. Thoughts?