Repository navigation
SVM sigmoid kernel fix (issue #13621) - #13718
Merged
Merged
Conversation
alalek
reviewed
Jan 30, 2019
alalek
left a comment
Member
There was a problem hiding this comment.
Well done! Thank you for the contribution!
Member
|
As a "bugfix" this patch should go into 3.4 branch first. We will merge changes from 3.4 into master regularly (weekly/bi-weekly). So, please:
Note: no needs to re-open PR, apply changes "inplace". If you have some issues let us know. |
…concentric circles
…-tanh(gamma * <x, y> + coef0)
lochsh
force-pushed
the
svm-sigmoid-fix
branch
from
January 30, 2019 12:09
b877bfa to
207c982
Compare
Merged
SavyaSanchi-Sharma
pushed a commit
to SavyaSanchi-Sharma/opencv
that referenced
this pull request
Jul 30, 2026
SVM sigmoid kernel fix (issue opencv#13621) (opencv#13718) * Added test for sigmoid case for retrieving support vectors * undo unhelpful test * add test for sigmoid SVM with data that is easily separable into two concentric circles * Update sigmoid kernel to use tanh(gamma * <x, y> + coef0) instead of -tanh(gamma * <x, y> + coef0) * remove unnecessary constraint on coef0 * cleanup * fixing inappropriate use of doubles * Add f to float literal * replace CV_Assert with ASSERT_EQ where appropriate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
resolves #13621
This pullrequest changes
tl;dr sigmoid kernel is now as it should be, removed a restriction on coef0 that I understand to be incorrect
Normally the sigmoid kernel used in SVM is:
K(x, y) = tanh(gamma * <x, y> + coef0)
But OpenCV had implemented the negative of this:
K(x, y) = -tanh(gamma * <x, y> + coef0)
The OpenCV documentation says that it should be the former.
I've fixed this and added a test to give some coverage. I chose a simple dataset that seemed well suited to the sigmoid kernel, and saw that someone else had used successfully:

When trying to replicate the gamma and coef0 values used in this example, I found that coef0 was restricted to be 0 or positive, but that isn't a necessary or sensible restriction given my understanding of the maths. Python's sci-kit learn doesn't enforce it.
I removed this restriction also.
This is my first time contributing to OpenCV and I'd appreciate feedback -- I wasn't sure if I was taking the right approach with the test, and tried to follow from what already existed.