Package libsvm

Examples of libsvm.svm_node


      StringTokenizer st = new StringTokenizer(line, " \t\n\r\f:");
      vy.addElement(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 = Integer.parseInt(st.nextToken());
        x[j].value = Double.parseDouble(st.nextToken());
      }
      if (m > 0)
        max_index = Math.max(max_index, x[m - 1].index);
View Full Code Here


    feature.add(new Double(dateInfo));

    // set the libSVM feature vector
    svm_node[] x = new svm_node[feature.size()];
    for (int j = 0; j < feature.size(); j++) {
      x[j] = new svm_node();
      x[j].index = j + 1;
      x[j].value = ((Double) feature.get(j)).doubleValue();
    }

    double clsLabel; // 1:CURRENT_SMOKER, 2:PAST_SMOKER, 3:SMOKER
View Full Code Here

  public static svm_node[] getNodes(String nodeStr) {
    String[] vals = nodeStr.substring(2).split(" ");
    svm_node[] nodes = new svm_node[vals.length];
    for(int i = 0; i < vals.length; i++){
      String[] map = vals[i].split(":");
      nodes[i] = new svm_node();
      nodes[i].index = Integer.parseInt(map[0]);
      nodes[i].value = Double.parseDouble(map[1]);
    }
    return nodes;
  }
