Package libsvm

Examples of libsvm.svm_node


          problem.y[i] = y;
          problem.x[i] = new svm_node[featureList.size()];
          int p = 0;
              for (int k=0; k < featureList.size(); k++) {
                MaltFeatureNode x = featureList.get(k);
            problem.x[i][p] = new svm_node();
            problem.x[i][p].value = x.getValue();
            problem.x[i][p].index = x.getIndex();         
            p++;
          }
          i++;
View Full Code Here


          for(j = 1; j < columns.length; j++) {
            final String[] items = pipePattern.split(columns[j])
            for (int k = 0; k < items.length; k++) {
              try {
                if (Integer.parseInt(items[k]) != -1) {
                  xlist.add(p, new svm_node());
                  xlist.get(p).value = 1;
                  xlist.get(p).index = Integer.parseInt(items[k])+offset;
                  p++;
                }
              } catch (NumberFormatException e) {
View Full Code Here

            int m = trainingSample.size();
            svm_node[] x = new svm_node[m];
            Entry<Integer, Double> currentEntry;
            for (int j = 0; j < m; j++) {
                currentEntry = it.next();
                x[j] = new svm_node();
                x[j].index = currentEntry.getKey();
                x[j].value = currentEntry.getValue();
            }
            return svm.svm_predict(currentModel, x);
        } catch (IOException ex) {
View Full Code Here

            it = currentFeatures.entrySet().iterator();
            m = currentFeatures.size();
            x = new svm_node[m];
            for (int j = 0; j < m; j++) {
                currentEntry = it.next();
                x[j] = new svm_node();
                x[j].index = currentEntry.getKey();
                x[j].value = currentEntry.getValue();
            }
            if (m > 0) {
                max_index = Math.max(max_index, x[m - 1].index);
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);
            }
          }
        }
      } 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

  public void addTrainingData(String v, double[] value, String label) {
    // convert value to feature vector
    rawData.add(v);
    svm_node[] testNodes = new svm_node[value.length];
    for (int k = 0; k < testNodes.length; k++) {
      svm_node node = new svm_node();
      node.index = k;
      node.value = value[k];
      testNodes[k] = node;
    }
    this.trainData.add(testNodes);
View Full Code Here

    Collection<Feature> cfeat = rf.computeFeatures(value, "");
    Feature[] x = cfeat.toArray(new Feature[cfeat.size()]);
    // row.add(f.getName());
    svm_node[] testNodes = new svm_node[cfeat.size()];
    for (int k = 0; k < cfeat.size(); k++) {
      svm_node node = new svm_node();
      node.index = k;
      node.value = x[k].getScore();
      testNodes[k] = node;
    }
    this.trainData.add(testNodes);
View Full Code Here

    Collection<Feature> cfeat = rf.computeFeatures(value, "");
    Feature[] x = cfeat.toArray(new Feature[cfeat.size()]);
    // row.add(f.getName());
    svm_node[] testNodes = new svm_node[cfeat.size()];
    for (int k = 0; k < cfeat.size(); k++) {
      svm_node node = new svm_node();
      node.index = k;
      node.value = x[k].getScore();
      testNodes[k] = node;
    }
    /* temp test */
 
View Full Code Here

    Vector vector = document.getFeatureVector(this.lexicon);
    int[] indices = vector.getIndices();
    double[] values = vector.getValues();
    svm_node[] svm_nodes = new svm_node[indices.length];
    for(int n = 0; n < svm_nodes.length; n++) {
      svm_nodes[n] = new svm_node();
      svm_nodes[n].index = indices[n];
      svm_nodes[n].value = values[n];
    }
    if(support_probabilities) // returns the real probabilities
    {
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.