简体   繁体   English

C ++支持向量机(SVM)模板库?

[英]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? 有什么好的SVM库可以让我训练自定义对象(不是2d点)和自定义距离函数吗?

I searched the answers in this similar stackoverflow question , but none of them allows me to use custom objects and distance functions. 我在类似的stackoverflow问题中搜索了答案,但是没有一个允许我使用自定义对象和距离函数。

First things first. 首先是第一件事。

SVM does not work on distance functions , it only accepts dot products . SVM 在距离功能上不起作用 ,它仅接受点积 So your distance function (actually similarity, but usually 1-distance is similarity) has to: 因此,您的距离函数(实际上是相似的,但通常1距离是相似的)必须:

  • be symmetric s(a,b)=s(b,a) 对称s(a,b)=s(b,a)
  • be positive definite s(a,a)>=0, s(a,a)=0 <=> a=0 是正定s(a,a)>=0, s(a,a)=0 <=> a=0
  • be linear in first argument s(ka, b) = ks(a,b) and s(a+b,c) = s(a,c) + s(b,c) 在第一个参数s(ka, b) = ks(a,b)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)) . 这可能很难检查,因为您实际上会问“从我的对象到某个矢量空间是否有函数phi,使得s(phi(x), phi(y)) ”是一个点积,因此导致定义所谓的内核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. 如果您的对象本身就是向量空间的元素,则有时将phi(x)=x放置为K=s就足够了,但是通常这是不正确的。

Once you have this kind of similarity nearly any SVM library (for example libSVM ) works with providing Gram matrix . 一旦具有这种相似性,几乎所有SVM库(例如libSVM )都可以提供Gram矩阵 Which is simply defined as 简称为

G_ij = K(x_i, x_j)

Thus requiring O(N^2) memory and time. 因此需要O(N^2)内存和时间。 Consequently it does not matter what are your objects, as SVM only works on pairwise dot-products , nothing more. 因此,您的对象无关紧要,因为SVM仅适用于成对的点积 ,仅此而已。

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. 这些方法能够创建行为类似于您的相似性的有效内核。

Check out the following: 查看以下内容:

  • MLPack : a lightweight library that provides lots of functionality. MLPack :提供许多功能的轻量级库。
  • DLib : a very popular toolkit that is used both in industry and academia. DLib :非常流行的工具包,可用于工业和学术界。

Apart from these, you can also use Python packages, but import them from C++. 除此之外,您还可以使用Python软件包,但可以从C ++导入它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM