亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? apriori.java

?? 本編碼是最簡(jiǎn)單易懂但完整的java實(shí)現(xiàn)。對(duì)初學(xué)Apriori的java編程有幫助。
?? JAVA
字號(hào):
package datamining;

import java.io.*;
import java.util.*;

/**
 * A bare bone clean implementation of the Apriori
 * algorithm for finding frequent itemsets. Good for educational
 * purposes and as a root class for experimenting on 
 * optimizations.
 *
 * In the latest version the use of DataHandler is added for reading
 * the database.
 *
 * @author Michael Holler
 * @version 0.8, 16.03.2004
 */
public class Apriori {

  int pass;		// number of passes
  int total;		// total number of frequent itemsets
  int minsup;		// minimal support of itemset
  
  String filename;	// the filename of the database
  Item root;		// the root item of the Trie
  BufferedWriter writer;// the buffer to write the output to 
  DataHandler dh;	// the handler for the database

  /**
   * Default constructur for creating a Apriori object.
   */ 
  public Apriori() {
    this.pass = 0;
    this.minsup = 4;
    this.dh = new DataHandler("test.dat");
    this.root = new Item(0);
  }

  /**
   * Constructur for creating a Apriori object with parameters.
   *
   * @param	filename	the name of the database file
   * @param	minsup		the minimal support threshold
   * @param	outfile		the name of the output file
   */ 
  public Apriori(String filename, int minsup, String outfile) {
    this.pass = 0;
    this.minsup = minsup;
    this.dh = new DataHandler(filename);
    this.root = new Item(0);
    try {
      if (!outfile.equals("")) {
        writer = new BufferedWriter(new FileWriter(outfile));
      }
    } catch (Exception e) {}
  }

  /**
   * Constructur for creating a Apriori object with parameters.
   * This one is used with other mining algorithms.
   *
   * @param	minsup		the minimal support threshold
   * @param	datahandler	the handler for the database	
   */ 
  public Apriori(int minsup, DataHandler datahandler) {
    this.pass = 0;
    this.minsup = minsup;
    this.dh = datahandler;
    this.root = new Item(0);
  }

  /**
   * The workhorse method for the basic implementation of
   * the Apriori algorithm.
   */
  public void findFrequentSets() {
    boolean running = true;
    int candidates = 0, transactions= 0, pruned = 0, itemsets;

    while (running) {
      this.pass++;

      candidates = this.generateCandidates(this.root, new Vector(), 1);
      transactions = this.countSupport();
      pruned = this.pruneCandidates(this.root);

      itemsets = candidates - pruned;
      
      // correct the candidate count on first pass for printing
      if (this.pass == 1)
	candidates = total;

      total += itemsets;
      if (itemsets <= this.pass && this.pass > 1) {
        running = false;
      }	

      System.out.println("pass: " + this.pass + 
		         ", total: " + total +
		         ", candidates: " + candidates +
	     	         ", pruned: " + pruned);
    }    
  }  

  /**
   * Method for generating new candidates.
   * Copies the siblings of an item to its children.
   *
   * @param	item	the item to which generated items are added	 
   * @param	depth	the depth of recursion
   * @return		the number of new candidates generated
   */
  public int generateCandidates(Item item, Vector current, int depth) {
    Vector v = item.getChildren(); 
    Item child = item;
    int generated = 0;

    for (Enumeration e = v.elements(); e.hasMoreElements(); ) { 
      child = (Item)e.nextElement(); 
      current.add(child);

      if (depth == this.pass-1) {
	generated += this.copySiblings(child, v, current);
      } else {
        generated += this.generateCandidates(child, current, depth+1);
      }
      
      current.remove(child);
    } 
    return generated;
  }

  /**
   * Method for copying the siblings of an Item to its children.
   *
   * @param	item		the item to which the siblings are copied
   * @param	siblings	the siblings to be copied
   * @param	current		the current itemset to be generated
   * @return			the number of siblings copied
   */
  public int copySiblings(Item item, Vector siblings, Vector current) {
    Enumeration e = siblings.elements();
    Item parent = item;
    Item sibling = new Item(); 
    int copied = 0;

    while (sibling.getLabel() < parent.getLabel() && e.hasMoreElements()) {
      sibling = (Item)e.nextElement();
    }

    while (e.hasMoreElements()) {
      sibling = (Item)e.nextElement();
      current.add(sibling);
      if (this.pass <= 2 || this.checkSubsets(current, this.root.getChildren(), 0, 1)) {
        parent.addChild(new Item(sibling.getLabel()));     
	copied++;
      }
      current.remove(sibling);
    }

    return copied;
  }
  
