I have an algorithm to run and at one of the steps I have to find duplicate pairs in a list called (PairList), count them and eliminate the pairs that are smaller than a specific parameter (minSupp).This is my code for adding the pairs to PairList.
for (int i = sizes.get(sequence.getId())-maxError ; i <= sizes.get(sequence.getId())-1; i++){
for(int j = i+1; j<sizes.get(sequence.getId()); j++){
//Get the first Item
int first = sequence.getItemsets().get(i);
//gets the second Item
int second =sequence.getItemsets().get(j);
//Generate pattern as pair
Pair pattern = new Pair(first, second);
sequenceID = sequence.getId();
//Generate triples with sequence ID and pair
Triples triples = new Triples(sequenceID, i, j);
if (!pairList.contains(pattern)){
//adds if it doesn't exist
pairList.add(pattern);
}
Now pairList contains some pairs like this: (3, 28) (3, 58) (3, 61) (3, 28) (5, 21) (3, 28) (5, 21) I want to know for instance how many times (3, 28) occurs in this List. and for a (minSupp=2) I want to remove the pairs that occurred less than 2 times So the output should be something like this:
(3, 28) : 3
(3, 58) : 1 (this must be removed)
(3, 61) : 1 remove
(5, 21) : 2
I worked on it and this is my code until now but it gives me an output far too much from what I want so please help!
for(Pair pair : pairList){
int a = Collections.frequency(pairList, pair);
for (int i=0 ; i<pairList.size() ; i++){
for (int j =i+1 ; j<pairList.size()-1;j++){
if (pairList.get(i).getX()==pairList.get(j).getX() && pairList.get(i).getY()==pairList.get(j).getY() ){
a++;
System.out.println(pair + ": " + a);
}