File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed
mlxtend/frequent_patterns Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change 66
77import numpy as np
88import pandas as pd
9- import pygtrie
109from ..frequent_patterns import fpcommon as fpc
1110
1211
12+ class _FixedLengthTrie :
13+ __slots__ = ("root" )
14+
15+ def __init__ (self , combinations ):
16+ self .root = dict ()
17+ for combination in combinations :
18+ current = self .root
19+ for item in combination :
20+ try :
21+ current = current [item ]
22+ except KeyError :
23+ next_node = dict ()
24+ current [item ] = next_node
25+ current = next_node
26+
27+ def __contains__ (self , combination ):
28+ current = self .root
29+ try :
30+ for item in combination :
31+ current = current [item ]
32+ return True
33+ except KeyError :
34+ return False
35+
36+
1337def generate_new_combinations (old_combinations ):
1438 """
1539 Generator of all combinations based on the last state of Apriori algorithm
@@ -44,7 +68,7 @@ def generate_new_combinations(old_combinations):
4468 """
4569
4670 length = len (old_combinations )
47- trie = pygtrie . Trie ( list ( zip ( old_combinations , [ 1 ] * length )) )
71+ trie = _FixedLengthTrie ( old_combinations )
4872 for i , old_combination in enumerate (old_combinations ):
4973 * head_i , _ = old_combination
5074 j = i + 1
You can’t perform that action at this time.
0 commit comments