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.