gplearn icon indicating copy to clipboard operation
gplearn copied to clipboard

Custom Feature with specified input type

Open jeremytanjianle opened this issue 5 years ago • 6 comments

Hi I'd like to create a custom function that only takes 1 array and 1 constant specifically. For example, a function that changes it to +1 / -1 depending on the constant threshold:

def binary_thresh_(x_array, thresh):
    solution = np.zero(x.shape)

    solution [x_array<thresh] = -1
    solution [x_array>=thresh] = 1
    return(solution)

binary_thresh= make_function(function=binary_thresh_, name='binary_thresh', arity=2)

Just would like to check if this is already possible. Thanks.

jeremytanjianle avatar Jun 02 '19 14:06 jeremytanjianle

I assume here that you want to fix thresh to be a constant and x_array to be a column from your input data? Presently this is not possible as the inputs to any function can be any of variable, constant or another function.

trevorstephens avatar Jun 03 '19 00:06 trevorstephens

@trevorstephens Is there any possible to constrain the thresh not to be a constant?

xiaoxiaoyaozi avatar Jul 12 '19 03:07 xiaoxiaoyaozi

As above, you cannot presently constrain input types, be that for inclusion or exclusion.

trevorstephens avatar Jul 12 '19 03:07 trevorstephens

@trevorstephens I custom some functions that require the last input is an integer. Every time I got a new list of program, I pruning it to a standard type. Before call the custom function, I add the integer I need to the program list. Everything seems perfect if I run the whole codes in single one core of CPU. When I tried to run it in more cores. things go well in the first generation, however, from second generation, the custom function just cannot get the last input. Do you have any ideas or suggestions about it?

otthqs avatar Aug 16 '19 11:08 otthqs

I custom some functions that require the last input is an integer.

Not sure how you would do that in the current implementation @otthqs ... Anyhow, without some code I cannot help. Open a new issue and include a short, self contained example so that I can understand what you are referring to.

trevorstephens avatar Aug 17 '19 10:08 trevorstephens

Thanks for your response @trevorstephens . I have already fix it.

Again, thanks for your contribution of gplearn package!

otthqs avatar Aug 19 '19 09:08 otthqs