Hi there i am currently working on a project and have started using the LIBSVM (http://www.csie.ntu.edu.tw/~cjlin/libsvm/) library for my java application to train the dataset of images with multiple dimension for each image.

I have a question regarding the svm_problem and svm_node

In the svm_problem we have the following code

package libsvm;
public class svm_problem implements java.io.Serializable
{
  public int l;
  public double[] y;
  public svm_node[][] x;
}

Am i right to say that

  • l represents the size of all the image?

  • y is the label of the image as in my case i want +1/-1

And now leads to my second question about svm_node[][]x

package libsvm;
public class svm_node implements java.io.Serializable
{
  public int index;
  public double value;
}

each svm_node from 1 to i where i is the number of my attribute are stored into each position of the array.

so for example i have a image values as follows

1 1:1.5 2:2.5 3:4.5

-1 1:1 2:2 3:3

So my int l = 3

my y will be

y[0] = 1

y[1] = -1

x[0][0].index = 1

x[0][0].value = 1.5

x[0][1].index = 2

x[0][1].value = 2.5

x[0][2].index = 3

x[0][2].value = 4.5

x[1][0].index = 1

x[1][0].value = 1

x[1][1].index = 2

x[1][1].value = 2

x[1][2].index = 3

x[1][2].value = 3

Am i right in my understanding?

有帮助吗?

解决方案

You are close.

svm_problem.l is the number of samples in the database, so in this case it will be 2.

Since libsvm uses a sparse notation, so you need to indicate when each row ends with an index of -1, for instance:

x[0][0].index = 1

x[0][0].value = 1.5

x[0][1].index = 2

x[0][1].value = 2.5

x[0][2].index = 3

x[0][2].value = 4.5

x[0][3].index = -1

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top