Package weka.classifiers.misc.monotone

Examples of weka.classifiers.misc.monotone.EnumerationIterator


    if (m_baseMin == null) {
      throw new IllegalStateException
      ("Classifier has not yet been built");
    }

    Iterator it = new EnumerationIterator(m_baseMin.enumerateInstances());
    while (it.hasNext()) {
      Instance r = (Instance) it.next();

      // we assume that rules are ordered in decreasing class value order
      // so that the first one that we encounter is immediately the
      // one with the biggest class value
      if (InstancesUtil.smallerOrEqual(r, instance)) {
View Full Code Here


    if (m_baseMax == null) {
      throw new IllegalStateException
      ("Classifier has not yet been built");
    }

    Iterator it = new EnumerationIterator(m_baseMax.enumerateInstances());
    while (it.hasNext()) {
      Instance r = (Instance) it.next();

      // we assume that rules are ordered in increasing class value order
      // so that the first bigger one we encounter will be the one
      // with the smallest label
      if (InstancesUtil.smallerOrEqual(instance, r)) {
View Full Code Here

  private Instance[] nearestRules(Instance instance, Instances base) {
    double min = Double.POSITIVE_INFINITY;
    double dist = 0;
    double[] instanceDouble = InstancesUtil.toDataDouble(instance);
    ArrayList nn = new ArrayList();
    Iterator it = new EnumerationIterator(base.enumerateInstances());
    while(it.hasNext()) {
      Instance r = (Instance) it.next();
      double[] rDouble = InstancesUtil.toDataDouble(r);
      switch (m_dtype) {
  case DT_EUCLID:
    dist = euclidDistance(instanceDouble, rDouble);
    break;
View Full Code Here

    // build the Map for the estimatedDistributions
    m_estimatedDistributions = new HashMap(m_train.numInstances() / 2);

    // cycle through all instances
    Iterator it = new EnumerationIterator(m_train.enumerateInstances());
    while (it.hasNext() == true) {
      Instance instance = (Instance) it.next();
      Coordinates c = new Coordinates(instance);

      // get DiscreteEstimator from the map
      DiscreteEstimator df =
  (DiscreteEstimator) m_estimatedDistributions.get(c);

      // if no DiscreteEstimator is present in the map, create one
      if (df == null) {
  df = new DiscreteEstimator(instances.numClasses(), 0);
      }
      df.addValue(instance.classValue(), instance.weight()); // update
      m_estimatedDistributions.put(c, df); // put back in map
    }

    // Create the attributes for m_baseMin and m_baseMax.
    // These are identical to those of m_train, except that the
    // class is set to 'numeric'
    // The class attribute is moved to the back
    FastVector newAtts = new FastVector(m_train.numAttributes());
    Attribute classAttribute = null;
    for (int i = 0; i < m_train.numAttributes(); i++) {
      Attribute att = m_train.attribute(i);
      if (i != m_train.classIndex()) {
  newAtts.addElement(att.copy());
      } else {
  classAttribute = new Attribute(att.name()); //numeric attribute
      }
    }
    newAtts.addElement(classAttribute);

    // original training instances are replaced by an empty set
    // of instances
    m_train = new Instances(m_train.relationName(), newAtts,
  m_estimatedDistributions.size());
    m_train.setClassIndex(m_train.numAttributes() - 1);


    // We cycle through the map of estimatedDistributions and
    // create one Instance for each entry in the map, with
    // a class value that is calculated from the distribution of
    // the class values
    it = m_estimatedDistributions.keySet().iterator();
    while(it.hasNext()) {
      // XXX attValues must be here, otherwise things go wrong
      double[] attValues = new double[m_train.numAttributes()];
      Coordinates cc = (Coordinates) it.next();
      DiscreteEstimator df =
  (DiscreteEstimator) m_estimatedDistributions.get(cc);
      cc.getValues(attValues);
      switch(m_atype) {
  case AT_MEAN:
View Full Code Here

   * checked
   * @return <code> true </code> if <code> instance </code>
   * is redundant, <code> false </code> otherwise
   */
  private boolean isRedundant(Instance instance) {
    Iterator it = new EnumerationIterator(m_baseMin.enumerateInstances());
    while(it.hasNext()) {
      Instance r = (Instance) it.next();
      if (instance.classValue() == r.classValue()
    && InstancesUtil.smallerOrEqual(r, instance) ) {
  return true;
      }
    }
View Full Code Here

   * checked
   * @return <code> true </code> if <code> instance </code>
   * is redundant, <code> false </code> otherwise
   */
  private boolean isRedundantMax(Instance instance) {
    Iterator it = new EnumerationIterator(m_baseMax.enumerateInstances());
    while(it.hasNext()) {
      Instance r = (Instance) it.next();
      if (instance.classValue() == r.classValue()
    && InstancesUtil.smallerOrEqual(instance, r) ) {
  return true;
      }
    }
View Full Code Here

   * @return <code> true </code> if adding <code> instance </code>
   * to the rule base would cause reversed preference among the rules,
   * <code> false </code> otherwise.
   */
  private boolean causesReversedPreference(Instance instance) {
    Iterator it = new EnumerationIterator(m_baseMin.enumerateInstances());
    while (it.hasNext()) {
      Instance r = (Instance) it.next();
      if (instance.classValue() > r.classValue() &&
    InstancesUtil.smallerOrEqual(instance, r)) {
  // in the original version of OLM this should not happen
  System.err.println
  ("Should not happen in the original OLM algorithm");
View Full Code Here

   * @return true if adding <code> instance </code> to the rule
   * base would cause reversed preference among the rules,
   * false otherwise.
   */
  private boolean causesReversedPreferenceMax(Instance instance) {
    Iterator it = new EnumerationIterator(m_baseMax.enumerateInstances());
    while (it.hasNext()) {
      Instance r = (Instance) it.next();
      if (instance.classValue() > r.classValue() &&
    InstancesUtil.smallerOrEqual(instance, r)) {
  return true;
      } else if (r.classValue() > instance.classValue() &&
    InstancesUtil.smallerOrEqual(r, instance)) {
View Full Code Here

TOP

Related Classes of weka.classifiers.misc.monotone.EnumerationIterator

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.