Exemplo n.º 1
0
  /**
   * Generates output file for a clasification problem @ param Foutput Name of the output file @
   * param real Vector of outputs instances @ param obtained Vector of net outputs
   *
   * @return Nothing
   */
  public void generateResultsClasification(String Foutput, int[] real, int[] obtained) {

    // Output file, classification problems
    FileOutputStream out;
    PrintStream p;
    Attribute at = Attributes.getOutputAttribute(0);

    // Check whether the output value is nominal or integer
    boolean isNominal = (at.getType() == at.NOMINAL);
    try {
      out = new FileOutputStream(Foutput);
      p = new PrintStream(out);
      CopyHeaderTest(p);
      // System.out.println("Longitudes "+real.length+" "+obtained.length);
      for (int i = 0; i < real.length; i++) {
        // Write the label associated to the class number,
        // when the output is nominal
        if (isNominal)
          p.print(at.getNominalValue(real[i]) + " " + at.getNominalValue(obtained[i]) + "\n");
        else p.print(real[i] + " " + obtained[i] + "\n");
      }
      p.close();
    } catch (Exception e) {
      System.err.println("Error building file for results: " + Foutput);
    }
  }
Exemplo n.º 2
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