Skip to content

MNT Cleaner cython cdef loss function in SGD - #17191

Merged
rth merged 2 commits into
scikit-learn:masterfrom
lorentzenchr:sgd_clean
May 12, 2020
Merged

rth merged 2 commits into
scikit-learn:masterfrom
lorentzenchr:sgd_clean

Conversation

@lorentzenchr

Copy link
Copy Markdown
Member

What does this implement/fix? Explain your changes.

This PR simpliefies the derivative loss functions for SGD. It makes the distinction bewtween cdef dloss() nogil: for productive use and def py_dloss(): for calls in the test suite only.

@rth

rth commented May 12, 2020

Copy link
Copy Markdown
Member

Thanks! I think,

    cpdef double dloss(self, double p, double y) nogil:

might work (and allow access from pure Python) as long as the corresponding classes are decorated with cython.final to mark them as not subclassable: https://stackoverflow.com/a/37869168/1791279 Whether it's worth it I am not sure. The current solution is also acceptable.

@lorentzenchr

Copy link
Copy Markdown
Member Author

cdef class LossFunction is subclassed and we want to test the dloss of the subclasses. I guess the @cython.final trick might not work here. (But good to know that trick!)

@rth

rth commented May 12, 2020

Copy link
Copy Markdown
Member

No I mean dloss loss is defined on subclasses, right? So that's where the final decorator could also be applied (not on the base class)..

@rth

rth commented May 12, 2020

Copy link
Copy Markdown
Member

I'm not saying that we should do it though, just that it might be possible.

Any opinions @thomasjpfan @jeremiedbb ?

@NicolasHug NicolasHug left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

One tiny perk of using the wrapper instead of cpdef is that compilation will be slightly faster compared to duplicating all methods

@rth rth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sounds good. Thanks!

@rth rth changed the title [MRG] MNT Cleaner cythn cdef loss function in SGD MNT Cleaner cythn cdef loss function in SGD May 12, 2020
@rth
rth merged commit 4b92a77 into scikit-learn:master May 12, 2020
@lorentzenchr lorentzenchr changed the title MNT Cleaner cythn cdef loss function in SGD MNT Cleaner cython cdef loss function in SGD May 12, 2020
@lorentzenchr
lorentzenchr deleted the sgd_clean branch May 12, 2020 21:13
gio8tisu pushed a commit to gio8tisu/scikit-learn that referenced this pull request May 15, 2020
viclafargue pushed a commit to viclafargue/scikit-learn that referenced this pull request Jun 26, 2020
jayzed82 pushed a commit to jayzed82/scikit-learn that referenced this pull request Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants