Skip to content

SVM sigmoid kernel fix (issue #13621) - #13718

Merged
alalek merged 9 commits into
opencv:3.4from
lochsh:svm-sigmoid-fix
Jan 31, 2019
Merged

alalek merged 9 commits into
opencv:3.4from
lochsh:svm-sigmoid-fix

Conversation

@lochsh

@lochsh lochsh commented Jan 29, 2019 •

Copy link
Copy Markdown
Contributor

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:
image

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.

buildworker:Win64 OpenCL=windows-2

@lochsh lochsh changed the title Svm sigmoid fix SVM sigmoid kernel fix Jan 29, 2019
@lochsh lochsh changed the title SVM sigmoid kernel fix SVM sigmoid kernel fix (issue #13621) Jan 29, 2019

@alalek alalek 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.

Well done! Thank you for the contribution!

Comment thread modules/ml/test/test_svmtrainauto.cpp Resolved
@alalek

alalek commented Jan 30, 2019

Copy link
Copy Markdown
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:

  • change "base" branch of this PR: master => 3.4 (use "Edit" button near PR title)
  • rebase your commits from master onto 3.4 branch. For example:
    git rebase -i --onto upstream/3.4 upstream/master
    (check list of your commits, save and quit (Esc + "wq" + Enter)
    where upstream is configured by following this GitHub guide and fetched (git fetch upstream).
  • push rebased commits into source branch of your fork (with --force option)

Note: no needs to re-open PR, apply changes "inplace". If you have some issues let us know.

@lochsh
lochsh changed the base branch from master to 3.4 January 30, 2019 12:03

@alalek alalek 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 to me! Thank you 👍

@alalek
alalek merged commit 4188980 into opencv:3.4 Jan 31, 2019
@lochsh
lochsh deleted the svm-sigmoid-fix branch January 31, 2019 15:40
@alalek alalek mentioned this pull request Feb 1, 2019
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
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.

2 participants