Java 类weka.core.InstanceComparator 实例源码

项目:collective-classification-weka-package    文件:CollectiveIBk.java   
/**
 * internal function for determining the class distribution for an instance, 
 * will be overridden by derived classes. <br/>
 * Here we just retrieve the class value for the given instance that was
 * calculated during building our classifier. It just returns "1" for the
 * class that was predicted, no real distribution.
 * Note: the ReplaceMissingValues filter is applied to a copy of the given
 * instance.
 * 
 * @param instance  the instance to get the distribution for
 * @return      the distribution for the given instance
 * @see         Classifier#distributionForInstance(Instance)
 * @see         ReplaceMissingValues
 * @throws Exception    if something goes wrong
 */
@Override
protected double[] getDistribution(Instance instance) throws Exception {
  double[]        result;
  int             i;                    

  result = new double[instance.numClasses()];
  for (i = 0; i < result.length; i++)
    result[i] = 0.0;

  i = Arrays.binarySearch(m_LabeledTestset, instance, new InstanceComparator(false));
  if (i >= 0) {
    result[(int) m_LabeledTestset[i].classValue()] = 1.0;
  }
  else {
    CollectiveHelper.writeToTempFile("train.txt", m_TrainsetNew.toString());
    CollectiveHelper.writeToTempFile("test.txt",  m_TestsetNew.toString());
    throw new Exception("Cannot find test instance: " + instance
      + "\n -> pos=" + i + " = " + m_LabeledTestset[StrictMath.abs(i)]);
  }

  return result;
}
项目:collective-classification-weka-package    文件:CollectiveIBk.java   
/**
 * performs the actual building of the classifier
 * @throws Exception if building fails
 */
@Override
protected void buildClassifier() throws Exception {
  int       i;

  i = 0;
  do {
    i++;
    if (getVerbose())
      System.out.println("Iteration " + i);

    update();
  }
  while (!isFinished());

  // move instances to sorted array
  m_LabeledTestset = new Instance[m_NeighborsTestset.length];
  for (i = 0; i < m_NeighborsTestset.length; i++)
    m_LabeledTestset[i] = m_NeighborsTestset[i].getInstance();
  Arrays.sort(m_LabeledTestset, new InstanceComparator(false));
}
项目:autoweka    文件:AddNoiseTest.java   
/** Need to remove non-nominal attributes, set class index */
protected void setUp() throws Exception {
  super.setUp();

  // class index
  m_Instances.setClassIndex(1);

  // only nominal attributes
  int i = 0;
  while (i < m_Instances.numAttributes()) {
    if (!m_Instances.attribute(i).isNominal())
      m_Instances.deleteAttributeAt(i);
    else
      i++;
  }

  m_Comparator = new InstanceComparator(true);
}
项目:umple    文件:AddNoiseTest.java   
/** Need to remove non-nominal attributes, set class index */
protected void setUp() throws Exception {
  super.setUp();

  // class index
  m_Instances.setClassIndex(1);

  // only nominal attributes
  int i = 0;
  while (i < m_Instances.numAttributes()) {
    if (!m_Instances.attribute(i).isNominal())
      m_Instances.deleteAttributeAt(i);
    else
      i++;
  }

  m_Comparator = new InstanceComparator(true);
}
项目:autoweka    文件:ChangeDateFormatTest.java   
/** Need to set class index */
protected void setUp() throws Exception {
  super.setUp();

  m_Instances.setClassIndex(1);
  m_Comparator = new InstanceComparator(true);
}
项目:umple    文件:ChangeDateFormatTest.java   
/** Need to set class index */
protected void setUp() throws Exception {
  super.setUp();

  m_Instances.setClassIndex(1);
  m_Comparator = new InstanceComparator(true);
}
项目:collective-classification-weka-package    文件:RankedInstanceComparator.java   
/**
 * initializes the comparator  
 * 
 * @param includeClass  whether to include the class attribute
 */
public RankedInstanceComparator(boolean includeClass) {
  super();

  m_Comparator = new InstanceComparator(includeClass);
}
项目:autoweka    文件:ReservoirSampleTest.java   
protected void setUp() throws Exception {
  super.setUp();

  m_Comparator = new InstanceComparator(true);
}
项目:umple    文件:ReservoirSampleTest.java   
protected void setUp() throws Exception {
  super.setUp();

  m_Comparator = new InstanceComparator(true);
}