trevorstephens / gplearn

Genetic Programming in Python, with a scikit-learn inspired API
http://gplearn.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.59k stars 281 forks source link

More Flexibility in User Defined Measure Function #37

Closed chenyuan920911 closed 7 years ago

chenyuan920911 commented 7 years ago

I was trying to use a self defined fitness function. Actually, my measure function won't use the y_true or w at all. Instead of using metrics that compares the difference between y_true and y_pred, I measure the fitness of individuals by feeding the y_pred into some other function(which would spit out a float) and get the returned values as fitness.

I think the following can be improved: 1) the measure function's arguments will not always be (y, y_pred, w), it could be more flexible and generalized. 2) the way you check if a np.float is returned by the function. I was searching for better ways of checking returned types in python, but didn't get satisfying results yet. It was actually quite tricky.

Thanks for your work on genetic programming. It's awesome and really easy to understand and use.

I'll be rather happy to help you improve this fantastic tool. There are much more can be added, things like selection function, mutation function, even user defined selection function, mutation function etc.

trevorstephens commented 7 years ago

Thanks for the suggestion @chenyuan920911 ... But I am having a hard time understanding your use case. Can you give a specific example?

The function must take these arguments in the specified order, but the function itself doesn't necessarily have to use them... So long as it returns a numeric type for the program's fitness you should be fine.

On the return type, the function only checks to ensure a numeric is returned, does not have to be a np object, or even floating point... Can you provide an example of what you're trying to achieve?

chenyuan920911 commented 7 years ago

Hi Travis,

I couldn't tell more about this since it relates to my work. But I can tell you that I am not using things like 'Mse'. And my y_pred has a fixed length (actually it could be in other lengths, but I have to speed thing up. One way I came up with was to cache some values that will be calculated again and again during the evolution. So y_pred has to be in a different than no.array([[2,2],[2,2]]).

Thanks!

Sent from my iPhone

On Jun 16, 2017, at 21:24, Trevor Stephens notifications@github.com wrote:

Thanks for the suggestion @chenyuan920911 ... But I am having a hard time understanding your use case. Can you give a specific example?

The function must take these arguments in the specified order, but the function itself doesn't necessarily have to use them... So long as it returns a numeric type for the program's fitness you should be fine.

On the return type, the function only checks to ensure a numeric is returned, does not have to be a np object, or even floating point... Can you provide an example of what you're trying to achieve?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

trevorstephens commented 7 years ago

Sorry but without a tangible example I can't really understand your requirements. If you wish you can always open a PR with something that solves the problem, but without an example I don't know what the problem is. Closing for now.