stability_label_algorithm/modules/argumentation/smallest_stable_set_calculator.py
def prune_step(item_sets: List[Tuple[T, ...]], possible_item_sets: List[Tuple[T, ...]]) -> List[Tuple[T, ...]]:
    """
    Prune possible item_sets whose subsets are not in the list of item_sets.

    :param item_sets: A list of item_sets of length k.
    :param possible_item_sets: A list of possible item_sets of length k + 1 to be pruned.
    :return: A pruned list of item_sets of length k + 1

    >>> example_item_sets = [('a', 'b', 'c'), ('a', 'b', 'd'),
    ...             ('b', 'c', 'd'), ('a', 'c', 'd')]
    >>> example_possible_item_sets = join_step(example_item_sets)
    >>> prune_step(example_item_sets, example_possible_item_sets)
    [('a', 'b', 'c', 'd')]
    """
    result = []

    # For faster lookups
    hash_codes = set(hash(item) for item in item_sets)

    # Go through every possible item set
    for possible_item_set in possible_item_sets:
        # Remove 1 from the combination, same as k-1 combinations. The item_sets created by removing the last two
        # items in the possible item_sets must be part of the item_sets by definition, due to the way the `join_step`
        # function merges the sorted item_sets

        for i in range(len(possible_item_set) - 2):
            removed = possible_item_set[:i] + possible_item_set[i + 1:]
            hash_code = hash(removed)

            # If every k combination exists in the set of item_sets, yield the possible item set. If it does not
            # exist, then its support cannot be large enough, since supp(A) >= supp(AB) for all B, and if supp(S) is
            # large enough, then supp(s) must be large enough for every s which is a subset of S.
            # This is the downward-closure property of the support function.
            # if removed not in item_sets:
            if hash_code not in hash_codes:
                break

        # If there is no break yet
        else:
            result.append(possible_item_set)

    return result

    Prune possible item_sets whose subsets are not in the list of item_sets.

    :param item_sets: A list of item_sets of length k.
    :param possible_item_sets: A list of possible item_sets of length k + 1 to be pruned.
    :return: A pruned list of item_sets of length k + 1

    >>> example_item_sets = [('a', 'b', 'c'), ('a', 'b', 'd'),
    ...             ('b', 'c', 'd'), ('a', 'c', 'd')]
    >>> example_possible_item_sets = join_step(example_item_sets)
    >>> prune_step(example_item_sets, example_possible_item_sets)
    [('a', 'b', 'c', 'd')]
    
Prune possible item_sets whose subsets are not in the list of item_sets.
Prune possible item_sets whose subsets are not in the list of item_sets .
def prune_step(item_sets: List[Tuple[T, ...]], possible_item_sets: List[Tuple[T, ...]]) -> List[Tuple[T, ...]]:
    result = []
    hash_codes = set(hash(item) for item in item_sets)
    for possible_item_set in possible_item_sets:
        for i in range(len(possible_item_set) - 2):
            removed = possible_item_set[:i] + possible_item_set[i + 1:]
            hash_code = hash(removed)
            if hash_code not in hash_codes:
                break
        else:
            result.append(possible_item_set)
    return result
def prune_step ( item_sets : List [ Tuple [ T , ... ] ] , possible_item_sets : List [ Tuple [ T , ... ] ] ) -> List [ Tuple [ T , ... ] ] : result = [ ] hash_codes = set ( hash ( item ) for item in item_sets ) for possible_item_set in possible_item_sets : for i in range ( len ( possible_item_set ) - 2 ) : removed = possible_item_set [ : i ] + possible_item_set [ i + 1 : ] hash_code = hash ( removed ) if hash_code not in hash_codes : break else : result . append ( possible_item_set ) return result
Prune possible item_sets whose subsets are not in the list of item_sets.
Prune possible item_sets whose subsets are not in the list of item_sets .
"""
    Prune possible item_sets whose subsets are not in the list of item_sets.

    :param item_sets: A list of item_sets of length k.
    :param possible_item_sets: A list of possible item_sets of length k + 1 to be pruned.
    :return: A pruned list of item_sets of length k + 1

    >>> example_item_sets = [('a', 'b', 'c'), ('a', 'b', 'd'),
    ...             ('b', 'c', 'd'), ('a', 'c', 'd')]
    >>> example_possible_item_sets = join_step(example_item_sets)
    >>> prune_step(example_item_sets, example_possible_item_sets)
    [('a', 'b', 'c', 'd')]
    """ # For faster lookups # Go through every possible item set # Remove 1 from the combination, same as k-1 combinations. The item_sets created by removing the last two # items in the possible item_sets must be part of the item_sets by definition, due to the way the `join_step` # function merges the sorted item_sets # If every k combination exists in the set of item_sets, yield the possible item set. If it does not # exist, then its support cannot be large enough, since supp(A) >= supp(AB) for all B, and if supp(S) is # large enough, then supp(s) must be large enough for every s which is a subset of S. # This is the downward-closure property of the support function. # if removed not in item_sets: # If there is no break yet
None
item_sets
List[Tuple[T, ...]]
A list of item_sets of length k.
A list of item_sets of length k .
possible_item_sets
List[Tuple[T, ...]]
A list of possible item_sets of length k + 1 to be pruned.
A list of possible item_sets of length k + 1 to be pruned .