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

📄 bayesnet.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    catch (Exception e) {      e.printStackTrace();    }  }  /**   * sets a specific option/value of the generator (option must be w/o   * then '-')   * @param option          the option to set   * @param value           the new value for the option   */  protected void setGeneratorOption(String option, String value) {    setGeneratorOption(getGenerator(), option, value);  }  /**   * 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) {    setGeneratorOption("N", "" + numAttributes);  }  /**   * Gets the number of attributes that should be produced.   * @return the number of attributes that should be produced   */  public int getNumAttributes() {     int       result;        result = -1;    try {      result = Integer.parseInt(          Utils.getOption('N', getGenerator().getOptions()));    }    catch (Exception e) {      e.printStackTrace();      result = -1;    }    return result;  }    /**   * 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 (including class attribute), ie the number of nodes in the bayesian net.";  }  /**   * returns the default cardinality   *    * @return the default cardinality   */  protected int defaultCardinality() {    return 2;  }  /**   * Sets the cardinality of the attributes (incl class attribute)   * @param value the cardinality   */  public void setCardinality(int value) {     setGeneratorOption("C", "" + value);  }  /**   * Gets the cardinality of the attributes (incl class attribute)   * @return the cardinality of the attributes   */  public int getCardinality() {     int       result;        result = -1;    try {      result = Integer.parseInt(          Utils.getOption('C', getGenerator().getOptions()));    }    catch (Exception e) {      e.printStackTrace();      result = -1;    }    return result;  }    /**   * Returns the tip text for this property   *    * @return tip text for this property suitable for   *         displaying in the explorer/experimenter gui   */  public String cardinalityTipText() {    return "The cardinality of the attributes, incl the class attribute.";  }  /**   * returns the default number of arcs   *    * @return the default number of arcs   */  protected int defaultNumArcs() {    return 20;  }  /**   * Sets the number of arcs for the bayesian net   * @param value the number of arcs   */  public void setNumArcs(int value) {    int       nodes;    int       minArcs;    int       maxArcs;    nodes   = getNumAttributes();    minArcs = nodes - 1;    maxArcs = nodes * (nodes - 1) / 2;        if (value > maxArcs)      throw new IllegalArgumentException(          "Number of arcs should be at most nodes * (nodes - 1) / 2 = "           + maxArcs + " instead of " + value + " (nodes = numAttributes)!");    else if (value < minArcs)      throw new IllegalArgumentException(          "Number of arcs should be at least (nodes - 1) = " + minArcs           + " instead of " + value + " (nodes = numAttributes)!");    else      setGeneratorOption("A", "" + value);  }  /**   * Gets the number of arcs for the bayesian net   * @return the number of arcs   */  public int getNumArcs() {     int       result;        result = -1;    try {      result = Integer.parseInt(          Utils.getOption('A', getGenerator().getOptions()));    }    catch (Exception e) {      e.printStackTrace();      result = -1;    }    return result;  }    /**   * Returns the tip text for this property   *    * @return tip text for this property suitable for   *         displaying in the explorer/experimenter gui   */  public String numArcsTipText() {    return "The number of arcs in the bayesian net, at most: n * (n - 1) / 2 and at least: (n - 1); with n = numAttributes";  }  /**   * Sets the number of examples, given by option.   * @param numExamples the new number of examples   */  public void setNumExamples(int numExamples) {     super.setNumExamples(numExamples);    setGeneratorOption("M", "" + numExamples);  }  /**   * Gets the number of examples, given by option.   * @return the number of examples, given by option    */  public int getNumExamples() {     int       result;        result = -1;    try {      result = Integer.parseInt(          Utils.getOption('M', getGenerator().getOptions()));    }    catch (Exception e) {      e.printStackTrace();      result = -1;    }    return result;  }  /**   * Return if single mode is set for the given data generator   * mode depends on option setting and or generator type.   *    * @return single mode flag   * @throws Exception if mode is not set yet   */  public boolean getSingleModeFlag() throws Exception {    return false;  }  /**   * Initializes the format for the dataset produced.    * Must be called before the generateExample or generateExamples   * methods are used.   * Re-initializes the random number generator with the given seed.   *   * @return the format for the dataset    * @throws Exception if the generating of the format failed   * @see  #getSeed()   */  public Instances defineDataFormat() throws Exception {    BayesNetGenerator   bng;    bng = new BayesNetGenerator();    bng.setOptions(getGenerator().getOptions());    setGeneratorOption(bng, "M", "1");    bng.generateRandomNetwork();    bng.generateInstances();    bng.m_Instances.renameAttribute(0, "class");    bng.m_Instances.setRelationName(getRelationNameToUse());        return bng.m_Instances;  }  /**   * Generates one example of the dataset.    *   * @return the generated example   * @throws Exception if the format of the dataset is not yet defined   * @throws Exception if the generator only works with generateExamples   * which means in non single mode   */  public Instance generateExample() throws Exception {    throw new Exception("Cannot generate examples one-by-one!");  }  /**   * Generates all examples of the dataset. Re-initializes the random number   * generator with the given seed, before generating instances.   *   * @return the generated dataset   * @throws Exception if the format of the dataset is not yet defined   * @throws Exception if the generator only works with generateExample,   * which means in single mode   * @see   #getSeed()   */  public Instances generateExamples() throws Exception {    getGenerator().setOptions(getGenerator().getOptions());    getGenerator().generateRandomNetwork();    getGenerator().generateInstances();    getGenerator().m_Instances.renameAttribute(0, "class");    getGenerator().m_Instances.setRelationName(getRelationNameToUse());        return getGenerator().m_Instances;  }  /**   * Generates a comment string that documentates the data generator.   * By default this string is added at the beginning of the produced output   * as ARFF file type, next after the options.   *    * @return string contains info about the generated rules   */  public String generateStart () {    return "";  }  /**   * Generates a comment string that documentats the data generator.   * By default this string is added at the end of theproduces output   * as ARFF file type.   *    * @return string contains info about the generated rules   * @throws Exception if the generating of the documentaion fails   */  public String generateFinished() throws Exception {    return "";  }  /**   * Main method for executing this class.   *   * @param args should contain arguments for the data producer:    */  public static void main(String[] args) {    runDataGenerator(new BayesNet(), args);  }}

⌨️ 快捷键说明

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