/**
   * builds the necessary datasets from the given Instances
   *
   * @throws Exception if anything goes wrong
   */
  protected void generateSets() throws Exception {
    Instances instances;
    Instance instance;

    instances = new Instances(m_Testset, 0);

    for (int i = 0; i < m_Testset.numInstances(); i++) {
      instance = (Instance) m_Testset.instance(i).copy();
      instance.setClassMissing();
      instances.add(instance);
    }

    m_Testset = instances;
  }
예제 #2
0
파일: WekaTest.java 프로젝트: fsteeg/tm2
 private static Instance createInstance(double[] ds, String string, Instances instances) {
   int l = ds.length;
   // Create the instance
   Instance instance = new Instance(1 + l);
   instance.setDataset(instances);
   for (int i = 1; i <= l; i++) {
     instance.setValue(i, ds[i - 1]);
   }
   if (string == null) {
     instance.setClassMissing();
   } else {
     instance.setClassValue(string);
   }
   return instance;
 }
예제 #3
0
파일: CNode.java 프로젝트: Waikato/meka
 /**
  * Transform - turn [y1,y2,y3,x1,x2] into [y1,y2,x1,x2].
  *
  * @return transformed Instance
  */
 public Instance transform(Instance x, double ypred[]) throws Exception {
   x = (Instance) x.copy();
   int L = x.classIndex();
   int L_c = (paY.length + 1);
   x.setDataset(null);
   for (int j = 0; j < (L - L_c); j++) {
     x.deleteAttributeAt(0);
   }
   for (int pa : paY) {
     // System.out.println("x_["+map[pa]+"] <- "+ypred[pa]);
     x.setValue(map[pa], ypred[pa]);
   }
   x.setDataset(T);
   x.setClassMissing();
   return x;
 }
  public Instance buildWekaInstance(QAPair pair) {

    double[] query = projector.transform(pair.getQueryList());
    double[] answer = projector.transform(pair.getAnswerList());
    double[] cosine = {projector.computeCosignSimilarity(query, answer), 0.0};

    FastVector attributes = buildCosineAttributes();
    Attribute label = (Attribute) attributes.lastElement();

    Instances testInstances = new Instances("test", attributes, 1);
    testInstances.setClass(label);

    Instance example = new Instance(1, cosine);
    testInstances.add(example);
    example.setDataset(testInstances);

    if (!pair.getLabel().equals("-1")) {
      example.setClassValue(pair.getLabel());
    } else {
      example.setClassMissing();
    }
    return example;
  }