Skip to content

Commit

Permalink
Replace pygtrie by a simplistic implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarbier committed Dec 30, 2019
1 parent 7eb928e commit 4c43f5c
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions mlxtend/frequent_patterns/apriori.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,34 @@

import numpy as np
import pandas as pd
import pygtrie
from ..frequent_patterns import fpcommon as fpc


class _FixedLengthTrie:
__slots__ = ("root")

def __init__(self, combinations):
self.root = dict()
for combination in combinations:
current = self.root
for item in combination:
try:
current = current[item]
except KeyError:
next_node = dict()
current[item] = next_node
current = next_node

def __contains__(self, combination):
current = self.root
try:
for item in combination:
current = current[item]
return True
except KeyError:
return False


def generate_new_combinations(old_combinations):
"""
Generator of all combinations based on the last state of Apriori algorithm
Expand Down Expand Up @@ -44,7 +68,7 @@ def generate_new_combinations(old_combinations):
"""

length = len(old_combinations)
trie = pygtrie.Trie(list(zip(old_combinations, [1]*length)))
trie = _FixedLengthTrie(old_combinations)
for i, old_combination in enumerate(old_combinations):
*head_i, _ = old_combination
j = i + 1
Expand Down

0 comments on commit 4c43f5c

Please sign in to comment.