Ejemplo n.º 1
0
  /**
   * It does remove an attribute. To remove an attribute, the train and the test sets have to be
   * passed to mantain the coherence of the system. Otherwise, only the attribute of the train set
   * would be removed, leaving inconsistent the instances of the test set, because of having one
   * extra attribute inexistent anymore.
   *
   * @param tSet is the test set.
   * @param inputAtt is a boolean that is true when the attribute that is wanted to be removed is an
   *     input attribute.
   * @param whichAtt is a integer that indicate the position of the attriubte to be deleted.
   * @return a boolean indicating if the attribute has been deleted
   */
  public boolean removeAttribute(InstanceSet tSet, boolean inputAtt, int whichAtt) {
    Attribute attToDel = null;
    // Getting a reference to the attribute to del
    if (inputAtt) {
      if (storeAttributesAsNonStatic && attributes != null)
        attToDel = (Attribute) attributes.getInputAttribute(whichAtt);
      else attToDel = (Attribute) Attributes.getInputAttribute(whichAtt);
    } else {
      if (storeAttributesAsNonStatic && attributes != null)
        attToDel = (Attribute) attributes.getOutputAttribute(whichAtt);
      else attToDel = (Attribute) Attributes.getOutputAttribute(whichAtt);
    }

    if (storeAttributesAsNonStatic && attributes != null) {
      System.out.println("Removing the attribute");
      if (!attributes.removeAttribute(inputAtt, whichAtt)
          || !tSet.attributes.removeAttribute(inputAtt, whichAtt)) return false;
    } else {
      if (!Attributes.removeAttribute(inputAtt, whichAtt)) return false;
    }

    for (int i = 0; i < instanceSet.length; i++) {
      if (storeAttributesAsNonStatic && attributes != null) {
        instanceSet[i].removeAttribute(attributes, attToDel, inputAtt, whichAtt);
      } else {
        instanceSet[i].removeAttribute(attToDel, inputAtt, whichAtt);
      }
    }

    if (tSet != null)
      for (int i = 0; i < tSet.instanceSet.length; i++) {
        if (storeAttributesAsNonStatic && attributes != null)
          tSet.instanceSet[i].removeAttribute(attributes, attToDel, inputAtt, whichAtt);
        else tSet.instanceSet[i].removeAttribute(attToDel, inputAtt, whichAtt);
      }
    return true;
  } // end removeAttribute