stability_label_algorithm/modules/argumentation/smallest_stable_set_calculator.py
def smallest_stable_sets(argumentation_system: ArgumentationSystem,
                         topics: List[Literal],
                         stability_labeler: LabelerInterface,
                         stability_function: Callable[[StabilityLabel], bool] = lambda x: x.is_contested_stable,
                         verbose: bool = False) -> List[List[Queryable]]:
    """
    Finds all smallest sets of observations for which each topic is stable.

    :param argumentation_system: Argumentation theory for which we compute the smallest stable sets
    :param topics: Topics that need to be stable in order to form a smallest_stable_set
    :param stability_labeler: Stability labelling object (e.g. FourBoolStabilityLabeler)
    :param stability_function: Function that checks if a given label is stable
    :param verbose: Boolean indicating if intermediate results should be printed to the console
    :return: All smallest sets of observations for which each topic is stable
    """

    # First check edge case: are all topics table in case we have no observations at all?
    initial_labels = stability_labeler.label(ArgumentationTheory(argumentation_system, []))
    if all([stability_function(initial_labels.literal_labeling[topic]) for topic in topics]):
        return [[]]

    # We will iteratively fill the smallest_stable_sets list
    smallest_stable_set_list: List[List[Queryable]] = []

    # Generate all unstable observable sets of size 1 (int representation). NB: (obs,) is a 1-tuple in Python.
    observables = sorted([q for q in argumentation_system.queryables])
    observable_sets_k_min_1_candidates = [(obs,) for obs in observables]
    observable_sets_k_min_1_unstable = []
    for obs_set in observable_sets_k_min_1_candidates:
        argumentation_theory = ArgumentationTheory(argumentation_system, list(obs_set))
        labels = stability_labeler.label(argumentation_theory)
        if all([stability_function(labels.literal_labeling[topic]) for topic in topics]):
            smallest_stable_set_list.append(list(obs_set))
            if verbose:
                print([str(o) for o in obs_set])
                for literal_str, literal in argumentation_system.language.items():
                    if literal in topics and labels.literal_labeling[literal].defended:
                        print(literal_str)
        else:
            observable_sets_k_min_1_unstable.append(obs_set)

    # Given all unstable observable sets of size (k - 1), generate all unstable observable sets of size k.
    while observable_sets_k_min_1_unstable:
        observable_sets_k_candidates = apriori_gen(observable_sets_k_min_1_unstable)
        observable_sets_k_unstable = []

        res = [join_and_prune_step(argumentation_system, topics, stability_labeler, stability_function, c, verbose)
               for c in observable_sets_k_candidates]

        for stable, unstable in res:
            smallest_stable_set_list = smallest_stable_set_list + stable
            observable_sets_k_unstable = observable_sets_k_unstable + unstable

        observable_sets_k_min_1_unstable = observable_sets_k_unstable

    return smallest_stable_set_list

    Finds all smallest sets of observations for which each topic is stable.

    :param argumentation_system: Argumentation theory for which we compute the smallest stable sets
    :param topics: Topics that need to be stable in order to form a smallest_stable_set
    :param stability_labeler: Stability labelling object (e.g. FourBoolStabilityLabeler)
    :param stability_function: Function that checks if a given label is stable
    :param verbose: Boolean indicating if intermediate results should be printed to the console
    :return: All smallest sets of observations for which each topic is stable
    
Finds all smallest sets of observations for which each topic is stable.
Finds all smallest sets of observations for which each topic is stable .
def smallest_stable_sets(argumentation_system: ArgumentationSystem,
                         topics: List[Literal],
                         stability_labeler: LabelerInterface,
                         stability_function: Callable[[StabilityLabel], bool] = lambda x: x.is_contested_stable,
                         verbose: bool = False) -> List[List[Queryable]]:
    initial_labels = stability_labeler.label(ArgumentationTheory(argumentation_system, []))
    if all([stability_function(initial_labels.literal_labeling[topic]) for topic in topics]):
        return [[]]
    smallest_stable_set_list: List[List[Queryable]] = []
    observables = sorted([q for q in argumentation_system.queryables])
    observable_sets_k_min_1_candidates = [(obs,) for obs in observables]
    observable_sets_k_min_1_unstable = []
    for obs_set in observable_sets_k_min_1_candidates:
        argumentation_theory = ArgumentationTheory(argumentation_system, list(obs_set))
        labels = stability_labeler.label(argumentation_theory)
        if all([stability_function(labels.literal_labeling[topic]) for topic in topics]):
            smallest_stable_set_list.append(list(obs_set))
            if verbose:
                print([str(o) for o in obs_set])
                for literal_str, literal in argumentation_system.language.items():
                    if literal in topics and labels.literal_labeling[literal].defended:
                        print(literal_str)
        else:
            observable_sets_k_min_1_unstable.append(obs_set)
    while observable_sets_k_min_1_unstable:
        observable_sets_k_candidates = apriori_gen(observable_sets_k_min_1_unstable)
        observable_sets_k_unstable = []
        res = [join_and_prune_step(argumentation_system, topics, stability_labeler, stability_function, c, verbose)
               for c in observable_sets_k_candidates]
        for stable, unstable in res:
            smallest_stable_set_list = smallest_stable_set_list + stable
            observable_sets_k_unstable = observable_sets_k_unstable + unstable
        observable_sets_k_min_1_unstable = observable_sets_k_unstable
    return smallest_stable_set_list
