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

📄 sfaninducer.java

📁 bayes network classifier toolbox 贝叶斯网络分类工具箱
💻 JAVA
字号:
/** *  JBNC - Bayesian Network Classifiers Toolbox <p> * *  Latest release available at http://sourceforge.net/projects/jbnc/ <p> * *  Copyright (C) 1999-2003 Jarek Sacha <p> * *  This program is free software; you can redistribute it and/or modify it *  under the terms of the GNU General Public License as published by the Free *  Software Foundation; either version 2 of the License, or (at your option) *  any later version. <p> * *  This program is distributed in the hope that it will be useful, but WITHOUT *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *  more details. <p> * *  You should have received a copy of the GNU General Public License along with *  this program; if not, write to the Free Software Foundation, Inc., 59 Temple *  Place - Suite 330, Boston, MA 02111-1307, USA. <br> *  http://www.fsf.org/licenses/gpl.txt */package jbnc.inducers;import BayesianNetworks.BayesNet;import jbnc.dataset.DatasetInt;import jbnc.util.BNTools;import java.io.FileOutputStream;import java.io.PrintStream;/** *  Constructs Selective Forest Augmented Naive Bayes classifier (SFAN). * * @author     Jarek Sacha * @since      June 1, 1999 */public class SFANInducer extends DiscardingBayesianInducer {  /**   *  Used for testing of the SFAN algorithm.   *   * @param  arg  The command line arguments   */  public static void main(String[] arg) {    try {      jbnc.util.Timer t = new jbnc.util.Timer();      System.out.println("\nTesting class...\n");      String fileStem = null;      if (arg.length > 0) {        fileStem = arg[0];      } else {        fileStem = "..\\db\\vote";      }//        fileStem = "..\\db_cv\\iris-0-1";      System.out.println("Load dataset: " + fileStem);      DatasetInt dataset = new DatasetInt();      dataset.openC45(fileStem);      jbnc.util.FrequencyCalc fc = new jbnc.util.FrequencyCalc(dataset);      SFANInducer sfan = new SFANInducer();      sfan.setQualityMeasure(new jbnc.measures.QualityMeasureLC());      sfan.setDebugMode(true);//      sfan.setDiscardNondependent(true);      sfan.train(fc);      t.stop();      BayesNet thisNet = sfan.getNetwork();      jbnc.util.BNCTester tester = new jbnc.util.BNCTester();      jbnc.util.BNCTester.Result r = tester.test(thisNet, dataset);      double ratio = r.nbPass / (double) (r.nbPass + r.nbFail);      System.out.println("Accuracy on training set = " + (ratio * 100) + "%");      t.println("\nExecution time = ");    } catch (Exception e) {      e.printStackTrace();    }  }  /**   *  Construct SFAN network from the training data   *   * @param  fc             Description of Parameter   * @param  usePriors      Description of Parameter   * @param  alpha_ijk      Description of Parameter   * @exception  Exception  Description of Exception   */  public void train(jbnc.util.FrequencyCalc fc,                    boolean usePriors,                    double alpha_ijk) throws Exception {    // Clean storage    clean();    // Some sanity checks//    verifyDataset(dataset);    //Make sure that usePriors and alphaK are consistent    if (!usePriors) {      alpha_ijk = 0;    }    // Check quality measure    if (qualityMeasure == null) {      throw new Exception("Network quality measure has not been assigned.");    }//    qualityMeasure.setDataset(dataset);    qualityMeasure.setUsePriors(usePriors);    qualityMeasure.setAlphaK(alpha_ijk);    if (debugMode) {      System.out.println("Attributes/Cases = "          + (fc.names.length - 1) + "/"          + fc.nbCases);    }    jbnc.operators.SAN san = new jbnc.operators.SAN();    jbnc.operators.ForestAugmenter fa = new jbnc.operators.ForestAugmenter();    san.setDiscardNonDependent(discardNonDependent);    san.setDebugMode(debugMode);    net = san.train(fc, qualityMeasure, fa, usePriors, alpha_ijk);    BNTools.learnParameters(net, fc, usePriors, alpha_ijk);    if (debugMode) {      FileOutputStream out = new FileOutputStream("SFAN_dump.bif");      PrintStream pOut = new PrintStream(out);      net.save_bif(pOut);    }  }}

⌨️ 快捷键说明

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