def calculate(heu_net: HeuristicsNet, dependency_thresh: float, and_measure_thresh: float, heu_net_decoration: str) -> HeuristicsNet: """ Calculates the dependency matrix and the AND measures using the Heuristics Miner ++ formulas Parameters ---------------- heu_net Heuristics net dependency_thresh Dependency threshold and_measure_thresh AND measure threshold heu_net_decoration Decoration to use (frequency/performance) Returns ---------------- heu_net Heuristics net """ heu_net.performance_matrix = {} heu_net.dependency_matrix = {} heu_net.dfg_matrix = {} for el in heu_net.dfg: act1 = el[0] act2 = el[1] if act1 not in heu_net.dfg_matrix: heu_net.dfg_matrix[act1] = {} heu_net.dependency_matrix[act1] = {} heu_net.performance_matrix[act1] = {} heu_net.dfg_matrix[act1][act2] = heu_net.dfg[el] heu_net.dependency_matrix[act1][act2] = -1 heu_net.performance_matrix[act1][act2] = heu_net.performance_dfg[ el] if heu_net.performance_dfg else 0.0 for act1 in heu_net.activities: heu_net.nodes[act1] = Node(heu_net, act1, heu_net.activities_occurrences[act1], node_type=heu_net.node_type) # calculates the dependencies between the activities heu_net = calculate_dependency(heu_net, dependency_thresh, heu_net_decoration) # calculates the AND measure for outgoing edges (e.g. which activities happen in parallel after a given activity) heu_net = calculate_and_out_measure(heu_net, and_measure_thresh) # calculates the AND measure for ingoing edges (e.g. which activities happen in parallel before a given activity) heu_net = calculate_and_in_measure(heu_net, and_measure_thresh) return heu_net
def calculate_dependency(heu_net: HeuristicsNet, dependency_thresh: float, heu_net_decoration: str) -> HeuristicsNet: """ Calculates the dependency matrix using the Heuristics Miner ++ formula Parameters -------------- heu_net Heuristics net dependency_thresh Dependency threshold heu_net_decoration Decoration to include (frequency/performance) Returns --------------- heu_net Heuristics net (enriched) """ for act1 in heu_net.activities: if act1 in heu_net.dfg_matrix: for act2 in heu_net.dfg_matrix[act1]: v1 = heu_net.dfg_matrix[act1][act2] v2 = heu_net.dfg_matrix[act2][act1] if act2 in heu_net.dfg_matrix and act1 in heu_net.dfg_matrix[ act2] else 0.0 tup = tuple(sorted((act1, act2))) # added term for Heuristics Miner ++ v3 = heu_net.concurrent_activities[tup] if tup in heu_net.concurrent_activities else 0.0 dep = (v1 - v2) / (v1 + v2 + v3) heu_net.dependency_matrix[act1][act2] = dep if dep > dependency_thresh: repr_value = v1 if heu_net_decoration == "frequency" else heu_net.performance_matrix[act1][act2] heu_net.nodes[act1].add_output_connection(heu_net.nodes[act2], dep, v1, repr_value=repr_value) heu_net.nodes[act2].add_input_connection(heu_net.nodes[act1], dep, v1, repr_value=repr_value) return heu_net
def discover_heu_net_plus_plus(start_activities, end_activities, activities_occurrences, dfg, performance_dfg, sojourn_time, concurrent_activities, parameters: Optional[Dict[Any, Any]] = None): """ Discovers an heuristics net using the Heuristics Miner ++ algorithm Implements the approach described in Burattin, Andrea, and Alessandro Sperduti. "Heuristics Miner for Time Intervals." ESANN. 2010. https://andrea.burattin.net/public-files/publications/2010-esann-slides.pdf Parameters -------------- start_activities Start activities end_activities End activities activities_occurrences Activities along with their number of occurrences dfg Directly-follows graph performance_dfg (Performance) Directly-follows graph sojourn_time Sojourn time for each activity concurrent_activities Concurrent activities parameters Parameters of the algorithm, including: - Parameters.DEPENDENCY_THRESH - Parameters.AND_MEASURE_THRESH - Parameters.MIN_ACT_COUNT - Parameters.MIN_DFG_OCCURRENCES - Parameters.HEU_NET_DECORATION Returns -------------- heu_net Heuristics net """ if parameters is None: parameters = {} dependency_thresh = exec_utils.get_param_value( Parameters.DEPENDENCY_THRESH, parameters, defaults.DEFAULT_DEPENDENCY_THRESH) and_measure_thresh = exec_utils.get_param_value( Parameters.AND_MEASURE_THRESH, parameters, defaults.DEFAULT_AND_MEASURE_THRESH) min_act_count = exec_utils.get_param_value(Parameters.MIN_ACT_COUNT, parameters, defaults.DEFAULT_MIN_ACT_COUNT) min_dfg_occurrences = exec_utils.get_param_value( Parameters.MIN_DFG_OCCURRENCES, parameters, defaults.DEFAULT_MIN_DFG_OCCURRENCES) heu_net_decoration = exec_utils.get_param_value( Parameters.HEU_NET_DECORATION, parameters, "frequency") # filter on activity and paths occurrence activities_occurrences = { x: y for x, y in activities_occurrences.items() if y >= min_act_count } dfg = { x: y for x, y in dfg.items() if y >= min_dfg_occurrences and x[0] in activities_occurrences and x[1] in activities_occurrences } performance_dfg = {x: y for x, y in performance_dfg.items() if x in dfg} start_activities = { x: y for x, y in start_activities.items() if x in activities_occurrences } end_activities = { x: y for x, y in end_activities.items() if x in activities_occurrences } activities = list(activities_occurrences.keys()) if heu_net_decoration == "frequency": heu_net = HeuristicsNet(dfg, activities=activities, activities_occurrences=activities_occurrences, start_activities=start_activities, end_activities=end_activities) else: heu_net = HeuristicsNet(dfg, activities=activities, activities_occurrences=activities_occurrences, start_activities=start_activities, end_activities=end_activities, performance_dfg=performance_dfg) heu_net.min_dfg_occurrences = min_dfg_occurrences heu_net.sojourn_times = sojourn_time heu_net.concurrent_activities = concurrent_activities return calculate(heu_net, dependency_thresh, and_measure_thresh, heu_net_decoration)
def apply_heu_dfg(dfg, activities=None, activities_occurrences=None, start_activities=None, end_activities=None, dfg_window_2=None, freq_triples=None, performance_dfg=None, parameters=None): """ Discovers an Heuristics Net using Heuristics Miner Parameters ------------ dfg Directly-Follows Graph activities (If provided) list of activities of the log activities_occurrences (If provided) dictionary of activities occurrences start_activities (If provided) dictionary of start activities occurrences end_activities (If provided) dictionary of end activities occurrences dfg_window_2 (If provided) DFG of window 2 freq_triples (If provided) Frequency triples performance_dfg (If provided) Performance DFG parameters Possible parameters of the algorithm, including: - Parameters.ACTIVITY_KEY - Parameters.TIMESTAMP_KEY - Parameters.CASE_ID_KEY - Parameters.DEPENDENCY_THRESH - Parameters.AND_MEASURE_THRESH - Parameters.MIN_ACT_COUNT - Parameters.MIN_DFG_OCCURRENCES - Parameters.DFG_PRE_CLEANING_NOISE_THRESH - Parameters.LOOP_LENGTH_TWO_THRESH Returns ------------ heu Heuristics Net """ if parameters is None: parameters = {} dependency_thresh = exec_utils.get_param_value(Parameters.DEPENDENCY_THRESH, parameters, defaults.DEFAULT_DEPENDENCY_THRESH) and_measure_thresh = exec_utils.get_param_value(Parameters.AND_MEASURE_THRESH, parameters, defaults.DEFAULT_AND_MEASURE_THRESH) min_act_count = exec_utils.get_param_value(Parameters.MIN_ACT_COUNT, parameters, defaults.DEFAULT_MIN_ACT_COUNT) min_dfg_occurrences = exec_utils.get_param_value(Parameters.MIN_DFG_OCCURRENCES, parameters, defaults.DEFAULT_MIN_DFG_OCCURRENCES) dfg_pre_cleaning_noise_thresh = exec_utils.get_param_value(Parameters.DFG_PRE_CLEANING_NOISE_THRESH, parameters, defaults.DEFAULT_DFG_PRE_CLEANING_NOISE_THRESH) loops_length_two_thresh = exec_utils.get_param_value(Parameters.LOOP_LENGTH_TWO_THRESH, parameters, defaults.DEFAULT_LOOP_LENGTH_TWO_THRESH) heu_net = HeuristicsNet(dfg, activities=activities, activities_occurrences=activities_occurrences, start_activities=start_activities, end_activities=end_activities, dfg_window_2=dfg_window_2, freq_triples=freq_triples, performance_dfg=performance_dfg) heu_net = calculate(heu_net, dependency_thresh=dependency_thresh, and_measure_thresh=and_measure_thresh, min_act_count=min_act_count, min_dfg_occurrences=min_dfg_occurrences, dfg_pre_cleaning_noise_thresh=dfg_pre_cleaning_noise_thresh, loops_length_two_thresh=loops_length_two_thresh) return heu_net