⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generator.java

📁 wekaUT是 university texas austin 开发的基于weka的半指导学习(semi supervised learning)的分类器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   * @return the number of examples the dataset should have   */  public int getNumExamplesAct() { return m_NumExamplesAct; }  /**   * Sets the print writer.   * @param newOutput the new print writer   */  public void setOutput(PrintWriter newOutput) {    m_Output = newOutput;  }  /**   * Gets the print writer.   * @return print writer object   */  public PrintWriter getOutput() { return m_Output; }  /**   * Sets the format of the dataset that is to be generated.    * @param the new dataset format of the dataset    */  protected void setFormat(Instances newFormat) {    m_Format = new Instances(newFormat, 0);  }  /**   * Gets the format of the dataset that is to be generated.    * @return the dataset format of the dataset   */  protected Instances getFormat() {    Instances format = new Instances(m_Format, 0);    return format;  }  /**   * Returns a string representing the dataset in the instance queue.   * @return the string representing the output data format   */  protected String toStringFormat() {     if (m_Format == null)     return "";   return m_Format.toString();  }  /**   * Calls the data generator.   *   * @param dataGenerator one of the data generators    * @param options options of the data generator   * @exception Exception if there was an error in the option list   */  public static void makeData(Generator generator, String [] options)     throws Exception {    PrintWriter output = null;    // read options /////////////////////////////////////////////////    try {      setOptions(generator, options);    } catch (Exception ex) {      String specificOptions = "";      if (generator instanceof OptionHandler) {        specificOptions = generator.listSpecificOptions(generator);        }      String genericOptions = listGenericOptions(generator);      throw new Exception('\n' + ex.getMessage()			  + specificOptions + genericOptions);    }        // define dataset format  ///////////////////////////////////////        // computes actual number of examples to be produced    generator.setFormat(generator.defineDataFormat());    // get print writer /////////////////////////////////////////////    output = generator.getOutput();    // output of options ////////////////////////////////////////////    output.println("% ");    output.print("% " + generator.getClass().getName() + " ");    String [] outOptions = generator.getGenericOptions();    for (int i = 0; i < outOptions.length; i++) {      output.print(outOptions[i] + " ");    }    outOptions = ((OptionHandler) generator).getOptions();    for (int i = 0; i < outOptions.length; i++) {      output.print(outOptions[i] + " ");    }    output.println("\n%");    // ask data generator which mode ////////////////////////////////    boolean singleMode = generator.getSingleModeFlag();    // start data producer   ////////////////////////////////////////     if (singleMode) {      // output of  dataset header //////////////////////////////////      output.println(generator.toStringFormat());      for (int i = 0; i < generator.getNumExamplesAct(); i++)  {        // over all examples to be produced        Instance inst = generator.generateExample();        output.println(inst);        }    } else { // generator produces all instances at once      Instances dataset = generator.generateExamples();      // output of  dataset ////////////////////////////////////////////      output.println(dataset);          }    // comment at end of ARFF File /////////////////////////////////////        String commentAtEnd = generator.generateFinished();      if (commentAtEnd.length() > 0) {      output.println(commentAtEnd);    }        if (output != null) {      output.close();    }  }  /**   * Makes a string with the options of the specific data generator.   *   * @param generator the datagenerator that is used   * @return string with the options of the data generator used   */  private String listSpecificOptions(Generator generator) {     String optionString = "";    if (generator instanceof OptionHandler) {      optionString += "\nData Generator options:\n\n";      Enumeration enum = ((OptionHandler)generator).listOptions();      while (enum.hasMoreElements()) {        Option option = (Option) enum.nextElement();	optionString += option.synopsis() + '\n'	    + option.description() + "\n";	}    }    return optionString;  }  /**   * Sets the generic options and specific options.   *   * @param generator the data generator used    * @param options the generic options and the specific options   * @exception Exception if help request or any invalid option   */  private static void setOptions(Generator generator,                                 String[] options) throws Exception {     boolean helpRequest = false;    String outfileName = new String("");     PrintWriter output;    // get help     helpRequest = Utils.getFlag('h', options);    if (Utils.getFlag('d', options)) { generator.setDebug(true); }    // get relationname    String relationName = Utils.getOption('r', options);     // set relation name at end of method after all options are set    // get outputfilename    outfileName = Utils.getOption('o', options);     // get num of classes    String numClasses = Utils.getOption('c', options);    if (numClasses.length() != 0)      generator.setNumClasses(Integer.parseInt(numClasses));    // get num of instances    String numExamples = Utils.getOption('n', options);    if (numExamples.length() != 0) {      generator.setNumExamples(Integer.parseInt(numExamples));      generator.setNumExamplesAct(Integer.parseInt(numExamples));      }    // get num of attributes    String numAttributes = Utils.getOption('a', options);    if (numAttributes.length() != 0)      generator.setNumAttributes(Integer.parseInt(numAttributes));          if (generator instanceof OptionHandler) {      ((OptionHandler)generator).setOptions(options);      }    // all options are set, now set relation name    generator.setRelationName(relationName);    // End read options    Utils.checkForRemainingOptions(options);    if (helpRequest) {      throw new Exception("Help requested.\n");    }    if (outfileName.length() != 0) {      output = new PrintWriter(new FileOutputStream(outfileName));    } else {       output = new PrintWriter(System.out);    }    generator.setOutput(output);  }  /**   * Method for listing generic options.   *   * @param generator the data generator   * @return string with the generic data generator options   */  private static String listGenericOptions (Generator generator) {    String genericOptions = "\nGeneral options:\n\n"	+ "-h\n"	+ "\tGet help on available options.\n"	+ "-a <number of attributes>\n"	+ "\tThe number of attributes the produced dataset should have.\n"	+ "-c <number of classes>\n"	+ "\tThe number of classes the produced dataset should have.\n"	+ "-n <number of examples>\n"	+ "\tThe number of examples the produced dataset should have.\n"	+ "-o <file>\n"	+ "\tThe name of the file output instances will be written to.\n"	+ "\tIf not supplied the instances will be written to stdout.\n";    return genericOptions;  }  /**   * Gets the current generic settings of the datagenerator.   *   * @return an array of strings suitable for passing to setOptions   */  private String [] getGenericOptions() {    String [] options = new String [10];    int current = 0;    String name = getRelationName();    if (name.length() > 0) {      options[current++] = "-r";      options[current++] = "" + getRelationName();    }    options[current++] = "-a"; options[current++] = "" + getNumAttributes();    options[current++] = "-c"; options[current++] = "" + getNumClasses();    options[current++] = "-n"; options[current++] = "" + getNumExamples();    while (current < options.length) {      options[current++] = "";    }    return options;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -