def apply_auto_filter(log, variants=None, parameters=None): """ Apply an end attributes filter detecting automatically a percentage Parameters ---------- log Log variants (If specified) Dictionary with variant as the key and the list of traces as the value parameters Parameters of the algorithm, including: Parameters.DECREASING_FACTOR -> Decreasing factor (stops the algorithm when the next activity by occurrence is below this factor in comparison to previous) Parameters.ACTIVITY_KEY -> Attribute key (must be specified if different from concept:name) Returns --------- filtered_log Filtered log """ if parameters is None: parameters = {} attribute_key = exec_utils.get_param_value(Parameters.ACTIVITY_KEY, parameters, DEFAULT_NAME_KEY) decreasing_factor = exec_utils.get_param_value( Parameters.DECREASING_FACTOR, parameters, filtering_constants.DECREASING_FACTOR) if len(log) > 0: parameters_variants = {PARAMETER_CONSTANT_ACTIVITY_KEY: attribute_key} if variants is None: variants = variants_filter.get_variants( log, parameters=parameters_variants) vc = variants_filter.get_variants_sorted_by_count(variants) end_activities = get_end_activities(log, parameters=parameters_variants) ealist = end_activities_common.get_sorted_end_activities_list( end_activities) eathreshold = end_activities_common.get_end_activities_threshold( ealist, decreasing_factor) filtered_log = filter_log_by_end_activities(end_activities, variants, vc, eathreshold, attribute_key) return filtered_log return log
def apply_auto_filter(log, variants=None, parameters=None): """ Apply an end attributes filter detecting automatically a percentage Parameters ---------- log Log variants (If specified) Dictionary with variant as the key and the list of traces as the value parameters Parameters of the algorithm, including: decreasingFactor -> Decreasing factor (stops the algorithm when the next activity by occurrence is below this factor in comparison to previous) attribute_key -> Attribute key (must be specified if different from concept:name) Returns --------- filtered_log Filtered log """ if parameters is None: parameters = {} attribute_key = parameters[ PARAMETER_CONSTANT_ACTIVITY_KEY] if PARAMETER_CONSTANT_ACTIVITY_KEY in parameters else DEFAULT_NAME_KEY decreasing_factor = parameters[ "decreasingFactor"] if "decreasingFactor" in parameters else DECREASING_FACTOR parameters_variants = { constants.PARAMETER_CONSTANT_ACTIVITY_KEY: attribute_key } if variants is None: variants = variants_filter.get_variants(log, parameters=parameters_variants) vc = variants_filter.get_variants_sorted_by_count(variants) start_activities = get_start_activities(log, parameters=parameters_variants) salist = start_activities_common.get_sorted_start_activities_list( start_activities) sathreshold = start_activities_common.get_start_activities_threshold( salist, decreasing_factor) filtered_log = filter_log_by_start_activities(start_activities, variants, vc, sathreshold, attribute_key) return filtered_log
def apply_auto_filter(log, variants=None, parameters=None): """ Apply an attributes filter detecting automatically a percentage Parameters ---------- log Log variants (If specified) Dictionary with variant as the key and the list of traces as the value parameters Parameters of the algorithm, including: Parameters.DECREASING_FACTOR -> Decreasing factor (stops the algorithm when the next activity by occurrence is below this factor in comparison to previous) Parameters.ATTRIBUTE_KEY -> Attribute key (must be specified if different from concept:name) Returns --------- filtered_log Filtered log_skeleton """ if parameters is None: parameters = {} attribute_key = exec_utils.get_param_value(Parameters.ATTRIBUTE_KEY, parameters, xes.DEFAULT_NAME_KEY) decreasing_factor = exec_utils.get_param_value( Parameters.DECREASING_FACTOR, parameters, filtering_constants.DECREASING_FACTOR) parameters_variants = { variants_filter.Parameters.ACTIVITY_KEY: attribute_key } if variants is None: variants = variants_filter.get_variants(log, parameters=parameters_variants) vc = variants_filter.get_variants_sorted_by_count(variants) pths = get_paths_from_log(log, attribute_key=attribute_key) plist = get_sorted_paths_list(pths) thresh = get_paths_threshold(plist, decreasing_factor) filtered_log = filter_log_by_paths(log, pths, variants, vc, thresh, attribute_key) return filtered_log
def apply_log(log, net, initial_marking, final_marking, enable_pltr_fitness=False, consider_remaining_in_fitness=False, activity_key="concept:name", reach_mark_through_hidden=True, stop_immediately_unfit=False, walk_through_hidden_trans=True, places_shortest_path_by_hidden=None, variants=None, is_reduction=False, thread_maximum_ex_time=MAX_DEF_THR_EX_TIME, cleaning_token_flood=False, disable_variants=False): """ Apply token-based replay to a log Parameters ---------- log Trace log net Petri net initial_marking Initial marking final_marking Final marking enable_pltr_fitness Enable fitness calculation at place level consider_remaining_in_fitness Boolean value telling if the remaining tokens should be considered in fitness evaluation activity_key Name of the attribute that contains the activity reach_mark_through_hidden Boolean value that decides if we shall try to reach the final marking through hidden transitions stop_immediately_unfit Boolean value that decides if we shall stop immediately when a non-conformance is detected walk_through_hidden_trans Boolean value that decides if we shall walk through hidden transitions in order to enable visible transitions places_shortest_path_by_hidden Shortest paths between places by hidden transitions variants List of variants contained in the event log is_reduction Expresses if the token-based replay is called in a reduction attempt thread_maximum_ex_time Alignment threads maximum allowed execution time cleaning_token_flood Decides if a cleaning of the token flood shall be operated disable_variants Disable variants grouping """ post_fix_cache = PostFixCaching() marking_to_activity_cache = MarkingToActivityCaching() if places_shortest_path_by_hidden is None: places_shortest_path_by_hidden = get_places_shortest_path_by_hidden( net) place_fitness_per_trace = {} transition_fitness_per_trace = {} aligned_traces = [] if enable_pltr_fitness: for place in net.places: place_fitness_per_trace[place] = { "underfed_traces": set(), "overfed_traces": set() } for transition in net.transitions: if transition.label: transition_fitness_per_trace[transition] = { "underfed_traces": {}, "fit_traces": {} } s_components = [] if cleaning_token_flood: s_components = get_s_components_from_petri(net, initial_marking, final_marking) notexisting_activities_in_model = {} trans_map = {} for t in net.transitions: trans_map[t.label] = t if len(log) > 0: if len(log[0]) > 0: if activity_key in log[0][0]: if variants is None: variants = get_variants_from_log( log, activity_key, disable_variants=disable_variants) vc = variants_module.get_variants_sorted_by_count(variants) threads = {} threads_results = {} all_activated_transitions = set() for i in range(len(vc)): variant = vc[i][0] threads_keys = list(threads.keys()) while len(threads_keys) > MAX_NO_THREADS: threads, threads_results, all_activated_transitions = check_threads( net, threads, threads_results, all_activated_transitions, is_reduction=is_reduction) if is_reduction and len(all_activated_transitions ) == len(net.transitions): break threads_keys = list(threads.keys()) threads, threads_results, all_activated_transitions = check_threads( net, threads, threads_results, all_activated_transitions, is_reduction=is_reduction) if is_reduction and len(all_activated_transitions) == len( net.transitions): break threads[variant] = ApplyTraceTokenReplay( variants[variant][0], net, initial_marking, final_marking, trans_map, enable_pltr_fitness, place_fitness_per_trace, transition_fitness_per_trace, notexisting_activities_in_model, places_shortest_path_by_hidden, consider_remaining_in_fitness, activity_key=activity_key, reach_mark_through_hidden=reach_mark_through_hidden, stop_immediately_when_unfit=stop_immediately_unfit, walk_through_hidden_trans=walk_through_hidden_trans, post_fix_caching=post_fix_cache, marking_to_activity_caching=marking_to_activity_cache, is_reduction=is_reduction, thread_maximum_ex_time=thread_maximum_ex_time, cleaning_token_flood=cleaning_token_flood, s_components=s_components) threads[variant].start() while len(threads) > 0: threads_keys = list(threads.keys()) t = threads[threads_keys[0]] t.join() threads, threads_results, all_activated_transitions = check_threads( net, threads, threads_results, all_activated_transitions, is_reduction=is_reduction) if is_reduction and len(all_activated_transitions) == len( net.transitions): break for trace in log: # trace_variant = ",".join([x[activity_key] for x in trace]) trace_variant = get_variant_from_trace( trace, activity_key, disable_variants=disable_variants) if trace_variant in threads_results: t = threads_results[trace_variant] aligned_traces.append(t) else: raise NoConceptNameException("at least an event is without " + activity_key) if enable_pltr_fitness: return aligned_traces, place_fitness_per_trace, transition_fitness_per_trace, notexisting_activities_in_model else: return aligned_traces