diff --git a/lang/fr/gklearn/gedlib/lib/libsvm.3.22/java/svm_predict.java b/lang/fr/gklearn/gedlib/lib/libsvm.3.22/java/svm_predict.java new file mode 100644 index 0000000..d714c5b --- /dev/null +++ b/lang/fr/gklearn/gedlib/lib/libsvm.3.22/java/svm_predict.java @@ -0,0 +1,194 @@ +import libsvm.*; +import java.io.*; +import java.util.*; + +class svm_predict { + private static svm_print_interface svm_print_null = new svm_print_interface() + { + public void print(String s) {} + }; + + private static svm_print_interface svm_print_stdout = new svm_print_interface() + { + public void print(String s) + { + System.out.print(s); + } + }; + + private static svm_print_interface svm_print_string = svm_print_stdout; + + static void info(String s) + { + svm_print_string.print(s); + } + + private static double atof(String s) + { + return Double.valueOf(s).doubleValue(); + } + + private static int atoi(String s) + { + return Integer.parseInt(s); + } + + private static void predict(BufferedReader input, DataOutputStream output, svm_model model, int predict_probability) throws IOException + { + int correct = 0; + int total = 0; + double error = 0; + double sumv = 0, sumy = 0, sumvv = 0, sumyy = 0, sumvy = 0; + + int svm_type=svm.svm_get_svm_type(model); + int nr_class=svm.svm_get_nr_class(model); + double[] prob_estimates=null; + + if(predict_probability == 1) + { + if(svm_type == svm_parameter.EPSILON_SVR || + svm_type == svm_parameter.NU_SVR) + { + svm_predict.info("Prob. model for test data: target value = predicted value + z,\nz: Laplace distribution e^(-|z|/sigma)/(2sigma),sigma="+svm.svm_get_svr_probability(model)+"\n"); + } + else + { + int[] labels=new int[nr_class]; + svm.svm_get_labels(model,labels); + prob_estimates = new double[nr_class]; + output.writeBytes("labels"); + for(int j=0;j=argv.length-2) + exit_with_help(); + try + { + BufferedReader input = new BufferedReader(new FileReader(argv[i])); + DataOutputStream output = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(argv[i+2]))); + svm_model model = svm.svm_load_model(argv[i+1]); + if (model == null) + { + System.err.print("can't open model file "+argv[i+1]+"\n"); + System.exit(1); + } + if(predict_probability == 1) + { + if(svm.svm_check_probability_model(model)==0) + { + System.err.print("Model does not support probabiliy estimates\n"); + System.exit(1); + } + } + else + { + if(svm.svm_check_probability_model(model)!=0) + { + svm_predict.info("Model supports probability estimates, but disabled in prediction.\n"); + } + } + predict(input,output,model,predict_probability); + input.close(); + output.close(); + } + catch(FileNotFoundException e) + { + exit_with_help(); + } + catch(ArrayIndexOutOfBoundsException e) + { + exit_with_help(); + } + } +}