在频繁的项目集挖掘中创建用于计算对,三胞胎等的哈希表

时间:2018-11-09 21:07:48

标签: java apriori

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class FreqItemset {

    // method to read parameters of file ( bucket and min sup)
    public int[] no_of_baskets_and_minsup(BufferedReader br) throws IOException {
        String line1 = br.readLine();
        return new int[] {Integer.parseInt(line1.split(" ")[0]), Integer.parseInt(line1.split(" ")[1])};
    }

    public void pass1(String file) {

        try {
            BufferedReader inputbr = new BufferedReader(new FileReader(file));
            int res[] = no_of_baskets_and_minsup(inputbr);
            int baskets = res[0];
            int minsup = res[1];
            System.out.println("Number of bukcets:"+baskets);
            System.out.println("Min support is:"+minsup);

            //pass 1 logic
            String basket=null;
            int[] unique_items = new int[100];
            while( (basket = inputbr.readLine()) !=null ) {  // for each basket

                String[] temp = basket.split(",");
                for(int i =1; i<temp.length; i++) {          // for each item in basket

                    unique_items[Integer.parseInt(temp[i])]++;   // increment counts
                }

                //todo create hashtable maintaing bukcet and count

                //For each pair of items in a basket.. 
                  // hash the pair to a bukce;
                  // add 1 to the count of that bukcet;
            }
        } catch (Exception ex) {
            System.out.println("Something wrong in Phase 1 :" + ex.getMessage() + "\n\n" + ex.getStackTrace());

        }
    }

    public static void main(String[] args) {

        String filename = "input.txt";
        long t1= System.currentTimeMillis();
        FreqItemset obj = new FreqItemset();
        obj.pass1(filename);
        long t2= System.currentTimeMillis();
        System.out.println("Time mili "+(t2-t1));
    }
}

在使用Multihash技术实现PCY算法以进行频繁项集挖掘时,在第1步中,我需要创建1个项集及其计数的数组。现在,我需要考虑每个篮子中的每一对,并使用哈希函数将其哈希到存储桶中。我必须在Pass 1(multihash PCY)中创建2个具有表的表。

我无法找到一种方法:给定一对i,j项,我应该如何使用自己的哈希表来实现哈希表等功能。 (i * j)%51和其他类似的值用于第二个哈希表。

我阅读了很多有关散列表的哈希表,但没有找到解决方法。

0 个答案:

没有答案