コード例 #1
0
ファイル: InstanceSet.java プロジェクト: Navieclipse/KEEL
  /** It does return the original header definiton but without @input and @output in there */
  public String getOriginalHeaderWithoutInOut() {
    String line = "";
    Attribute[] attrs = null;

    // Getting the relation name and the attributes
    if (storeAttributesAsNonStatic && attributes != null) {
      line = "@relation " + attributes.getRelationName() + "\n";
      attrs = attributes.getAttributes();
    } else {
      line = "@relation " + Attributes.getRelationName() + "\n";
      attrs = Attributes.getAttributes();
    }

    for (int i = 0; i < attrs.length; i++) {
      line += attrs[i].toString() + "\n";
    }
    return line;
  } // end getOriginalHeaderWithoutInOut
コード例 #2
0
ファイル: InstanceSet.java プロジェクト: Navieclipse/KEEL
  /**
   * It prints the dataset to the specified PrintWriter. The order of the attributes is the same as
   * in the original file
   *
   * @param out is the PrintWriter where to print
   * @param printInOut indicates if the @inputs (1), @outputs(2), both of them (3) or any (0) has to
   *     be printed
   */
  public void printAsOriginal(PrintWriter out, int printInOut) {
    /*Printing the header as the original one*/
    out.println(header);

    if (storeAttributesAsNonStatic && attributes != null) {
      if (printInOut == 1 || printInOut == 3) out.println(attributes.getInputHeader());
      if (printInOut == 2 || printInOut == 3) out.println(attributes.getOutputHeader());
    } else {
      if (printInOut == 1 || printInOut == 3) out.println(Attributes.getInputHeader());
      if (printInOut == 2 || printInOut == 3) out.println(Attributes.getOutputHeader());
    }

    out.print("@data");
    for (int i = 0; i < instanceSet.length; i++) {
      out.println();
      if (storeAttributesAsNonStatic && attributes != null)
        instanceSet[i].printAsOriginal(attributes, out);
      else instanceSet[i].printAsOriginal(out);
    }
  } // end printAsOriginal
コード例 #3
0
ファイル: InstanceSet.java プロジェクト: Navieclipse/KEEL
  /**
   * 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
コード例 #4
0
ファイル: InstanceSet.java プロジェクト: Navieclipse/KEEL
  /**
   * It does return a new header (not necessary the same header as the input file one). It only
   * includes the valid attributes, those ones defined in @inputs and @outputs (or taken as that
   * role following the keel format specification).
   *
   * @return a String with the new header
   */
  public String getNewHeader() {
    String line = "";
    Attribute[] attrs = null;

    // Getting the relation name and the attributes
    if (storeAttributesAsNonStatic && attributes != null) {
      line = "@relation " + attributes.getRelationName() + "\n";
      attrs = attributes.getInputAttributes();
    } else {
      line = "@relation " + Attributes.getRelationName() + "\n";
      attrs = Attributes.getInputAttributes();
    }

    for (int i = 0; i < attrs.length; i++) {
      line += attrs[i].toString() + "\n";
    }

    // Gettin all the outputs attributes
    if (storeAttributesAsNonStatic && attributes != null) {
      attrs = attributes.getOutputAttributes();
      line += attrs[0].toString() + "\n";

      // Getting @inputs and @outputs
      line += attributes.getInputHeader() + "\n";
      line += attributes.getOutputHeader() + "\n";
    } else {
      attrs = Attributes.getOutputAttributes();
      line += attrs[0].toString() + "\n";

      // Getting @inputs and @outputs
      line += Attributes.getInputHeader() + "\n";
      line += Attributes.getOutputHeader() + "\n";
    }

    return line;
  } // end getNewHeader
コード例 #5
0
ファイル: InstanceSet.java プロジェクト: Navieclipse/KEEL
  public void print() {
    System.out.println("------------- ATTRIBUTES --------------");
    if (storeAttributesAsNonStatic && attributes != null) {
      attributes.print();
    } else {
      Attributes.print();
    }

    System.out.println("-------------- INSTANCES --------------");
    for (int i = 0; i < instanceSet.length; i++) {
      System.out.print("\n> Instance " + i + ":");

      if (storeAttributesAsNonStatic && attributes != null) {
        instanceSet[i].print(attributes);
      } else instanceSet[i].print();
    }
  } // end print
コード例 #6
0
ファイル: InstanceSet.java プロジェクト: Navieclipse/KEEL
 /**
  * Appends the given attribute to the non-static list of the current InstanceSet
  *
  * @param at The Attribute to be Appended
  */
 public void addAttribute(Attribute at) {
   if (attributes == null) attributes = new InstanceAttributes();
   attributes.addAttribute(at);
 }
コード例 #7
0
ファイル: InstanceSet.java プロジェクト: Navieclipse/KEEL
 /**
  * setAttributesAsNonStatic
  *
  * <p>It stores the static-defined attributes in the class Attributes as non static in the object
  * attributes. After this it does not remove the static-definition of the Attributes; this is in
  * that way to permit to call this functions for differents datasets from the same problem, such
  * as, a train dataset and the correspondent test dataset.
  */
 public void setAttributesAsNonStatic() {
   attributes = new InstanceAttributes();
   attributes.copyStaticAttributes();
 } // end setAttributesAsNonStatic