def smallest_stable_sets ( argumentation_system : ArgumentationSystem , topics : List [ Literal ] , stability_labeler : LabelerInterface , stability_function : Callable [ [ StabilityLabel ] , bool ] = lambda x : x . is_contested_stable , verbose : bool = False ) -> List [ List [ Queryable ] ] : initial_labels = stability_labeler . label ( ArgumentationTheory ( argumentation_system , [ ] ) ) if all ( [ stability_function ( initial_labels . literal_labeling [ topic ] ) for topic in topics ] ) : return [ [ ] ] smallest_stable_set_list : List [ List [ Queryable ] ] = [ ] observables = sorted ( [ q for q in argumentation_system . queryables ] ) observable_sets_k_min_1_candidates = [ ( obs , ) for obs in observables ] observable_sets_k_min_1_unstable = [ ] for obs_set in observable_sets_k_min_1_candidates : argumentation_theory = ArgumentationTheory ( argumentation_system , list ( obs_set ) ) labels = stability_labeler . label ( argumentation_theory ) if all ( [ stability_function ( labels . literal_labeling [ topic ] ) for topic in topics ] ) : smallest_stable_set_list . append ( list ( obs_set ) ) if verbose : print ( [ str ( o ) for o in obs_set ] ) for literal_str , literal in argumentation_system . language . items ( ) : if literal in topics and labels . literal_labeling [ literal ] . defended : print ( literal_str ) else : observable_sets_k_min_1_unstable . append ( obs_set ) while observable_sets_k_min_1_unstable : observable_sets_k_candidates = apriori_gen ( observable_sets_k_min_1_unstable ) observable_sets_k_unstable = [ ] res = [ join_and_prune_step ( argumentation_system , topics , stability_labeler , stability_function , c , verbose ) for c in observable_sets_k_candidates ] for stable , unstable in res : smallest_stable_set_list = smallest_stable_set_list + stable observable_sets_k_unstable = observable_sets_k_unstable + unstable observable_sets_k_min_1_unstable = observable_sets_k_unstable return smallest_stable_set_list
Finds all smallest sets of observations for which each topic is stable.
Finds all smallest sets of observations for which each topic is stable .
"""
    Finds all smallest sets of observations for which each topic is stable.

    :param argumentation_system: Argumentation theory for which we compute the smallest stable sets
    :param topics: Topics that need to be stable in order to form a smallest_stable_set
    :param stability_labeler: Stability labelling object (e.g. FourBoolStabilityLabeler)
    :param stability_function: Function that checks if a given label is stable
    :param verbose: Boolean indicating if intermediate results should be printed to the console
    :return: All smallest sets of observations for which each topic is stable
    """ # First check edge case: are all topics table in case we have no observations at all? # We will iteratively fill the smallest_stable_sets list # Generate all unstable observable sets of size 1 (int representation). NB: (obs,) is a 1-tuple in Python. # Given all unstable observable sets of size (k - 1), generate all unstable observable sets of size k.
All smallest sets of observations for which each topic is stable
All smallest sets of observations for which each topic is stable
argumentation_system
ArgumentationSystem
Argumentation theory for which we compute the smallest stable sets
Argumentation theory for which we compute the smallest stable sets
topics
List[Literal]
Topics that need to be stable in order to form a smallest_stable_set
Topics that need to be stable in order to form a smallest_stable_set
stability_labeler
LabelerInterface
Stability labelling object
Stability labelling object
stability_function
Callable[[StabilityLabel], bool]
Function that checks if a given label is stable
Function that checks if a given label is stable
verbose
bool
Boolean indicating if intermediate results should be printed to the console
Boolean indicating if intermediate results should be printed to the console