예제 #1
0
파일: Prism.java 프로젝트: Navieclipse/KEEL
  /** Creates the total selector's set for get all the possible rules */
  private Complejo hazSelectores(Dataset train) {

    Complejo almacenSelectores;
    int nClases = train.getnclases();
    almacenSelectores =
        new Complejo(nClases); // Aqui voy a almacenar los selectores (numVariable,operador,valor)
    Attribute[] atributos = null;
    int num_atributos, type;
    Vector nominalValues;
    atributos = Attributes.getAttributes();
    num_atributos = Attributes.getNumAttributes();
    Selector s;

    for (int i = 0; i < train.getnentradas(); i++) {
      type = atributos[i].getType();
      switch (type) {
        case 0: // NOMINAL
          nominalValues = atributos[i].getNominalValuesList();
          // System.out.print("{");
          for (int j = 0; j < nominalValues.size(); j++) {
            // System.out.print ((String)nominalValues.elementAt(j)+"  ");
            s = new Selector(i, 0, (String) nominalValues.elementAt(j), true); // [atr,op,valor]
            // incluimos tb los valores en double para facilitar algunas funciones
            s.setValor((double) j);
            almacenSelectores.addSelector(s);
            // s.print();
          }
          // System.out.println("}");
          break;
      }
      // System.out.println(num_atributos);
    }
    return almacenSelectores;
  }
예제 #2
0
  /**
   * Returns the attribute that has the name.
   *
   * @param name The name of the attribute.
   */
  public final Attribute getAttribute(String name) {
    for (int i = 0; i < attributes.size(); i++)
      if (((Attribute) attributes.elementAt(i)).name().equalsIgnoreCase(name))
        return (Attribute) attributes.elementAt(i);

    return null;
  }
예제 #3
0
파일: ABB.java 프로젝트: Navieclipse/KEEL
  /**
   * Checks if a node is legitimate. A node is illegitimate if its hamming distance to a pruned node
   * is 1 (this is, the node is a child of a previously pruned node).
   *
   * @param f node to check its legitimacy
   * @return true if the node is legitimate, false otherwise.
   */
  private boolean legitimate(boolean f[]) {
    boolean feas = true;
    for (int i = 0; i < pruned.size() && feas; i++) {
      if (hamming(pruned.elementAt(i), f) == 1) feas = false;
    }

    return feas;
  }
예제 #4
0
  /**
   * Function to remove all the attributes with missing value in the given attribute.
   *
   * @param attIndex The index of the attribute.
   */
  public final void deleteWithMissing(int attIndex) {
    Vector newItemsets = new Vector(numItemsets());

    for (int i = 0; i < numItemsets(); i++)
      if (!itemset(i).isMissing(attIndex)) newItemsets.addElement(itemset(i));

    itemsets = newItemsets;
  }
예제 #5
0
  /** Function to stores header of a data file. */
  private void readHeader() {
    String attributeName;
    Vector attributeValues;
    int i;

    name = Attributes.getRelationName();

    // Create vectors to hold information temporarily.
    attributes = new Vector();

    keel.Dataset.Attribute at;

    // store attribute,inputs and outputs of the header
    for (int j = 0; j < Attributes.getNumAttributes(); j++) {
      at = Attributes.getAttribute(j);
      attributeName = at.getName();

      // check if it is real
      if (at.getType() == 2) {
        float min = (float) at.getMinAttribute();
        float max = (float) at.getMinAttribute();
        attributes.addElement(new Attribute(attributeName, j));
        Attribute att = (Attribute) attributes.elementAt(j);
        att.setRange(min, max);
        att.activate();
      } else {
        if (at.getType() == 1) // check if it is integer
        {
          int min = (int) at.getMinAttribute();
          int max = (int) at.getMinAttribute();
          attributes.addElement(new Attribute(attributeName, j));
          Attribute att = (Attribute) attributes.elementAt(j);
          att.setRange(min, max);
          att.activate();
        } else // it is nominal
        {
          attributeValues = new Vector();
          for (int k = 0; k < at.getNumNominalValues(); k++) {
            attributeValues.addElement(at.getNominalValue(k));
          }
          attributes.addElement(new Attribute(attributeName, attributeValues, j));
          Attribute att = (Attribute) attributes.elementAt(j);
          att.activate();
        }
      }
    } // for

    // set the index of the output class
    classIndex = Attributes.getNumAttributes() - 1;
  }
예제 #6
0
  /**
   * Function to swap two itemsets.
   *
   * @param i The first itemset.
   * @param j The second itemset.
   */
  private void swap(int i, int j) {
    Object help = itemsets.elementAt(i);

    itemsets.insertElementAt(itemsets.elementAt(j), i);
    itemsets.removeElementAt(i + 1);
    itemsets.insertElementAt(help, j);
    itemsets.removeElementAt(j + 1);
  }
예제 #7
0
  /**
   * Enumerates all the attributes.
   *
   * @return An enumeration that contains all the attributes.
   */
  public Enumeration enumerateAttributes() {
    Vector help = new Vector(attributes.size() - 1);

    for (int i = 0; i < attributes.size(); i++)
      if (i != classIndex) help.addElement(attributes.elementAt(i));

    return help.elements();
  }
예제 #8
0
파일: ABB.java 프로젝트: Navieclipse/KEEL
  /** Recursive method for ABB */
  private void abb(boolean feat[]) {
    boolean[] child;
    double measure;

    threshold = data.measureIEP(feat);

    for (int i = 0; i < cardinalidadCto(feat); i++) {
      child = removeOne(feat, i);
      measure = data.measureIEP(child);

      if (legitimate(child) && measure < threshold) {
        if (measure < data.measureIEP(features)) {
          // we keep the best found in 'features'
          System.arraycopy(child, 0, features, 0, child.length);
        }
        abb(child);
      } else { // we prune this node
        pruned.add(child);
      }
    }
  }
예제 #9
0
 /** Returns the last itemset. */
 public final Itemset lastItemset() {
   return (Itemset) itemsets.lastElement();
 }
예제 #10
0
 /**
  * Returns the itemset at the given position.
  *
  * @param index The index of the itemset.
  */
 public final Itemset itemset(int index) {
   return (Itemset) itemsets.elementAt(index);
 }
예제 #11
0
 /**
  * Enumerates all the itemsets.
  *
  * @return An enumeration that contains all the itemsets.
  */
 public final Enumeration enumerateItemsets() {
   return itemsets.elements();
 }
예제 #12
0
 /**
  * Function to remove an itemset at the given position.
  *
  * @param index The index of the itemset to be deleted.
  */
 public final void delete(int index) {
   itemsets.removeElementAt(index);
 }
예제 #13
0
 /** Returns the number of itemsets. */
 public final int numItemsets() {
   return itemsets.size();
 }
예제 #14
0
 /** Returns the number of attributes. */
 public final int numAttributes() {
   return attributes.size();
 }
예제 #15
0
 /**
  * Returns the attribute that has the index.
  *
  * @param index The index of the attribute.
  */
 public final Attribute getAttribute(int index) {
   return (Attribute) attributes.elementAt(index);
 }
예제 #16
0
  /**
   * Function to add one itemset.
   *
   * @param itemset The itemset to add to the dataset.
   */
  public final void addItemset(Itemset itemset) {
    Itemset newItemset = (Itemset) itemset.copy();

    newItemset.setDataset(this);
    itemsets.addElement(newItemset);
  }