fangfangli / cleartk

Automatically exported from code.google.com/p/cleartk
0 stars 0 forks source link

don't require command-line libsvm or liblinear #272

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Rather than requiring the command-line libsvm, we should create an svm_problem 
from the data file and call the Java train. We can get the svm_problem loading 
code from svm_train, which looks like:

                BufferedReader fp = new BufferedReader(new FileReader(input_file_name));
                Vector<Double> vy = new Vector<Double>();
                Vector<svm_node[]> vx = new Vector<svm_node[]>();
                int max_index = 0;

                while(true)
                {
                        String line = fp.readLine();
                        if(line == null) break;

                        StringTokenizer st = new StringTokenizer(line," \t\n\r\f:");

                        vy.addElement(atof(st.nextToken()));
                        int m = st.countTokens()/2;
                        svm_node[] x = new svm_node[m];
                        for(int j=0;j<m;j++)
                        {
                                x[j] = new svm_node();
                                x[j].index = atoi(st.nextToken());
                                x[j].value = atof(st.nextToken());
                        }
                        if(m>0) max_index = Math.max(max_index, x[m-1].index);
                        vx.addElement(x);
                }

                prob = new svm_problem();
                prob.l = vy.size();
                prob.x = new svm_node[prob.l][];
                for(int i=0;i<prob.l;i++)
                        prob.x[i] = vx.elementAt(i);
                prob.y = new double[prob.l];
                for(int i=0;i<prob.l;i++)
                        prob.y[i] = vy.elementAt(i);

                if(param.gamma == 0 && max_index > 0)
                        param.gamma = 1.0/max_index;

                if(param.kernel_type == svm_parameter.PRECOMPUTED)
                        for(int i=0;i<prob.l;i++)
                        {
                                if (prob.x[i][0].index != 0)
                                {
                                        System.err.print("Wrong kernel matrix: first column must be 0:sample_serial_number\n");
                                        System.exit(1);
                                }
                                if ((int)prob.x[i][0].value <= 0 || (int)prob.x[i][0].value > max_index)
                                {
                                        System.err.print("Wrong input format: sample_serial_number out of range\n");
                                        System.exit(1);
                                }
                        }

                fp.close();

Original issue reported on code.google.com by steven.b...@gmail.com on 29 Jan 2012 at 7:32

GoogleCodeExporter commented 9 years ago
Note that this may be moot if we move forward with #161.  

Original comment by phi...@ogren.info on 12 Feb 2012 at 11:25

GoogleCodeExporter commented 9 years ago
I'm not sure Issue 161 (using jlibsvm) is such a good idea, since jlibsvm is 
still based on LIBSVM 2.88, the current version is 3.11, and it seems like 
jlibsvm hasn't been touched in a while.

Original comment by steven.b...@gmail.com on 28 Feb 2012 at 1:07

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r3920.

Original comment by steven.b...@gmail.com on 20 Jul 2012 at 8:02

GoogleCodeExporter commented 9 years ago

Original comment by steven.b...@gmail.com on 5 Aug 2012 at 8:45