stability_label_algorithm/modules/argumentation/smallest_stable_set_calculator.py
def join_step(item_sets: List[Tuple[T, ...]]) -> List[Tuple[T, ...]]:
    """
    Join k length item_sets into k + 1 length item_sets.

    This algorithm assumes that the list of item_sets are sorted, and that the item_sets themselves are sorted tuples.
    Instead of always enumerating all n^2 combinations, the algorithm only has n^2 runtime for each block of
    item_sets with the first k - 1 items equal.

    :param item_sets: A list of item sets of length k, to be joined to k + 1 length item sets
    :return: A list of k + 1 length item sets

    >>> # This is an example from the 1994 paper by Agrawal et al.
    >>> example_item_sets = [(1, 2, 3), (1, 2, 4), (1, 3, 4), (1, 3, 5), (2, 3, 4)]
    >>> join_step(example_item_sets)
    [(1, 2, 3, 4), (1, 3, 4, 5)]
    """
    result = []

    i = 0
    # Iterate over every item set in the item_sets
    while i < len(item_sets):

        # The number of rows to skip in the while-loop, initially set to 1
        skip = 1

        # Get all but the last item in the item set, and the last item
        *item_set_first, item_set_last = item_sets[i]

        # We now iterate over every item set following this one, stopping if the first k - 1 items are not equal.
        # If we're at (1, 2, 3), we'll consider (1, 2, 4) and (1, 2, 7), but not (1, 3, 1)

        # Keep a list of all last elements, i.e. tail elements, to perform 2-combinations on later on
        tail_items = [item_set_last]
        tail_items_append = tail_items.append  # Micro-optimization

        # Iterate over ever item set following this item set
        for j in range(i + 1, len(item_sets)):

            # Get all but the last item in the item set, and the last item
            *item_set_n_first, item_set_n_last = item_sets[j]

            # If it's the same, append and skip this item set in while-loop
            if item_set_first == item_set_n_first:

                # Micro-optimization
                tail_items_append(item_set_n_last)
                skip += 1

            # If it's not the same, break out of the for-loop
            else:
                break

        # For every 2-combination in the tail items, yield a new candidate item set, which is sorted.
        item_set_first_tuple = tuple(item_set_first)
        for a, b in sorted(itertools.combinations(tail_items, 2)):
            result.append(item_set_first_tuple + (a,) + (b,))

        # Increment the while-loop counter
        i += skip

    return result

    Join k length item_sets into k + 1 length item_sets.

    This algorithm assumes that the list of item_sets are sorted, and that the item_sets themselves are sorted tuples.
    Instead of always enumerating all n^2 combinations, the algorithm only has n^2 runtime for each block of
    item_sets with the first k - 1 items equal.

    :param item_sets: A list of item sets of length k, to be joined to k + 1 length item sets
    :return: A list of k + 1 length item sets

    >>> # This is an example from the 1994 paper by Agrawal et al.
    >>> example_item_sets = [(1, 2, 3), (1, 2, 4), (1, 3, 4), (1, 3, 5), (2, 3, 4)]
    >>> join_step(example_item_sets)
    [(1, 2, 3, 4), (1, 3, 4, 5)]
    
Join k length item_sets into k + 1 length item_sets.
This algorithm assumes that the list of item_sets are sorted, and that the item_sets themselves are sorted tuples.
Instead of always enumerating all n^2 combinations, the algorithm only has n^2 runtime for each block of
item_sets with the first k - 1 items equal.
Join k length item_sets into k + 1 length item_sets . This algorithm assumes that the list of item_sets are sorted and that the item_sets themselves are sorted tuples . Instead of always enumerating all n^2 combinations the algorithm only has n^2 runtime for each block of item_sets with the first k - 1 items equal .
def join_step(item_sets: List[Tuple[T, ...]]) -> List[Tuple[T, ...]]:
    result = []
    i = 0
    while i < len(item_sets):
        skip = 1
        *item_set_first, item_set_last = item_sets[i]
        tail_items = [item_set_last]
        tail_items_append = tail_items.append  
        for j in range(i + 1, len(item_sets)):
            *item_set_n_first, item_set_n_last = item_sets[j]
            if item_set_first == item_set_n_first:
                tail_items_append(item_set_n_last)
                skip += 1
            else:
                break
        item_set_first_tuple = tuple(item_set_first)
        for a, b in sorted(itertools.combinations(tail_items, 2)):
            result.append(item_set_first_tuple + (a,) + (b,))
        i += skip
    return result
def join_step ( item_sets : List [ Tuple [ T , ... ] ] ) -> List [ Tuple [ T , ... ] ] : result = [ ] i = 0 while i < len ( item_sets ) : skip = 1 * item_set_first , item_set_last = item_sets [ i ] tail_items = [ item_set_last ] tail_items_append = tail_items . append for j in range ( i + 1 , len ( item_sets ) ) : * item_set_n_first , item_set_n_last = item_sets [ j ] if item_set_first == item_set_n_first : tail_items_append ( item_set_n_last ) skip += 1 else : break item_set_first_tuple = tuple ( item_set_first ) for a , b in sorted ( itertools . combinations ( tail_items , 2 ) ) : result . append ( item_set_first_tuple + ( a , ) + ( b , ) ) i += skip return result
Join k length item_sets into k + 1 length item_sets.
Join k length item_sets into k + 1 length item_sets .
"""
    Join k length item_sets into k + 1 length item_sets.

    This algorithm assumes that the list of item_sets are sorted, and that the item_sets themselves are sorted tuples.
    Instead of always enumerating all n^2 combinations, the algorithm only has n^2 runtime for each block of
    item_sets with the first k - 1 items equal.

    :param item_sets: A list of item sets of length k, to be joined to k + 1 length item sets
    :return: A list of k + 1 length item sets

    >>> # This is an example from the 1994 paper by Agrawal et al.
    >>> example_item_sets = [(1, 2, 3), (1, 2, 4), (1, 3, 4), (1, 3, 5), (2, 3, 4)]
    >>> join_step(example_item_sets)
    [(1, 2, 3, 4), (1, 3, 4, 5)]
    """ # Iterate over every item set in the item_sets # The number of rows to skip in the while-loop, initially set to 1 # Get all but the last item in the item set, and the last item # We now iterate over every item set following this one, stopping if the first k - 1 items are not equal. # If we're at (1, 2, 3), we'll consider (1, 2, 4) and (1, 2, 7), but not (1, 3, 1) # Keep a list of all last elements, i.e. tail elements, to perform 2-combinations on later on # Micro-optimization # Iterate over ever item set following this item set # Get all but the last item in the item set, and the last item # If it's the same, append and skip this item set in while-loop # Micro-optimization # If it's not the same, break out of the for-loop # For every 2-combination in the tail items, yield a new candidate item set, which is sorted. # Increment the while-loop counter
A list of k + 1 length item sets
>>> # This is an example from the 1994 paper by Agrawal et al.
A list of k + 1 length item sets >>> # This is an example from the 1994 paper by Agrawal et al .
item_sets
List[Tuple[T, ...]]
A list of item sets of length k, to be joined to k + 1 length item sets
A list of item sets of length k to be joined to k + 1 length item sets