  /**
   * Checks if the subsets of the itemset to be generated are all frequent.
   *
   * @param	current  	the current itemset to be generated	
   * @param	children	the children in the trie on this depth	
   * @param	mark		the mark in the current itemset
   * @param	depth		depth of recursion
   * @return			true if the subsets are frequent, else false	
   */
  public boolean checkSubsets(Vector current, Vector children, int mark, int depth) {
    boolean ok = true;
    Item child;
    int index;
    int i = depth;

    if (children == null) return false;

    while (ok && (mark <= i)) {
      index = children.indexOf(current.elementAt(i));
      if (index >= 0) {
        if (depth < this.pass-1) {
          child = (Item)children.elementAt(index);
          ok = checkSubsets(current, child.getChildren(), i+1, depth+1);
        }
      } else {
        ok = false;
      }
      i--;
    }

    return ok;
  }

  /**
   * Method for counting the supports of the candidates
   * generated on this pass.
   *
   * @return 		the number of transactions from which 
   * 			the support was counted
   */
  public int countSupport() {
    int rowcount = 0;
    int[] items;
    this.dh.open();
    for (items = this.dh.read(); items.length > 0; items = this.dh.read()) {
      rowcount++;
      if (this.pass == 1) {
        this.root.incSupport();
        this.total += generateFirstCandidates(items);
      } else {
        countSupport(root, items, 0, 1);
      }
    }
    return rowcount;
  }

  /**
   * Method generates the first candidates by adding each item
   * found in the database to the children of the root item. Also
   * counts the supports of the items found in the database.
   *
   * @param	items	the array of integer items from the database
   * @return		the number of candidates generated
   */
  public int generateFirstCandidates(int[] items) {
    Vector v = root.getChildren(); 
    Enumeration e = v.elements();
    Item item = new Item();
    int generated = 0;

    for (int i = 0; i < items.length; i++) { 

      while (e.hasMoreElements() && item.getLabel() < items[i]) {
        item = (Item)e.nextElement(); 
      }

      if (item.getLabel() == items[i]) {
        item.incSupport();
        if (e.hasMoreElements())
          item = (Item)e.nextElement(); 
      } else if (item.getLabel() > items[i]) {
        int index = v.indexOf(item);
        Item child = new Item(items[i]);
        child.incSupport();
        this.root.addChild(child, index); 
        generated++;
      } else { 
        Item child = new Item(items[i]);
        child.incSupport();
        this.root.addChild(child);
        generated++;
      }
    } 
    return generated;
  }

  /**
   * Adds the cover of the Item given as paramater and all the
   * Items in Trie below it.
   *
   * @param	item	the item the cover of which is to be counted
   * @param	items	the array of integer items from the database
   * @param	i 	the position in the array 
   * @param	depth	the depth of recursion 
   */
  public void countSupport(Item item, int[] items, int i, int depth) {
    Vector v = item.getChildren(); 
    Item child;
    int tmp;
    Enumeration e = v.elements();

    // loop through the children to check
    while (e.hasMoreElements()) {
      child = (Item)e.nextElement();
     
      // break, if the whole transaction is checked
      if (i == items.length) { break; }
      
      // do a linear search for the child in the transaction starting from i
      tmp = i;
      while (tmp < items.length && items[tmp] < child.getLabel()) tmp++;
      
      // if the same item exists, increase support or go deaper
      if (tmp < items.length && child.getLabel() == items[tmp]) {
        if (depth == this.pass) {
	  child.incSupport();
	} else {
          countSupport(child, items, tmp+1, depth+1);
        }
	i = tmp+1;
      }

    }
  }
  
  /**
   * Method for pruning the candidates. Removes items that are
   * not frequent from the Trie.
   *
   * @param	item	the item the children of which will be pruned
   * @return		the number of items pruned from the candidates
   */
  public int pruneCandidates(Item item) {
    Vector v = item.getChildren(); 
    Item child = item;
    int pruned = 0;
    
    for (Enumeration e = new Vector(v).elements(); e.hasMoreElements(); ) { 
      child = (Item)e.nextElement(); 

      // check infrequency, existence and that it is fully counted
      if (child.getSupport() < this.minsup) {
	v.remove(child);
	pruned++;
      } else {
        pruned += pruneCandidates(child);
      }
    }
    return pruned;
  }
  
