-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
the problem of generating expression of Strongly Typed GP #579
Comments
I believe this issue comes from predetermined tree depth that is trying to be filled out. A workaround in the mean time is to add a pass through primitive:
|
Thank you for reply, I used the method to avoid the problem, but this led the expressions to be redundant, and not graceful. |
Yes but logically it does not make sense to ask the program to build full trees if for some non-leave it is impossible to find an other non-leave if the required type. I guess there could be a tree generation utility that allows for it ... |
Hi @liningbo, have you figured out how to avoid this problem? |
@BrandonDotLin I just do as jasonzutty said, make a function to return a int value equal to the input of the function. |
while len(stack) != 0:
depth, type_ = stack.pop()
if condition(height, depth) or len(pset.primitives[type_]) == 0:
try:
term = random.choice(pset.terminals[type_])
except IndexError:
_, _, traceback = sys.exc_info()
raise IndexError("The gp.generate function tried to add "
"a terminal of type '%s', but there is "
"none available." % (type_,)).with_traceback(traceback)
if isclass(term):
term = term()
expr.append(term) you can add some code to |
Hope this pull request can be merged ASAP. |
This cannot be merged as it breaks the logic of a full tree. |
version : 1.2
problem: deap can not add terminal when primitive set has not suitable type but terminal set has.
example:
pset = gp.PrimitiveSetTyped('main', [], pd.DataFrame)
pset.addPrimitive(func1, [pd.DataFrame, pd.DataFrame], pd.DataFrame)
pset.addPrimitive(func2, [pd.DataFrame,int], pd.DataFrame)
pset.addTerminal(terminal=pd.DataFrame(), ret_type=pd.DataFrame,name='t1')
pset.addTerminal(1, int, name=str(1))
expr = gp.genFull(pset, min_=1, max_=10)
tree = gp.PrimitiveTree(expr)
print(str(tree))
the code will the error:
IndexError: The gp.generate function tried to add a primitive of type '<class 'int'>', but there is none available.
I think though primitive set has not the function which will return int, but the terminal set has the constant of type int. so deap should add terminal of type int into the expression but not raise error.
The text was updated successfully, but these errors were encountered: