SVM,MATLAB中点与超平面之间的距离 [英] Distance between a point and the hyperplane in SVM, MATLAB

查看:477
本文介绍了SVM,MATLAB中点与超平面之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将LIBSVM用于MATLAB.现在,我正在尝试计算点与超平面之间的距离.

I'm using LIBSVM for MATLAB. Now I'm trying to compute the the distance between a point and the hyperplane.

根据官方解决方案( http://www .csie.ntu.edu.tw/〜cjlin/libsvm/faq.html#f4151 ):

According to the official solution (http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#f4151):

距离是

|decision_value| / |w|

我们有

|w|^2 = w^Tw = alpha^T Q alpha = 2*(dual_obj + sum alpha_i). 

因此,在svm.cpp中,请找到计算双重目标值的位置(即子例程Solve()),并添加一条语句以打印w^Tw."

Thus in svm.cpp please find theplace where we calculate the dual objective value (i.e., the subroutine Solve()) and add a statement to print w^Tw."

但是我有点困惑:"svm.cpp"中有超过3,000行,计算双重目标的位置"在哪里?谁能告诉我怎么做??

But I'm a little confused: there are over 3,000 lines in 'svm.cpp', where is the 'place where we calculate the dual objective'? Could anyone tell me how to make it???

还是有其他解决方案可以计算出距超平面的距离?

Or is there any other solution to figure out the distance from hyperplane?

谢谢!

推荐答案

免责声明:这不是答案.我完全不熟悉此程序包,因此我只是在推测.我本可以在评论中输入它,但它不合适,所以在这里.

Disclaimer: This is not an answer. I am not familiar with this package at all, so I am just speculating. I would have put this in the comments, but it wouldn't fit, so here it is.

我认为您要查找的代码可能在第#行周围svm.cpp 的747,其中计算了目标值.请注意,FAQ引用了双重目标值,但是svm.cpp中未出现单词"dual".因此,如果我们假设该功能是从一开始就解决了双重问题,那么这可能会起作用:

I think that the code you are looking for might be around line #747 of svm.cpp where the objective value is computed. Note that the FAQ references the dual objective value, but the word "dual" does not appear in svm.cpp. So if we assume that the function is set up to solve the dual problem from the beginning then this might work:

// calculate objective value
{
    char buf[BUFSIZ];
    double sum_alpha = 0;

    double v = 0;
    int i;
    for(i=0;i<l;i++)
    {
        v += alpha[i] * (G[i] + p[i]);
        sum_alpha += alpha[i];
    }
    si->obj = v/2;

    vsprintf(buf,"Distance to hyperplane = %f",v+2*sum_alpha);
    (*svm_print_string)(buf);
}

我还没有编译或测试这段代码,也不知道这是否是正确的选择,因此请花大量精力来回答整个问题

I have not compiled nor tested this code, neither do I know if this is the right thing to do, so take this entire answer with a big grain of salt

这篇关于SVM,MATLAB中点与超平面之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