  /**
   * Method gets and returns the root of the 
   * candidate trie.
   *
   * @return		the root of the candidate trie
   */ 
  public Item getTrie() {
    return this.root;
  }
  
  /**
   * Method prints the itemsets to the system output and to a file
   * if the name of an output file exists.
   */
  public void printFrequentSets() {
    if (this.writer != null) { 
      print(root, "");
    }
    System.out.println("\nnumber of frequent itemsets found: " + this.total);
  }
  
  /**
   * Loops through the Trie recursively adding 
   * paths and subpaths to the output string along the way.
   *
   * @param	item	the item where the recursion is
   * @param	str	the string of the gatherd itemset
   */
  public void print(Item item, String str) {
    Vector v = item.getChildren(); 

    for (Enumeration e = v.elements(); e.hasMoreElements(); ) { 
      item = (Item)e.nextElement(); 
      try {
        this.writer.write(str + item.getLabel() 
			  + " (" + item.getSupport() + ")\n");
        this.writer.flush();
      } catch (Exception x) { 
        System.out.println("no output file");
      }
      if (item.hasChildren()) {
        print(item, str + item.getLabel() + " ");
      }
    }
  }

  /**
   * Main method for testing the algorithm.
   *
   * @param 	args	the arguments can contain the filename
   * 			of the testfile and the minimal support
   * 			threshold and a filename for output
   */
  public static void main(String args[]) {
    String testfile = "test.dat";
    String outfile = "";
    int support = 5;
    try {
      testfile = args[0];
    } catch (Exception e) {
      System.out.println("Didn't get filename. Using '" + testfile + "'.");
    }
    try {
      support = new Integer(args[1]).intValue();
    } catch (Exception e) {
      System.out.println("Didn't get support threshold. Using '" + support + "'.");
    }	    
    try {
      outfile = args[2];
    } catch (Exception e) {
      System.out.println("Didn't get output filename. Not printing.");
    }

    StopWatch sw = new StopWatch();
    sw.start();
    Apriori apriori = new Apriori(testfile, support, outfile);
    apriori.findFrequentSets();
    apriori.printFrequentSets();
    sw.stop();
    sw.print();
  }


}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品日韩在线一区| 蜜臀91精品一区二区三区| 国产91对白在线观看九色| 久久亚洲私人国产精品va媚药| 伊人开心综合网| 日本一区二区三区国色天香 | 一区二区三区中文字幕| 大白屁股一区二区视频| 国产精品女主播av| 91麻豆成人久久精品二区三区| 国产精品久久久99| 欧美午夜免费电影| 蜜臀av性久久久久蜜臀av麻豆| 精品日韩一区二区三区 | 亚洲综合激情网| 欧美日韩免费高清一区色橹橹| 午夜一区二区三区在线观看| 欧美成人一区二区三区| 风流少妇一区二区| 亚洲一区二区三区在线播放| 日韩三级电影网址| 国产91丝袜在线播放九色| 亚洲欧美另类小说视频| 一区二区三区精密机械公司| 亚洲激情一二三区| 精品视频一区二区不卡| 日韩影院在线观看| 精品成人佐山爱一区二区| 成人网页在线观看| 欧美在线看片a免费观看| 国产成人av电影免费在线观看| 欧美福利电影网| 国产伦精品一区二区三区视频青涩 | 亚洲va国产va欧美va观看| 日韩视频免费观看高清完整版在线观看 | 欧美一区二区精品在线| 亚洲成av人**亚洲成av**| 久久免费视频色| 在线观看视频91| 国产成人综合在线播放| 夜夜精品浪潮av一区二区三区| 日韩欧美中文字幕一区| 91女神在线视频| 麻豆91小视频| 亚洲蜜臀av乱码久久精品| 日韩精品在线一区二区| 日本精品视频一区二区| 国产mv日韩mv欧美| 精久久久久久久久久久| 亚洲成av人**亚洲成av**| 中文字幕亚洲欧美在线不卡| 日韩三级精品电影久久久| 日本高清成人免费播放| 国产v日产∨综合v精品视频| 免费精品视频在线| 一区二区三区精品在线观看| 亚洲国产精品精华液ab| 欧美大白屁股肥臀xxxxxx| 欧美午夜精品理论片a级按摩| 国产成人自拍网| 捆绑调教美女网站视频一区| 亚洲va欧美va人人爽| 亚洲天天做日日做天天谢日日欢| 久久久天堂av| 国产亚洲福利社区一区| 日韩精品中文字幕一区| 色哟哟亚洲精品| 92精品国产成人观看免费| 国产91丝袜在线播放| 国产成人一级电影| 国产精品一区二区x88av| 久久99热狠狠色一区二区| 日韩av不卡在线观看| 午夜电影网一区| 午夜国产精品影院在线观看| 亚洲成人久久影院| 午夜精品福利视频网站| 婷婷丁香激情综合| 午夜精品成人在线视频| 视频一区二区三区中文字幕| 亚洲成人先锋电影| 男男gaygay亚洲| 免费在线一区观看| 国产在线视频一区二区| 国产在线播放一区二区三区| 国内欧美视频一区二区| 国产福利不卡视频| 国产成人精品影视| 东方aⅴ免费观看久久av| 成人黄色免费短视频| 91蜜桃网址入口| 91传媒视频在线播放| 精品视频免费看| 日韩一区二区三区电影| www国产亚洲精品久久麻豆| 久久久久久久久久久久久女国产乱 | 91福利在线看| 欧美日韩精品久久久| 精品少妇一区二区三区在线视频| 久久久久国产精品免费免费搜索| 国产片一区二区| 亚洲人快播电影网| 午夜久久电影网| 国产一区二区在线观看视频| 成人免费视频免费观看| 91久久免费观看| 日韩一区二区三区视频在线观看| 久久综合九色欧美综合狠狠| 国产精品私房写真福利视频| 一区二区三区中文在线观看| 全部av―极品视觉盛宴亚洲| 国产精品影视天天线| 97精品国产97久久久久久久久久久久| 在线观看欧美黄色| 久久综合久久综合久久| 亚洲色欲色欲www在线观看| 五月天一区二区| 国产成a人亚洲精品| 精品视频在线免费看| 久久久久久久久一| 亚洲成人免费视频| 国产iv一区二区三区| 欧美日韩国产小视频在线观看| 久久综合九色综合97婷婷女人 | 成人爱爱电影网址| 在线不卡的av| 国产精品久久久久婷婷| 日本女优在线视频一区二区| 成人激情综合网站| 精品少妇一区二区三区视频免付费| 国产精品久久精品日日| 久久精品国产成人一区二区三区 | 欧美美女bb生活片| 欧美国产日本韩| 日韩精品91亚洲二区在线观看 | 欧美日韩第一区日日骚| 中文字幕免费观看一区| 美腿丝袜亚洲一区| 欧美日韩在线精品一区二区三区激情| 国产亚洲一区二区在线观看| 日韩在线观看一区二区| 91久久国产综合久久| 成人欧美一区二区三区1314| 狠狠狠色丁香婷婷综合激情| 欧美日韩在线电影| 亚洲精品免费电影| 成人av电影在线网| 久久精品夜色噜噜亚洲a∨| 日本一不卡视频| 精品视频免费在线| 亚洲图片你懂的| 高清不卡一区二区| 久久精品在线免费观看| 精品在线亚洲视频| 日韩美女视频一区二区在线观看| 亚洲成人免费影院| 欧美影视一区二区三区| 综合久久国产九一剧情麻豆| 大桥未久av一区二区三区中文| 精品乱人伦小说| 久久99精品久久久| 日韩免费视频一区二区| 日韩国产高清影视| 欧美绝品在线观看成人午夜影视| 亚洲综合一区在线| 色八戒一区二区三区| 亚洲欧美成aⅴ人在线观看| 成人黄色免费短视频| 国产精品久久久久桃色tv| 成人黄色大片在线观看| 国产精品传媒入口麻豆| 成人国产精品免费观看动漫 | 国产精品久久久久三级| 91在线观看视频| 伊人性伊人情综合网| 欧美中文字幕亚洲一区二区va在线| 日韩码欧中文字| 欧美在线观看一区| 视频在线在亚洲| 日韩欧美一卡二卡| 国产乱码精品一区二区三区av| 久久免费电影网| 高清不卡在线观看| 亚洲猫色日本管| 91精品午夜视频| 精品夜夜嗨av一区二区三区| 久久精品一区八戒影视| 99视频精品在线| 亚洲一区av在线| 欧美精品一二三| 激情综合色播五月| 久久女同性恋中文字幕| 成人在线一区二区三区| 国产精品色一区二区三区| 91黄色免费观看| 天使萌一区二区三区免费观看| 欧美电影免费观看高清完整版在线 | 亚洲欧美一区二区三区久本道91| 欧洲av一区二区嗯嗯嗯啊| 日韩av一级电影|