Chan Kha Vu
Chan Kha Vu

Reputation: 10390

C++ support vector machine (SVM) template libraries?

I have a dataset from custom abstract objects and a custom distance function. Is there any good SVM libraries that allows me to train on my custom objects (not 2d points) and my custom distance function?

I searched the answers in this similar stackoverflow question, but none of them allows me to use custom objects and distance functions.

Upvotes: 0

Views: 713

Answers (2)

banach_tarski
banach_tarski

Reputation: 31

Check out the following:

  • MLPack: a lightweight library that provides lots of functionality.
  • DLib: a very popular toolkit that is used both in industry and academia.

Apart from these, you can also use Python packages, but import them from C++.

Upvotes: 3

lejlot
lejlot

Reputation: 66775

First things first.

SVM does not work on distance functions, it only accepts dot products. So your distance function (actually similarity, but usually 1-distance is similarity) has to:

  • be symmetric s(a,b)=s(b,a)
  • be positive definite s(a,a)>=0, s(a,a)=0 <=> a=0
  • be linear in first argument s(ka, b) = k s(a,b) and s(a+b,c) = s(a,c) + s(b,c)

This can be tricky to check, as you actually ask "is there a function from my objects to some vector space, phi such that s(phi(x), phi(y))" is a dot-product, thus leading to definition of so called kernel, K(x,y)=s(phi(x), phi(y)). If your objects are themselves elements of vector space, then sometimes it is enough to put phi(x)=x thus K=s, but it is not true in general.

Once you have this kind of similarity nearly any SVM library (for example libSVM) works with providing Gram matrix. Which is simply defined as

G_ij = K(x_i, x_j)

Thus requiring O(N^2) memory and time. Consequently it does not matter what are your objects, as SVM only works on pairwise dot-products, nothing more.

If you look appropriate mathematical tools to show this property, what can be done is to look for kernel learning from similarity. These methods are able to create valid kernel which behaves similarly to your similarity.

Upvotes: 3

Related Questions