def apply_token_replay(log, net, initial_marking, final_marking, parameters=None): """ Calculates all metrics based on token-based replay and returns a unified dictionary Parameters ----------- log Trace log net Petri net initial_marking Initial marking final_marking Final marking parameters Parameters Returns ----------- dictionary Dictionary containing fitness, precision, generalization and simplicity; along with the average weight of these metrics """ if parameters is None: parameters = {} activity_key = parameters[ PARAM_ACTIVITY_KEY] if PARAM_ACTIVITY_KEY in parameters else log_lib.util.xes.DEFAULT_NAME_KEY fitness_weight = parameters[PARAM_FITNESS_WEIGHT] if PARAM_FITNESS_WEIGHT in parameters else 0.25 precision_weight = parameters[PARAM_PRECISION_WEIGHT] if PARAM_PRECISION_WEIGHT in parameters else 0.25 simplicity_weight = parameters[PARAM_SIMPLICITY_WEIGHT] if PARAM_SIMPLICITY_WEIGHT in parameters else 0.25 generalization_weight = parameters[ PARAM_GENERALIZATION_WEIGHT] if PARAM_GENERALIZATION_WEIGHT in parameters else 0.25 sum_of_weights = (fitness_weight + precision_weight + simplicity_weight + generalization_weight) fitness_weight = fitness_weight / sum_of_weights precision_weight = precision_weight / sum_of_weights simplicity_weight = simplicity_weight / sum_of_weights generalization_weight = generalization_weight / sum_of_weights parameters_tr = {pmutil.constants.PARAMETER_CONSTANT_ACTIVITY_KEY: activity_key} aligned_traces = token_replay.apply(log, net, initial_marking, final_marking, parameters=parameters_tr) parameters = { "activity_key": activity_key } fitness = fitness_token_based.evaluate(aligned_traces) precision = precision_token_based.apply(log, net, initial_marking, final_marking, parameters=parameters) generalization = generalization_token_based.get_generalization(net, aligned_traces) simplicity = simplicity_arc_degree.apply(net) metrics_average_weight = fitness_weight * fitness["averageFitness"] + precision_weight * precision \ + generalization_weight * generalization + simplicity_weight * simplicity dictionary = { "fitness": fitness, "precision": precision, "generalization": generalization, "simplicity": simplicity, "metricsAverageWeight": metrics_average_weight } return dictionary
def apply(log, net, initial_marking, final_marking, parameters=None): """ Calculates all metrics based on token-based replay and returns a unified dictionary Parameters ----------- log Log net Petri net initial_marking Initial marking final_marking Final marking parameters Parameters Returns ----------- dictionary Dictionary containing fitness, precision, generalization and simplicity; along with the average weight of these metrics """ if parameters is None: parameters = {} log = log_conversion.apply(log, parameters, log_conversion.TO_EVENT_LOG) activity_key = exec_utils.get_param_value( Parameters.ACTIVITY_KEY, parameters, log_lib.util.xes.DEFAULT_NAME_KEY) fitness_weight = exec_utils.get_param_value( Parameters.PARAM_FITNESS_WEIGHT, parameters, 0.25) precision_weight = exec_utils.get_param_value( Parameters.PARAM_PRECISION_WEIGHT, parameters, 0.25) simplicity_weight = exec_utils.get_param_value( Parameters.PARAM_SIMPLICITY_WEIGHT, parameters, 0.25) generalization_weight = exec_utils.get_param_value( Parameters.PARAM_GENERALIZATION_WEIGHT, parameters, 0.25) sum_of_weights = (fitness_weight + precision_weight + simplicity_weight + generalization_weight) fitness_weight = fitness_weight / sum_of_weights precision_weight = precision_weight / sum_of_weights simplicity_weight = simplicity_weight / sum_of_weights generalization_weight = generalization_weight / sum_of_weights parameters_tr = {token_replay.Parameters.ACTIVITY_KEY: activity_key} aligned_traces = token_replay.apply(log, net, initial_marking, final_marking, parameters=parameters_tr) parameters = {token_replay.Parameters.ACTIVITY_KEY: activity_key} fitness = fitness_token_based.evaluate(aligned_traces) precision = precision_token_based.apply(log, net, initial_marking, final_marking, parameters=parameters) generalization = generalization_token_based.get_generalization( net, aligned_traces) simplicity = simplicity_arc_degree.apply(net) metrics_average_weight = fitness_weight * fitness["log_fitness"] + precision_weight * precision \ + generalization_weight * generalization + simplicity_weight * simplicity fscore = 0.0 if (fitness['log_fitness'] + precision) > 0: fscore = (2 * fitness['log_fitness'] * precision) / (fitness['log_fitness'] + precision) dictionary = { "fitness": fitness, "precision": precision, "generalization": generalization, "simplicity": simplicity, "metricsAverageWeight": metrics_average_weight, "fscore": fscore } return dictionary