svm_model.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // svm_model
  3. //
  4. package opennlp.tools.svm.libsvm;
  5. public class svm_model implements Cloneable, java.io.Serializable {
  6. public svm_parameter param; // parameter
  7. public int nr_class; // number of classes, = 2 in regression/one class svm
  8. public int l; // total #SV
  9. public SupportVectorMachineNode[][] SV; // SVs (SV[l])
  10. public double[][] sv_coef; // coefficients for SVs in decision functions (sv_coef[k-1][l])
  11. public double[] rho; // constants in decision functions (rho[k*(k-1)/2])
  12. public double[] probA; // pariwise probability information
  13. public double[] probB;
  14. public int[] sv_indices; // sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the train set
  15. // for classification only
  16. public int[] label; // label of each class (label[k])
  17. public int[] nSV; // number of SVs for each class (nSV[k])
  18. // nSV[0] + nSV[1] + ... + nSV[k-1] = l
  19. public svm_model makeCopy() {
  20. svm_model clone = new svm_model();
  21. clone.copy(this);
  22. return clone;
  23. }
  24. public void copy(svm_model rhs){
  25. param = rhs.param;
  26. nr_class = rhs.nr_class;
  27. l = rhs.l; // total #SV
  28. SV=new SupportVectorMachineNode[rhs.SV.length][]; // SVs (SV[l])
  29. for(int i=0; i < rhs.SV.length; ++i){
  30. SV[i] = new SupportVectorMachineNode[rhs.SV[i].length];
  31. for(int j=0; j < rhs.SV[i].length; ++j){
  32. SV[i][j] = rhs.SV[i][j].makeCopy();
  33. }
  34. }
  35. sv_coef = new double[rhs.sv_coef.length][]; // coefficients for SVs in decision functions (sv_coef[k-1][l])
  36. for(int i=0; i < rhs.sv_coef.length; ++i){
  37. sv_coef[i] = rhs.sv_coef[i].clone();
  38. }
  39. rho = rhs.rho == null ? null : rhs.rho.clone(); // constants in decision functions (rho[k*(k-1)/2])
  40. probA = rhs.probA == null ? null : rhs.probA.clone(); // pariwise probability information
  41. probB = rhs.probB == null ? null : rhs.probB.clone();
  42. sv_indices = rhs.sv_indices == null ? null : rhs.sv_indices.clone(); // sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the train set
  43. // for classification only
  44. label = rhs.label == null ? null : rhs.label.clone(); // label of each class (label[k])
  45. nSV = rhs.nSV == null ? null : rhs.nSV.clone(); // number of SVs for each class (nSV[k])
  46. }
  47. }