weka.core.AdditionalMeasureProducer Java Examples

The following examples show how to use weka.core.AdditionalMeasureProducer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AttributeSelectedClassifier.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * Returns an enumeration of the additional measure names
  * @return an enumeration of the measure names
  */
 public Enumeration enumerateMeasures() {
   Vector newVector = new Vector(3);
   newVector.addElement("measureNumAttributesSelected");
   newVector.addElement("measureSelectionTime");
   newVector.addElement("measureTime");
   if (m_Classifier instanceof AdditionalMeasureProducer) {
     Enumeration en = ((AdditionalMeasureProducer)m_Classifier).
enumerateMeasures();
     while (en.hasMoreElements()) {
String mname = (String)en.nextElement();
newVector.addElement(mname);
     }
   }
   return newVector.elements();
 }
 
Example #2
Source File: AttributeSelectedClassifier.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
  * Returns the value of the named measure
  * @param additionalMeasureName the name of the measure to query for its value
  * @return the value of the named measure
  * @throws IllegalArgumentException if the named measure is not supported
  */
 public double getMeasure(String additionalMeasureName) {
   if (additionalMeasureName.compareToIgnoreCase("measureNumAttributesSelected") == 0) {
     return measureNumAttributesSelected();
   } else if (additionalMeasureName.compareToIgnoreCase("measureSelectionTime") == 0) {
     return measureSelectionTime();
   } else if (additionalMeasureName.compareToIgnoreCase("measureTime") == 0) {
     return measureTime();
   } else if (m_Classifier instanceof AdditionalMeasureProducer) {
     return ((AdditionalMeasureProducer)m_Classifier).
getMeasure(additionalMeasureName);
   } else {
     throw new IllegalArgumentException(additionalMeasureName 
		  + " not supported (AttributeSelectedClassifier)");
   }
 }
 
Example #3
Source File: InputMappedClassifier.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns an enumeration of the additional measure names
 * @return an enumeration of the measure names
 */
public Enumeration enumerateMeasures() {
  Vector newVector = new Vector();
  
  if (m_Classifier instanceof AdditionalMeasureProducer) {
    Enumeration en = ((AdditionalMeasureProducer)m_Classifier).
      enumerateMeasures();
    while (en.hasMoreElements()) {
      String mname = (String)en.nextElement();
      newVector.addElement(mname);
    }
  }
  return newVector.elements();
}
 
Example #4
Source File: InputMappedClassifier.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the value of the named measure
 * @param additionalMeasureName the name of the measure to query for its value
 * @return the value of the named measure
 * @throws IllegalArgumentException if the named measure is not supported
 */
public double getMeasure(String additionalMeasureName) {
   if (m_Classifier instanceof AdditionalMeasureProducer) {
    return ((AdditionalMeasureProducer)m_Classifier).
      getMeasure(additionalMeasureName);
  } else {
    throw new IllegalArgumentException(additionalMeasureName 
                        + " not supported (InputMappedClassifier)");
  }
}
 
Example #5
Source File: CollectiveForest.java    From collective-classification-weka-package with GNU General Public License v3.0 4 votes vote down vote up
/**
 * performs the actual building of the classifier
 * 
 * @throws Exception if building fails
 */
@Override
protected void buildClassifier() throws Exception {
  Classifier        tree;
  int               i;
  int               n;
  int               nextSeed;
  double[]          dist;
  Instances         bagData;
  boolean[]         inBag;
  double            outOfBagCount;
  double            errorSum;
  Instance          outOfBagInst;

  m_PureTrainNodes = 0;
  m_PureTestNodes  = 0;
  
  for (i = 0; i < getNumTrees(); i++) {
    // info
    if (getVerbose())
      System.out.print(".");

    // get next seed number
    nextSeed = m_Random.nextInt();

    // bagging?
    if (getUseBagging()) {
      // inBag-dataset/array
      inBag   = new boolean[m_TrainsetNew.numInstances()];
      bagData = resample(m_TrainsetNew, nextSeed, inBag);
      
      // build i.th tree
      tree = initClassifier(nextSeed);

      // determine and store distributions
      for (n = 0; n < m_TestsetNew.numInstances(); n++) {
        dist = tree.distributionForInstance(m_TestsetNew.instance(n));
        m_List.addDistribution(m_TestsetNew.instance(n), dist);
      }

      // determine out-of-bag-error
      outOfBagCount = 0;
      errorSum      = 0;

      for (n = 0; n < inBag.length; n++) {  
        if (!inBag[n]) {
          outOfBagInst = m_TrainsetNew.instance(n);
          outOfBagCount += outOfBagInst.weight();
          if (m_TrainsetNew.classAttribute().isNumeric()) {
            errorSum += outOfBagInst.weight() *
              StrictMath.abs(tree.classifyInstance(outOfBagInst)
                       - outOfBagInst.classValue());
          } 
          else {
            if (tree.classifyInstance(outOfBagInst) 
                  != outOfBagInst.classValue()) {
              errorSum += outOfBagInst.weight();
            }
          }
        }
      }

      m_OutOfBagError = errorSum / outOfBagCount;
    }
    else {
      // build i.th tree
      tree = initClassifier(nextSeed);

      // determine and store distributions
      for (n = 0; n < m_TestsetNew.numInstances(); n++) {
        dist = tree.distributionForInstance(m_TestsetNew.instance(n));
        m_List.addDistribution(m_TestsetNew.instance(n), dist);
      }
    }

    // get information about pure nodes
    try {
      if (tree instanceof AdditionalMeasureProducer) {
        m_PureTrainNodes += ((AdditionalMeasureProducer) tree).getMeasure(
                                "measurePureTrainNodes");
        m_PureTestNodes  += ((AdditionalMeasureProducer) tree).getMeasure(
                                "measurePureTestNodes");
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }

    tree = null;
  }
    
  if (getVerbose())
    System.out.println();
}