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

📄 rdg1.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    tmpStr = Utils.getOption('I', options);    if (tmpStr.length() != 0)      setNumIrrelevant(Integer.parseInt(tmpStr));    else      setNumIrrelevant(defaultNumIrrelevant());    if ((getNumAttributes() - getNumIrrelevant()) < getMinRuleSize())       throw new Exception("Possible rule size is below minimal rule size.");    tmpStr = Utils.getOption('N', options);    if (tmpStr.length() != 0)      setNumNumeric(Integer.parseInt(tmpStr));    else      setNumNumeric(defaultNumNumeric());    setVoteFlag(Utils.getFlag('V', options));  }  /**   * Gets the current settings of the datagenerator RDG1.   *   * @return an array of strings suitable for passing to setOptions   */  public String[] getOptions() {    Vector        result;    String[]      options;    int           i;        result  = new Vector();    options = super.getOptions();    for (i = 0; i < options.length; i++)      result.add(options[i]);        result.add("-a");    result.add("" + getNumAttributes());        result.add("-c");    result.add("" + getNumClasses());    result.add("-N");     result.add("" + getNumNumeric());        result.add("-I");     result.add("" + getNumIrrelevant());        result.add("-M");     result.add("" + getMinRuleSize());        result.add("-R");     result.add("" + getMaxRuleSize());        if (getVoteFlag())      result.add("-V");     return (String[]) result.toArray(new String[result.size()]);  }  /**   * returns the default number of attributes   *    * @return the default number of attributes   */  protected int defaultNumAttributes() {    return 10;  }  /**   * Sets the number of attributes the dataset should have.   * @param numAttributes the new number of attributes   */  public void setNumAttributes(int numAttributes) {    m_NumAttributes = numAttributes;  }  /**   * Gets the number of attributes that should be produced.   * @return the number of attributes that should be produced   */  public int getNumAttributes() {     return m_NumAttributes;   }    /**   * Returns the tip text for this property   *    * @return tip text for this property suitable for   *         displaying in the explorer/experimenter gui   */  public String numAttributesTipText() {    return "The number of attributes the generated data will contain.";  }  /**   * returns the default number of classes   *    * @return the default number of classes   */  protected int defaultNumClasses() {    return 2;  }  /**   * Sets the number of classes the dataset should have.   * @param numClasses the new number of classes   */  public void setNumClasses(int numClasses) {     m_NumClasses = numClasses;   }  /**   * Gets the number of classes the dataset should have.   * @return the number of classes the dataset should have   */  public int getNumClasses() {     return m_NumClasses;   }    /**   * Returns the tip text for this property   *    * @return tip text for this property suitable for   *         displaying in the explorer/experimenter gui   */  public String numClassesTipText() {    return "The number of classes to generate.";  }  /**   * returns the default max size of rules   *    * @return the default max size of rules   */  protected int defaultMaxRuleSize() {    return 10;  }  /**   * Gets the maximum number of tests in rules.   *   * @return the maximum number of tests allowed in rules   */  public int getMaxRuleSize() {     return m_MaxRuleSize;   }    /**   * Sets the maximum number of tests in rules.   *   * @param newMaxRuleSize new maximum number of tests allowed in rules.   */  public void setMaxRuleSize(int newMaxRuleSize) {    m_MaxRuleSize = newMaxRuleSize;  }    /**   * Returns the tip text for this property   *    * @return tip text for this property suitable for   *         displaying in the explorer/experimenter gui   */  public String maxRuleSizeTipText() {    return "The maximum number of tests in rules.";  }  /**   * returns the default min size of rules   *    * @return the default min size of rules   */  protected int defaultMinRuleSize() {    return 1;  }  /**   * Gets the minimum number of tests in rules.   *   * @return the minimum number of tests allowed in rules   */  public int getMinRuleSize() {     return m_MinRuleSize;   }    /**   * Sets the minimum number of tests in rules.   *   * @param newMinRuleSize new minimum number of test in rules.   */  public void setMinRuleSize(int newMinRuleSize) {    m_MinRuleSize = newMinRuleSize;  }    /**   * Returns the tip text for this property   *    * @return tip text for this property suitable for   *         displaying in the explorer/experimenter gui   */  public String minRuleSizeTipText() {    return "The minimum number of tests in rules.";  }  /**   * returns the default number of irrelevant attributes   *    * @return the default number of irrelevant attributes   */  protected int defaultNumIrrelevant() {    return 0;  }  /**   * Gets the number of irrelevant attributes.   *   * @return the number of irrelevant attributes   */  public int getNumIrrelevant() {     return m_NumIrrelevant;   }    /**   * Sets the number of irrelevant attributes.   *   * @param newNumIrrelevant the number of irrelevant attributes.   */  public void setNumIrrelevant(int newNumIrrelevant) {    m_NumIrrelevant = newNumIrrelevant;  }    /**   * Returns the tip text for this property   *    * @return tip text for this property suitable for   *         displaying in the explorer/experimenter gui   */  public String numIrrelevantTipText() {    return "The number of irrelevant attributes.";  }  /**   * returns the default number of numeric attributes   *    * @return the default number of numeric attributes   */  protected int defaultNumNumeric() {    return 0;  }  /**   * Gets the number of numerical attributes.   *   * @return the number of numerical attributes.   */  public int getNumNumeric() {     return m_NumNumeric;   }    /**   * Sets the number of numerical attributes.   *   * @param newNumNumeric the number of numerical attributes.   */  public void setNumNumeric(int newNumNumeric) {     m_NumNumeric = newNumNumeric;  }    /**   * Returns the tip text for this property   *    * @return tip text for this property suitable for   *         displaying in the explorer/experimenter gui   */  public String numNumericTipText() {    return "The number of numerical attributes.";  }  /**   * Gets the vote flag.   *   * @return voting flag.   */  public boolean getVoteFlag() {     return m_VoteFlag;   }    /**   * Sets the vote flag.   *   * @param newVoteFlag boolean with the new setting of the vote flag.   */  public void setVoteFlag(boolean newVoteFlag) {     m_VoteFlag = newVoteFlag;   }    /**   * Returns the tip text for this property   *    * @return tip text for this property suitable for   *         displaying in the explorer/experimenter gui   */  public String voteFlagTipText() {    return "Whether to use voting or not.";  }  /**   * Gets the single mode flag.   *   * @return true if methode generateExample can be used.   */  public boolean getSingleModeFlag() {     return (!getVoteFlag());   }  /**   * Gets the array that defines which of the attributes   * are seen to be irrelevant.   *   * @return the array that defines the irrelevant attributes   */  public boolean[] getAttList_Irr() {     return m_AttList_Irr;   }    /**   * Sets the array that defines which of the attributes   * are seen to be irrelevant.   *   * @param newAttList_Irr array that defines the irrelevant attributes.   */  public void setAttList_Irr(boolean[] newAttList_Irr) {    m_AttList_Irr = newAttList_Irr;  }    /**   * Returns the tip text for this property   *    * @return tip text for this property suitable for   *         displaying in the explorer/experimenter gui   */  public String attList_IrrTipText() {    return "The array with the indices of the irrelevant attributes.";  }  /**   * Initializes the format for the dataset produced.    *   * @return the output data format   * @throws Exception data format could not be defined    */  public Instances defineDataFormat() throws Exception {    Instances dataset;    Random random = new Random (getSeed());    setRandom(random);    m_DecisionList = new FastVector();    // number of examples is the same as given per option    setNumExamplesAct(getNumExamples());    // define dataset    dataset = defineDataset(random);    return dataset;   }  /**   * Generate an example of the dataset dataset.    * @return the instance generated   * @throws Exception if format not defined or generating <br/>   * examples one by one is not possible, because voting is chosen   */  public Instance generateExample() throws Exception {    Random random = getRandom();    Instances format = getDatasetFormat();    if (format == null)       throw new Exception("Dataset format not defined.");    if (getVoteFlag())       throw new Exception("Examples cannot be generated one by one.");    // generate values for all attributes    format = generateExamples(1, random, format);    return format.lastInstance();  }  /**   * Generate all examples of the dataset.    * @return the instance generated   * @throws Exception if format not defined or generating <br/>   * examples one by one is not possible, because voting is chosen   */  public Instances generateExamples() throws Exception {    Random random = getRandom();    Instances format = getDatasetFormat();    if (format == null)       throw new Exception("Dataset format not defined.");    // generate values for all attributes    format = generateExamples(getNumExamplesAct(), random, format);    // vote all examples, and set new class value    if (getVoteFlag())      format = voteDataset(format);

⌨️ 快捷键说明

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