View Full Code Here

        Object val = aac.getClass().getMethod("calcm"+feats[i]).invoke(aac);
        if (val instanceof String) {
          String s = (String) val;
          if (s.equals("yes") || s.equals("Y") || s.equals("C") || s.equals("P")) {
//            vec += " " + (i+1) + ":1";
            svm_node node = new svm_node();
            node.index = i+1;
            node.value = 1;
            nodeList.add(node);
          } else if (s.equals("S")) {
//            vec += " " + (i+1) + ":0.5";
            svm_node node = new svm_node();
            node.index = i+1;
            node.value = 0.5;
            nodeList.add(node);
          } else if (!s.equals("U") && !s.equals("N") && !s.equals("no") && !s.equals("I")){ //TODO: cleanup
            int ii = Integer.parseInt(s);
            if (ii>=0 && ii<=6){
//              vec += " " + (i+1) + ":" + (ii/6.0);
              svm_node node = new svm_node();
              node.index = i+1;
              node.value = ii/6.0;
              nodeList.add(node);
            }
           
View Full Code Here

    for (int i = 0; i < feats.length; i++, ind++) {
      try {
        if (feats[i].equals("Anaph")) {
          double anaph_prob = needsAnaph ? calcAnaphoricity(aJCas, anaphor) : 1.0;
//          vec += " " + (ind+1) + ":" + anaph_prob;
          svm_node n = new svm_node();
          n.index = ind+1;
          n.value = anaph_prob;
          nodes.add(n);
          continue;
        }
        if (feats[i].contains(":")){
          String[] catFeat = feats[i].split(":");
          String featType = catFeat[0];
          String featName = catFeat[1];
          // if catFeat[0].equalsIgnoreCase("cat"){}   // Not necessary, no other feature namespaces used yet.
          String methodName = "num" + featName;
          //          Class<String> strClass = new Class<String>();
          int num = (Integer) sac.getClass().getMethod(methodName, Markable.class).invoke(sac, anaphor);
          methodName = "calc" + featType + featName;
          Method method = sac.getClass().getMethod(methodName, Integer.class, Markable.class);
          for(int j = 0; j < num; j++, ind++){
            String val = (String) method.invoke(sac, j, anaphor);
            if(val.equalsIgnoreCase("Y")){
              svm_node n = new svm_node();
              n.index = ind+1;
              n.value = 1;
              nodes.add(n);
//              vec += " " + (ind+1) + ":1";
            }
          }
          continue;
        }else{
          Object val = sac.getClass().getMethod("calc"+feats[i]).invoke(sac);
          if (val instanceof String) {
            String s = (String) val;
            if (s.equals("yes") || s.equals("Y") || s.equals("C")) {
              //            vec += " " + (ind+1) + ":1";
              svm_node n = new svm_node();
              n.index = ind+1;
              n.value = 1;
              nodes.add(n);
            }
          }
          else if (val instanceof Integer) {
            int v = ((Integer)val).intValue();
            if (v!=0) {
              //            vec += " " + (ind+1) + ":" + ((double)v/(i==0?600:10));
              svm_node n = new svm_node();
              n.index = ind+1;
              n.value = (double) v; // ((double)v/(i==0?600:10));
              nodes.add(n);
            }
          }
          else if (val instanceof Double) {
            //          vec += " " + (ind+1) + ":" + val;
            if((Double)val != 0.0){
              svm_node n = new svm_node();
              n.index = ind+1;
              n.value = (Double) val;
              nodes.add(n);
            }
          }else if (val instanceof Boolean) {
            if((Boolean) val == true){
              svm_node n = new svm_node();
              n.index = ind + 1;
              n.value = 1.0;
              nodes.add(n);
            }
          }

        }
      } catch (Exception e) { e.printStackTrace(); }
    }
   
    if(frags != null && frags.size() > 0){
      SimpleTree tn = TreeExtractor.extractPathTree(MarkableTreeUtils.markableNode(aJCas, antecedent.getBegin(), antecedent.getEnd()),
          MarkableTreeUtils.markableNode(aJCas, anaphor.getBegin(), anaphor.getEnd()));
//      SimpleTree tn = TreeExtractor.extractPathEnclosedTree(MarkableTreeUtils.markableNode(aJCas, antecedent.getBegin(), antecedent.getEnd()),
//          MarkableTreeUtils.markableNode(aJCas, anaphor.getBegin(), anaphor.getEnd()),
//          aJCas);
      // now go over the tree fragment features:
      for(SimpleTree frag : frags){
        if(TreeUtils.contains(tn, frag)){
          svm_node n = new svm_node();
          n.index = ind+1;
          n.value = 1.0;
          nodes.add(n);
        }
        ind++;
View Full Code Here

  private static svm_node[] getNodes(String nodeStr) {
    String[] vals = nodeStr.substring(2).split(" ");
    svm_node[] nodes = new svm_node[vals.length];
    for(int i = 0; i < vals.length; i++){
      String[] map = vals[i].split(":");
      nodes[i] = new svm_node();
      nodes[i].index = Integer.parseInt(map[0]);
      nodes[i].value = Double.parseDouble(map[1]);
    }
    return nodes;
  }
View Full Code Here

     
      //classify SE sentences based on the trained libSVM model
        svm_node[] x = new svm_node[psf.getFeatures().size()];
      for(int j=0;j<psf.getFeatures().size();j++)
      {
        x[j] = new svm_node();
        x[j].index = j+1;
        String nomFea = psf.getFeatures(j);
        x[j].value = Double.parseDouble(feaMap.get(nomFea));
      }
     
View Full Code Here

    {
        svm_node[] nodes = new svm_node[features.size()];
        int i = 0;
        // Features map is sorted, so we can just flatten it to a list for libsvm
        for (SortedMap.Entry<Integer, Double> feature : features.getFeatures().entrySet()) {
            nodes[i] = new svm_node();
            nodes[i].index = feature.getKey();
            nodes[i].value = feature.getValue();
            i++;
        }
View Full Code Here

    {
        svm_node[] nodes = new svm_node[features.size()];
        int i = 0;
        // Features map is sorted, so we can just flatten it to a list for libsvm
        for (SortedMap.Entry<Integer, Double> feature : features.getFeatures().entrySet()) {
            nodes[i] = new svm_node();
            nodes[i].index = feature.getKey();
            nodes[i].value = feature.getValue();
            i++;
        }
View Full Code Here

    {
        svm_node[] nodes = new svm_node[features.size()];
        int i = 0;
        // Features map is sorted, so we can just flatten it to a list for libsvm
        for (SortedMap.Entry<Integer, Double> feature : features.getFeatures().entrySet()) {
            nodes[i] = new svm_node();
            nodes[i].index = feature.getKey();
            nodes[i].value = feature.getValue();
            i++;
        }
View Full Code Here

TOP

Related Classes of libsvm.svm_node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.