-
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
typed Primitive Set Index Error #219
Comments
I found out this
While adding primitiveAlleast one relation should be there for each type
and you were missing the 1st case While adding terminal / ephemeralFor all primitive you have used should atleast have one terminals for them
and you are missing the 2nd case |
So now you have to add a dummy primitive and terminal for each of the missing case
You have keep in mind that all dummy terminals and primitive shouldn't get selected.
|
This is a bug here: https://github.com/DEAP/deap/blob/master/deap/gp.py#L634 Basically it should not check the condition if either terminals or primitives are not available. Both not being available would be a legitimate error. I can make a PR for it. |
Hi,
I was trying to formulate a problem two numpy arrays as terminals and undetermined number of random floats as ephemeral constants. (these random floats are the second input for function fmul that multiples an numpy array with a float).
The tree depth is limited to 10 and I added 300 constants, however i still get the following error....
is there a way to fix it? thanks.
IndexError: The gp.generate function tried to add a primitive of type '<type 'float'>', but there is none available.
`pset = gp.PrimitiveSetTyped("MAIN", [np.ndarray, np.ndarray],np.ndarray, 2)
pset.addPrimitive(numpy.add, [np.ndarray, np.ndarray],np.ndarray, name="vadd")
pset.addPrimitive(numpy.subtract, [np.ndarray, np.ndarray] ,np.ndarray, name="vsub")
pset.addPrimitive(numpy.multiply, [np.ndarray, np.ndarray] ,np.ndarray, name="vmul")
pset.addPrimitive(numpy.multiply, [np.ndarray, float] ,np.ndarray, name="fmul")
pset.addPrimitive(numpy.negative, [np.ndarray] ,np.ndarray, name="vneg")
#adding many ephemeral constants
for i in range(300):
pset.addEphemeralConstant("rand%s"%i, lambda: random.randint(-1,1), float)
pset.renameArguments(ARG0='x')
pset.renameArguments(ARG1='y')
toolbox.register("expr", gp.genHalfAndHalf, pset=pset, min_=1, max_=10)`
The text was updated successfully, but these errors were encountered: