📄 faq.html
字号:
< x_space[colornum * i].index = 1;
< x_space[colornum * i].value = q->x;
< x_space[colornum * i + 1].index = 2;
< x_space[colornum * i + 1].value = q->y;
< x_space[colornum * i + 2].index = -1;
< prob.x[i] = &x_space[colornum * i];
---
> x_space[3 * i].index = 1;
> x_space[3 * i].value = q->x;
> x_space[3 * i + 1].index = 2;
> x_space[3 * i + 1].value = q->y;
> x_space[3 * i + 2].index = -1;
> prob.x[i] = &x_space[3 * i];
397c390
< if(current_value > 5) current_value = 1;
---
> if(current_value > 3) current_value = 1;
</pre>
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q7:_Java_version_of_libsvm"></a>
<a name="f601"><b>Q: What is the difference between Java version and C++ version of libsvm?</b></a>
<br/>
<p>
They are the same thing. We just rewrote the C++ code
in Java.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q7:_Java_version_of_libsvm"></a>
<a name="f602"><b>Q: Is the Java version significantly slower than the C++ version?</b></a>
<br/>
<p>
This depends on the VM you used. We have seen good
VM which leads the Java version to be quite competitive with
the C++ code. (though still slower)
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q7:_Java_version_of_libsvm"></a>
<a name="f603"><b>Q: While training I get the following error message: java.lang.OutOfMemoryError. What is wrong?</b></a>
<br/>
<p>
You should try to increase the maximum Java heap size.
For example,
<pre>
java -Xmx2048m -classpath libsvm.jar svm_train ...
</pre>
sets the maximum heap size to 2048M.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q7:_Java_version_of_libsvm"></a>
<a name="f604"><b>Q: Why you have the main source file svm.m4 and then transform it to svm.java?</b></a>
<br/>
<p>
Unlike C, Java does not have a preprocessor built-in.
However, we need some macros (see first 3 lines of svm.m4).
</ul>
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q8:_Python_interface"></a>
<a name="f702"><b>Q: On MS windows, why does python fail to load the pyd file?</b></a>
<br/>
<p>
It seems the pyd file is version dependent. So far we haven't
found out a good solution. Please email us if you have any
good suggestions.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q8:_Python_interface"></a>
<a name="f703"><b>Q: How to modify the python interface on MS windows and rebuild the .pyd file ?</b></a>
<br/>
<p>
To modify the interface, follow the instructions given in
<a href=
http://www.swig.org/Doc1.3/Python.html#Python>
http://www.swig.org/Doc1.3/Python.html#Python
</a>
<p>
If you just want to build .pyd for a different python version,
after libsvm 2.5, you can easily use the file Makefile.win.
See details in README.
Alternatively, you can use Visual C++. Here is
the example using Visual Studio .Net 2005:
<ol>
<li>Create a Win32 DLL project and set (in Project->$Project_Name
Properties...->Configuration) to "Release."
About how to create a new dynamic link library, please refer to
<a href=http://msdn2.microsoft.com/en-us/library/ms235636(VS.80).aspx>http://msdn2.microsoft.com/en-us/library/ms235636(VS.80).aspx</a>
<li> Add svm.cpp, svmc_wrap.c, pythonXX.lib to your project.
<li> Add the directories containing Python.h and svm.h to the Additional
Include Directories(in Project->$Project_Name
Properties...->C/C++->General)
<li> Add __WIN32__ to Preprocessor definitions (in
Project->$Project_Name Properties...->C/C++->Preprocessor)
<li> Set Create/Use Precompiled Header to Not Using Precompiled Headers
(in Project->$Project_Name Properties...->C/C++->Precompiled Headers)
<li> Build the DLL.
<li> You may have to rename .dll to .pyd
</ol>
<!--
There do exist work arounds, however. In
http://aspn.activestate.com/ASPN/Mail/Message/python-list/983252
they presented a solution: 1) find the version of python in the
registry 2) perform LoadLibrary("pythonxx.dll") and 3) resolve the
reference to functions through GetProcAddress. It is said that SWIG
may help on this.
http://mailman.cs.uchicago.edu/pipermail/swig/2001-July/002744.html
presented a similar example.
-->
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q8:_Python_interface"></a>
<a name="f704"><b>Q: Except the python-C++ interface provided, could I use Jython to call libsvm ?</b></a>
<br/>
<p> Yes, here are some examples:
<pre>
$ export CLASSPATH=$CLASSPATH:~/libsvm-2.4/java/libsvm.jar
$ ./jython
Jython 2.1a3 on java1.3.0 (JIT: jitc)
Type "copyright", "credits" or "license" for more information.
>>> from libsvm import *
>>> dir()
['__doc__', '__name__', 'svm', 'svm_model', 'svm_node', 'svm_parameter',
'svm_problem']
>>> x1 = [svm_node(index=1,value=1)]
>>> x2 = [svm_node(index=1,value=-1)]
>>> param = svm_parameter(svm_type=0,kernel_type=2,gamma=1,cache_size=40,eps=0.001,C=1,nr_weight=0,shrinking=1)
>>> prob = svm_problem(l=2,y=[1,-1],x=[x1,x2])
>>> model = svm.svm_train(prob,param)
*
optimization finished, #iter = 1
nu = 1.0
obj = -1.018315639346838, rho = 0.0
nSV = 2, nBSV = 2
Total nSV = 2
>>> svm.svm_predict(model,x1)
1.0
>>> svm.svm_predict(model,x2)
-1.0
>>> svm.svm_save_model("test.model",model)
</pre>
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q8:_Python_interface"></a>
<a name="f705"><b>Q: How could I install the python interface on Mac OS? </b></a>
<br/>
<p> Instead of
LDFLAGS = -shared
in the Makefile, you need
<pre>
LDFLAGS = -framework Python -bundle
</pre>
<!--
LDFLAGS = -bundle -flat_namespace -undefined suppress
-->
The problem is that under MacOs there is no "shared libraries."
Instead they use "dynamic libraries."
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q8:_Python_interface"></a>
<a name="f706"><b>Q: I typed "make" on a unix system, but it says "Python.h: No such file or directory?"</b></a>
<br/>
<p>
Even though you may have python on your
system, very likely
python development tools
are not installed. Please check with
your system administrator.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q9:_MATLAB_interface"></a>
<a name="f801"><b>Q: I compile the MATLAB interface without problem, but why errors occur while running it?</b></a>
<br/>
<p>
Your compiler version may not be supported/compatible for MATLAB.
Please check <a href=http://www.mathworks.com/support/compilers/current_release>this MATLAB page</a> first and then specify the version
number. For example, if g++ X.Y is supported, replace
<pre>
CXX = g++
</pre>
in the Makefile with
<pre>
CXX = g++-X.Y
</pre>
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q9:_MATLAB_interface"></a>
<a name="f8011"><b>Q: On 64bit Windows I compile the MATLAB interface without problem, but why errors occur while running it?</b></a>
<br/>
<p>
If you use Microsoft Visual Studio,
probabally it is not properly installed.
See the explanation
<a href=http://www.mathworks.com/support/compilers/current_release/win64.html#n7>here</a>.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q9:_MATLAB_interface"></a>
<a name="f802"><b>Q: Does the MATLAB interface provide a function to do scaling?</b></a>
<br/>
<p>
It is extremely easy to do scaling under MATLAB.
The following one-line code scale each feature to the range
of [0.1]:
<pre>
(data - repmat(min(data,[],1),size(data,1),1))*spdiags(1./(max(data,[],1)-min(data,[],1))',0,size(data,2),size(data,2))
</pre>
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q9:_MATLAB_interface"></a>
<a name="f803"><b>Q: How could I use MATLAB interface for parameter selection?</b></a>
<br/>
<p>
One can do this by a simple loop.
See the following example:
<pre>
bestcv = 0;
for log2c = -1:3,
for log2g = -4:1,
cmd = ['-v 5 -c ', num2str(2^log2c), ' -g ', num2str(2^log2g)];
cv = svmtrain(heart_scale_label, heart_scale_inst, cmd);
if (cv >= bestcv),
bestcv = cv; bestc = 2^log2c; bestg = 2^log2g;
end
fprintf('%g %g %g (best c=%g, g=%g, rate=%g)\n', log2c, log2g, cv, bestc, bestg, bestcv);
end
end
</pre>
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q9:_MATLAB_interface"></a>
<a name="f8031"><b>Q: I use MATLAB parallel programming toolbox on a multi-core environment for parameter selection. Why the program is even slower?</b></a>
<br/>
<p>
Fabrizio Lacalandra of University of Pisa reported this issue.
It seems the problem is caused by the screen output.
If you disable the <b>info</b> function
using <pre>#if 0,</pre> then the problem
may be solved.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q9:_MATLAB_interface"></a>
<a name="f804"><b>Q: How could I generate the primal variable w of linear SVM?</b></a>
<br/>
<p>
Assume you have two labels -1 and +1.
After obtaining the model from calling svmtrain,
do the following to have w and b:
<pre>
w = model.SVs' * model.sv_coef;
b = -model.rho;
if model.Label(1) == -1
w = -w;
b = -b;
end
</pre>
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q9:_MATLAB_interface"></a>
<a name="f805"><b>Q: Is there an OCTAVE interface for libsvm?</b></a>
<br/>
<p>
Yes, after libsvm 2.86, the matlab interface
works on OCTAVE as well. Please type
<pre>
make octave
</pre>
for installation.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<p align="middle">
<a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm">LIBSVM home page</a>
</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -