Package: log-distance-measures
Event Log Distance MeasuresInstallationPackage available in PyPI:https://pypi.org/project/log-distance-measures/. Install it with:pipinstalllog-distance-measuresDescriptionPython package with the implementation of different distance measures between two event logs, from the control-flow, temporal, and queuing
perspectives:Control-flowN-Gram Distribution DistanceControl-Flow Log Distance (CFLD)TemporalAbsolute Event Distribution DistanceCase Arrival Distribution DistanceCircadian Event Distribution DistanceRelative Event Distribution DistanceCycle Time Distribution DistanceExample of input initializationimportpandasaspdfromlog_distance_measures.configimportEventLogIDs# Set event log column ID mappingevent_log_ids=EventLogIDs(# These values are stored in DEFAULT_CSV_IDScase="case_id",activity="Activity",start_time="start_time",end_time="end_time")# Read and transform time attributesevent_log=pd.read_csv("/path/to/event_log.csv")event_log[event_log_ids.start_time]=pd.to_datetime(event_log[event_log_ids.start_time],utc=True)event_log[event_log_ids.end_time]=pd.to_datetime(event_log[event_log_ids.end_time],utc=True)Control-flow Log Distance (CFLD)Distance measure between two event logs with the same number of traces (L1andL2) comparing the control-flow dimension (see "Camargo
M, Dumas M, González-Rojas O. 2021. Discovering generative models from event logs: data-driven simulation vs deep learning. PeerJ Computer
Science 7:e577https://doi.org/10.7717/peerj-cs.577" for a detailed description of a similarity version of this measure).Transform each process trace ofL1andL2to their corresponding activity sequence.Compute the Damerau-Levenshtein distance between each traceifromL1and each tracejofL2, and normalize it by dividing by the
length of the longest trace.Compute the matching between the traces of both logs (such that eachiis matched to a differentj, and vice versa) minimizing the
sum of distances with linear programming.Compute the CFLD as the average of the normalized distance values.Example of usefromlog_distance_measures.configimportDEFAULT_CSV_IDSfromlog_distance_measures.control_flow_log_distanceimportcontrol_flow_log_distance# Call passing the event logs, and its column ID mappingsdistance=control_flow_log_distance(original_log,DEFAULT_CSV_IDS,# First event log and its column id mappingssimulated_log,DEFAULT_CSV_IDS,# Second event log and its column id mappings)N-Gram Distribution DistanceDistance measure between two event logs computing the difference in the frequencies of the n-grams observed in the event logs (
being the n-grams of an event log all the groups ofnconsecutive elements observed in it).Given a sizen, get all sequences ofnactivities (n-gram) observed in each event log (adding artificial activities to the start and
end of each trace to consider these as well, e.g.,0 - 0 - Afor a trace starting withAand ann = 3).Compute the number of times that each n-gram is observed in each event log (its frequency).Compute the sum of absolute differences between the frequencies of all computed n-grams (e.g. the frequency ofA - B - Cin the first
event log w.r.t. its frequency in the second event log).Example of usefromlog_distance_measures.configimportDEFAULT_CSV_IDSfromlog_distance_measures.n_gram_distributionimportn_gram_distribution_distance# Call passing the event logs, and its column ID mappingsdistance=n_gram_distribution_distance(original_log,DEFAULT_CSV_IDS,# First event log and its column id mappingssimulated_log,DEFAULT_CSV_IDS,# Second event log and its column id mappingsn=3# trigrams)Absolute Event Distribution DistanceDistance measure computing how different the histograms of the timestamps of two event logs are, discretizing the timestamps by absolute
hour.Take all the start timestamps, the end timestamps, or both.Discretize the timestamps by absolute hour (those timestamps between02/05/2022 10:00:00and02/05/2022 10:59:59go to the same
bin).Compare the discretized histograms of the two event logs with the Wasserstein Distance (a.k.a. EMD).Example of usefromlog_distance_measures.absolute_event_distributionimportabsolute_event_distribution_distancefromlog_distance_measures.configimportAbsoluteTimestampType,DEFAULT_CSV_IDS,discretize_to_hour# Call passing the event logs, its column ID mappings, timestamp type, and discretize functiondistance=absolute_event_distribution_distance(original_log,DEFAULT_CSV_IDS,# First event log and its column id mappingssimulated_log,DEFAULT_CSV_IDS,# Second event log and its column id mappingsdiscretize_type=AbsoluteTimestampType.BOTH,# Type of timestamp distribution (consider start times and/or end times)discretize_event=discretize_to_hour# Function to discretize the absolute seconds of each timestamp (default by hour))This EMD measure can be also used to compare the distribution of the start timestamps (withAbsoluteHourEmdType.START), or the end
timestamps (withAbsoluteHourEmdType.END), instead of both of them.Furthermore, the binning is performed to hour by default, but it can be customized passing another function discretize the total amount of
seconds to its bin.importmathfromlog_distance_measures.absolute_event_distributionimportabsolute_event_distribution_distancefromlog_distance_measures.configimportAbsoluteTimestampType,DEFAULT_CSV_IDS,discretize_to_day# EMD of the (END) timestamps distribution where each bin represents a daydistance=absolute_event_distribution_distance(original_log,DEFAULT_CSV_IDS,simulated_log,DEFAULT_CSV_IDS,discretize_type=AbsoluteTimestampType.END,discretize_event=discretize_to_day)# EMD of the timestamps distribution where each bin represents a weekdistance=absolute_event_distribution_distance(original_log,DEFAULT_CSV_IDS,simulated_log,DEFAULT_CSV_IDS,discretize_event=lambdaseconds:math.floor(seconds/3600/24/7))Case Arrival Distribution DistanceDistance measure computing how different the discretized histograms of the arrival events of two event logs are.Compute the arrival timestamp for each process case (its first start time).Discretize the timestamps by absolute hour (those timestamps between02/05/2022 10:00:00and02/05/2022 10:59:59go to the same
bin).Compare the discretized histograms of the two event logs with the Wasserstein Distance (a.k.a. EMD).Example of usefromlog_distance_measures.case_arrival_distributionimportcase_arrival_distribution_distancefromlog_distance_measures.configimportDEFAULT_CSV_IDS,discretize_to_hourdistance=case_arrival_distribution_distance(original_log,DEFAULT_CSV_IDS,# First event log and its column id mappingssimulated_log,DEFAULT_CSV_IDS,# Second event log and its column id mappingsdiscretize_event=discretize_to_hour# Function to discretize each timestamp (default by hour))Circadian Event Distribution DistanceDistance measure computing how different the histograms of the timestamps of two event logs are, comparing all the instants recorded in the
same weekday together, and discretizing them to the hour in the day.Take all the start timestamps, the end timestamps, or both.Group the timestamps by their weekday (e.g. all the timestamps recorded on Monday of one log are going to be compared with the timestamps
recorded on Monday of the other event log).Discretize the timestamps to their hour (those timestamps between '10:00:00' and '10:59:59' go to the same bin).Compare the histograms of the two event logs for each weekday (with the Wasserstein Distance, a.k.a. EMD), and compute the average.Extra 1: If there are no recorded timestamps for one of the weekdays in both logs, no distance is measured for that day.Extra 2: If there are no recorded timestamps for one of the weekdays in one of the logs, the distance for that day is set to 23 (the
maximum distance for two histograms with values from 0 to 23)Example of usefromlog_distance_measures.circadian_event_distributionimportcircadian_event_distribution_distancefromlog_distance_measures.configimportAbsoluteTimestampType,DEFAULT_CSV_IDSdistance=circadian_event_distribution_distance(original_log,DEFAULT_CSV_IDS,# First event log and its column id mappingssimulated_log,DEFAULT_CSV_IDS,# Second event log and its column id mappingsdiscretize_type=AbsoluteTimestampType.BOTH# Consider both start/end timestamps of each activity instance)Similarly than with the Absolute Event Distribution Distance, the Circadian Event Distribution Distance can be also used to compare the
distribution of the start timestamps (withAbsoluteHourEmdType.START), or the end timestamps (withAbsoluteHourEmdType.END), instead of
both of them.Relative Event Distribution DistanceDistance measure computing how different the histograms of the relative (w.r.t. the start of each case) timestamps of two event logs are,
discretizing the timestamps by absolute hour.Take all the start timestamps, the end timestamps, or both.Make them relative w.r.t. the start of their process case (e.g. the first timestamp in a case is 0, the second one is the time itnerval
from the first one).Discretize the durations by hour (e.g. those durations between0and3599go to the same bin).Compare the discretized histograms of the two event logs with the Wasserstein Distance (a.k.a. EMD).Example of usefromlog_distance_measures.configimportAbsoluteTimestampType,DEFAULT_CSV_IDS,discretize_to_hourfromlog_distance_measures.relative_event_distributionimportrelative_event_distribution_distance# Call passing the event logs, its column ID mappings, timestamp type, and discretize functiondistance=relative_event_distribution_distance(original_log,DEFAULT_CSV_IDS,# First event log and its column id mappingssimulated_log,DEFAULT_CSV_IDS,# Second event log and its column id mappingsdiscretize_type=AbsoluteTimestampType.BOTH,# Type of timestamp distribution (consider start times and/or end times)discretize_event=discretize_to_hour# Function to discretize the absolute seconds of each timestamp (default by hour))Similarly than with the Absolute Event Distribution Distance, the Relative Event Distribution Distance can be also used to compare the
distribution of the start timestamps (withAbsoluteHourEmdType.START), or the end timestamps (withAbsoluteHourEmdType.END), instead of
both of them.Work in Progress DistanceDistance measure computing how different the histograms of the number of active cases (computing the average active cases per window) of two
event logs are.Build a timeline with a bin for each hour since the beginning to the end of both logs.Compute, for each bin, the average number of active cases (e.g. 4 and a half active cases in the window from01/01/2023 10:00:00to01/01/2023 10:59:59).Compare the histograms of the two event logs with the Wasserstein Distance (a.k.a. EMD).Example of useimportpandasaspdfromlog_distance_measures.configimportDEFAULT_CSV_IDSfromlog_distance_measures.work_in_progressimportwork_in_progress_distance# Call passing the event logs, its column ID mappings, timestamp type, and discretize functionwork_in_progress_distance(original_log,DEFAULT_CSV_IDS,# First event log and its column id mappingssimulated_log,DEFAULT_CSV_IDS,# Second event log and its column id mappingswindow_size=pd.Timedelta(hours=1)# Bins of 1 hour)Cycle Time Distribution DistanceDistance measure computing how different the cycle time discretized histograms of two event logs are.Compute the cycle time of each process instance.Group the cycle times in bins by a given bin size (time gap).Compare the discretized histograms of the two event logs with the Wasserstein Distance (a.k.a. EMD).Example of useimportpandasaspdfromlog_distance_measures.configimportDEFAULT_CSV_IDSfromlog_distance_measures.cycle_time_distributionimportcycle_time_distribution_distancedistance=cycle_time_distribution_distance(original_log,DEFAULT_CSV_IDS,# First event log and its column id mappingssimulated_log,DEFAULT_CSV_IDS,# Second event log and its column id mappingsbin_size=pd.Timedelta(hours=1)# Bins of 1 hour)