def test_inductive_miner(self):
     log = xes_importer.apply(
         os.path.join("input_data", "running-example.xes"))
     from pm4py.algo.discovery.inductive import factory as inductive_miner
     net, im, fm = inductive_miner.apply(
         log, variant=inductive_miner.DFG_BASED_OLD_VERSION)
     net, im, fm = inductive_miner.apply(log,
                                         variant=inductive_miner.DFG_BASED)
Example #2
0
def f1_score(xes_file, dfg1, dfg2):
    f1_score_1, f1_score_2 = 0, 0
    #first we use inductive miner to generate the petric nets of both the DFGs
    net1, initial_marking1, final_marking1 = inductive_miner.apply(dfg1)
    net2, initial_marking2, final_marking2 = inductive_miner.apply(dfg2)
    fitness_1 = replay_factory.apply(xes_file, net1, initial_marking1,
                                     final_marking1)
    fitness_2 = replay_factory.apply(xes_file, net2, initial_marking2,
                                     final_marking2)

    return fitness_1, fitness_2
Example #3
0
def handle_uploaded_file(f, algorithm):

    logPath2 = '/home/pm4py_test/logs/log.xes'
    logPath1 = '/home/pm4py_test/media/log.xes'
    # os.remove('static/proc/model.png')
    fs = FileSystemStorage()
    fs.save('log.xes', f)
    move_file(logPath1, logPath2)

    log = xes_importer.import_log(logPath2)
    if algorithm == "alpha":
        print(algorithm)
        net, initial_marking, final_marking = heuristics_miner.apply(log)
    elif algorithm == "inductive":
        print(algorithm)
        net, initial_marking, final_marking = inductive_miner.apply(log)
    elif algorithm == "heuristics":
        print(algorithm)
        net, initial_marking, final_marking = heuristics_miner.apply(log)
    else:
        print('error !!!')
        print(algorithm)
        return
    gviz = vis_factory.apply(net, initial_marking, final_marking)
    vis_factory.view(gviz)
    pngUris = glob.glob('/home/pm4py_test/*.png')
    gvUris = glob.glob('/home/pm4py_test/*.gv')
    modelUri = '/home/pm4py_test/proc/static/proc/model.png'
    print(pngUris)
    print(gvUris)

    os.remove(gvUris[0])
    move_file(pngUris[0], modelUri)
def execute_script(variant="frequency"):
    # read the log using the nonstandard importer (faster)
    log_path = os.path.join("..", "tests", "input_data", "receipt.xes")
    log = xes_importer.import_log(log_path, variant="nonstandard")
    # applies Inductive Miner on the log
    net, initial_marking, final_marking = inductive_miner.apply(log)
    # find shortest paths in the net
    spaths = get_shortest_paths(net)

    # then we start to decorate the net
    # we decide if we should decorate it with frequency or performance
    # we decide the aggregation measure (sum, min, max, mean, median, stdev)
    aggregation_measure = "mean"
    if variant == "frequency":
        aggregation_measure = "sum"
    # we find the DFG
    dfg = dfg_factory.apply(log, variant=variant)
    # we find the number of activities occurrences in the log
    activities_count = attributes_filter.get_attribute_values(log, "concept:name")
    # we calculate the statistics on the Petri net applying the greedy algorithm
    aggregated_statistics = get_decorations_from_dfg_spaths_acticount(net, dfg, spaths,
                                                                      activities_count,
                                                                      variant=variant,
                                                                      aggregation_measure=aggregation_measure)
    # we find the gviz
    gviz = pn_vis_factory.apply(net, initial_marking, final_marking, variant=variant,
                                aggregated_statistics=aggregated_statistics, parameters={"format": "svg"})
    # we show the viz on screen
    pn_vis_factory.view(gviz)
Example #5
0
def execute_script():
    log = xes_importer.apply(
        os.path.join("..", "tests", "input_data", "running-example.xes"))
    net, im, fm = inductive_miner.apply(log)
    # perform the backwards token-based replay
    replayed_traces = tr_factory.apply(log, net, im, fm, variant="backwards")
    print(replayed_traces)
def execute_script():
    log = xes_importer.apply(
        os.path.join("..", "tests", "input_data", "running-example.xes"))
    net, im, fm = inductive_miner.apply(log)
    # perform the Montecarlo simulation with the arrival rate inferred by the log (the simulation lasts 5 secs)
    log, res = montecarlo_simulation.apply(log,
                                           net,
                                           im,
                                           fm,
                                           parameters={
                                               "enable_diagnostics": False,
                                               "max_thread_exec_time": 5
                                           })
    print(
        "\n(Montecarlo - Petri net) case arrival ratio inferred from the log")
    print(res["median_cases_ex_time"])
    print(res["total_cases_time"])
    # perform the Montecarlo simulation with the arrival rate specified (the simulation lasts 5 secs)
    log, res = montecarlo_simulation.apply(log,
                                           net,
                                           im,
                                           fm,
                                           parameters={
                                               "enable_diagnostics": False,
                                               "max_thread_exec_time": 5,
                                               "case_arrival_ratio": 60
                                           })
    print(
        "\n(Montecarlo - Petri net) case arrival ratio specified by the user")
    print(res["median_cases_ex_time"])
    print(res["total_cases_time"])
Example #7
0
 def test_s_components(self):
     # to avoid static method warnings in tests,
     # that by construction of the unittest package have to be expressed in such way
     self.dummy_variable = "dummy_value"
     log = xes_importer.import_log(os.path.join(INPUT_DATA_DIR, "running-example.xes"))
     net, im, fm = inductive_miner.apply(log)
     s_comps = petri.utils.get_s_components_from_petri(net, im, fm)
     del s_comps
Example #8
0
def run_imdfb(log, label, activity_key):
    from pm4py.algo.discovery.inductive import factory as inductive_miner

    miner_params = {
        PARAMETER_CONSTANT_TIMESTAMP_KEY: "time",
        PARAMETER_CONSTANT_ACTIVITY_KEY: activity_key
    }

    return inductive_miner.apply(log, parameters=miner_params)
Example #9
0
def execute_script():
    # in this case, we obtain a decision tree by alignments on a specific decision point
    log = xes_importer.apply(os.path.join("..", "tests", "input_data", "receipt.xes"))
    net, im, fm = inductive_miner.apply(log)
    # we need to specify a decision point. In this case, the place p_25 is a suitable decision point
    clf, feature_names, classes = algorithm.get_decision_tree(log, net, im, fm, decision_point="p_25")
    # we can visualize the decision tree
    gviz = visualizer.apply(clf, feature_names, classes, parameters={"format": "svg"})
    visualizer.view(gviz)
Example #10
0
def SPIMDFb(context):
    args = context.args
    inputFile = os.path.join(args.inputData, os.listdir(args.inputData)[0])
    log = xes_importer.import_log(inputFile)
    net, initial_marking, final_marking = inductive_miner.apply(log)
    gviz = pn_vis_factory.apply(net, initial_marking, final_marking)
    pn_vis_factory.save(gviz, os.path.join(args.outputData, "inductive-miner.png"))

    return args.outputData
Example #11
0
 def test_evaluation_pm2(self):
     # to avoid static method warnings in tests,
     # that by construction of the unittest package have to be expressed in such way
     self.dummy_variable = "dummy_value"
     log = xes_importer.import_log(
         os.path.join(INPUT_DATA_DIR, "running-example.xes"))
     net, marking, final_marking = inductive_miner.apply(log)
     metrics = evaluation_factory.apply(log, net, marking, final_marking)
     del metrics
Example #12
0
def execute_script():
    log = xes_importer.import_log(
        os.path.join("..", "tests", "input_data", "receipt.xes"))
    filtered_log = auto_filter.auto_filter.apply_auto_filter(log)
    net, initial_marking, final_marking = inductive_miner.apply(filtered_log)
    replayed_traces, place_fitness, trans_fitness, unwanted_activities = token_based_replay.apply(
        log,
        net,
        initial_marking,
        final_marking,
        parameters={
            "disable_variants": True,
            "enable_pltr_fitness": True
        })
    trans_diagnostics = duration_diagnostics.diagnose_from_trans_fitness(
        log, trans_fitness)
    act_diagnostics = duration_diagnostics.diagnose_from_notexisting_activities(
        log, unwanted_activities)
    for trans in trans_diagnostics:
        print(trans, trans_diagnostics[trans])
    for act in act_diagnostics:
        print(act, act_diagnostics[act])

    # build decision trees
    string_attributes = ["org:group"]
    numeric_attributes = []

    parameters = {
        "string_attributes": string_attributes,
        "numeric_attributes": numeric_attributes
    }

    trans_root_cause = root_cause_analysis.diagnose_from_trans_fitness(
        log, trans_fitness, parameters=parameters)

    print("trans_root_cause=", trans_root_cause)

    for trans in trans_root_cause:
        clf = trans_root_cause[trans]["clf"]
        feature_names = trans_root_cause[trans]["feature_names"]
        classes = trans_root_cause[trans]["classes"]
        # visualization could be called
        # gviz = dt_vis_factory.apply(clf, feature_names, classes)
        # dt_vis_factory.view(gviz)

    act_root_cause = root_cause_analysis.diagnose_from_notexisting_activities(
        log, unwanted_activities, parameters=parameters)

    print("act_root_cause=", act_root_cause)

    for act in act_root_cause:
        clf = act_root_cause[act]["clf"]
        feature_names = act_root_cause[act]["feature_names"]
        classes = act_root_cause[act]["classes"]
Example #13
0
 def test_inductiveminer_stream(self):
     stream = csv_importer.apply(
         os.path.join("input_data", "running-example.csv"))
     net, im, fm = inductive_miner.apply(stream)
     aligned_traces_tr = tr_factory.apply(stream, net, im, fm)
     aligned_traces_alignments = align_factory.apply(stream, net, im, fm)
     evaluation = eval_factory.apply(stream, net, im, fm)
     fitness = rp_fit_factory.apply(stream, net, im, fm)
     precision = precision_factory.apply(stream, net, im, fm)
     generalization = generalization_factory.apply(stream, net, im, fm)
     simplicity = simplicity_factory.apply(net)
Example #14
0
 def test_inductiveminer_df(self):
     log = csv_import_adapter.import_dataframe_from_path(
         os.path.join("input_data", "running-example.csv"))
     net, im, fm = inductive_miner.apply(log)
     aligned_traces_tr = tr_factory.apply(log, net, im, fm)
     aligned_traces_alignments = align_factory.apply(log, net, im, fm)
     evaluation = eval_factory.apply(log, net, im, fm)
     fitness = rp_fit_factory.apply(log, net, im, fm)
     precision = precision_factory.apply(log, net, im, fm)
     generalization = generalization_factory.apply(log, net, im, fm)
     simplicity = simplicity_factory.apply(net)
Example #15
0
def generate_inductive_miner_net(xes_log):
    try:
        inductive_net, initial_marking, final_marking = inductive_miner.apply(
            xes_log)
        return {
            'inductive_net': inductive_net,
            'initial_marking': initial_marking,
            'final_marking': final_marking
        }
    except AttributeError:
        print("Please check input values")
Example #16
0
 def obtainPetriNetThroughImdf(self, log_name):
     # to avoid static method warnings in tests,
     # that by construction of the unittest package have to be expressed in such way
     self.dummy_variable = "dummy_value"
     if ".xes" in log_name:
         trace_log = xes_importer.import_log(log_name)
     else:
         event_log = csv_importer.import_log(log_name)
         trace_log = log_transform.transform_event_log_to_trace_log(event_log)
     net, marking, final_marking = inductive_miner.apply(trace_log, None)
     return trace_log, net, marking, final_marking
Example #17
0
def inductive_miner_petrinet_no_decor(log_file):
    net, i_m, f_m = inductive_miner.apply(log_file)
    gviz = pn_vis_factory.apply(net,
                                i_m,
                                f_m,
                                parameters={
                                    "format": "png",
                                    "debug": False
                                })

    pn_vis_factory.save(gviz, "static/inductive_miner_petnet_no_decor.png")
    return net, i_m, f_m
 def test_docmeasures11(self):
     # to avoid static method warnings in tests,
     # that by construction of the unittest package have to be expressed in such way
     self.dummy_variable = "dummy_value"
     from pm4py.objects.log.importer.xes import factory as xes_importer
     log = xes_importer.import_log(os.path.join("input_data",
                                                "receipt.xes"))
     from pm4py.algo.discovery.alpha import factory as alpha_miner
     from pm4py.algo.discovery.inductive import factory as inductive_miner
     alpha_petri, alpha_initial_marking, alpha_final_marking = alpha_miner.apply(
         log)
     inductive_petri, inductive_initial_marking, inductive_final_marking = inductive_miner.apply(
         log)
     from pm4py.evaluation.replay_fitness import factory as replay_factory
     fitness_alpha = replay_factory.apply(log, alpha_petri,
                                          alpha_initial_marking,
                                          alpha_final_marking)
     fitness_inductive = replay_factory.apply(log, inductive_petri,
                                              inductive_initial_marking,
                                              inductive_final_marking)
     del fitness_alpha
     del fitness_inductive
     from pm4py.evaluation.precision import factory as precision_factory
     precision_alpha = precision_factory.apply(log, alpha_petri,
                                               alpha_initial_marking,
                                               alpha_final_marking)
     precision_inductive = precision_factory.apply(
         log, inductive_petri, inductive_initial_marking,
         inductive_final_marking)
     del precision_alpha
     del precision_inductive
     from pm4py.evaluation.generalization import factory as generalization_factory
     generalization_alpha = generalization_factory.apply(
         log, alpha_petri, alpha_initial_marking, alpha_final_marking)
     generalization_inductive = generalization_factory.apply(
         log, inductive_petri, inductive_initial_marking,
         inductive_final_marking)
     del generalization_alpha
     del generalization_inductive
     from pm4py.evaluation.simplicity import factory as simplicity_factory
     simplicity_alpha = simplicity_factory.apply(alpha_petri)
     simplicity_inductive = simplicity_factory.apply(inductive_petri)
     del simplicity_alpha
     del simplicity_inductive
     from pm4py.evaluation import factory as evaluation_factory
     alpha_evaluation_result = evaluation_factory.apply(
         log, alpha_petri, alpha_initial_marking, alpha_final_marking)
     inductive_evaluation_result = evaluation_factory.apply(
         log, inductive_petri, inductive_initial_marking,
         inductive_final_marking)
     del alpha_evaluation_result
     del inductive_evaluation_result
Example #19
0
    def obtainPetriNetThroughImdf(self,
                                  log_name,
                                  variant=inductive_miner.DEFAULT_VARIANT):
        # to avoid static method warnings in tests,
        # that by construction of the unittest package have to be expressed in such way
        self.dummy_variable = "dummy_value"
        if ".xes" in log_name:
            log = xes_importer.import_log(log_name)
        else:
            event_log = csv_importer.import_event_stream(log_name)
            log = log_conv_fact.apply(event_log)
        # apply dummily the test to all the available variants
        net, marking, final_marking = inductive_miner.apply(
            log, variant=inductive_miner.DFG_BASED_OLD_VERSION)
        net, marking, final_marking = inductive_miner.apply(
            log, variant=inductive_miner.DFG_BASED)
        net, marking, final_marking = inductive_miner.apply(log,
                                                            variant=variant)
        soundness = check_soundness.check_petri_wfnet_and_soundness(net)
        del soundness

        return log, net, marking, final_marking
Example #20
0
 def test_etc1(self):
     # to avoid static method warnings in tests,
     # that by construction of the unittest package have to be expressed in such way
     self.dummy_variable = "dummy_value"
     log = xes_importer.import_log(
         os.path.join(INPUT_DATA_DIR, "running-example.xes"))
     net, marking, final_marking = inductive_miner.apply(log)
     precision = etc_factory.apply(log,
                                   net,
                                   marking,
                                   final_marking,
                                   variant=etc_factory.ETCONFORMANCE_TOKEN)
     del precision
Example #21
0
    def obtainPetriNetThroughImdf(self, log_name):
        # to avoid static method warnings in tests,
        # that by construction of the unittest package have to be expressed in such way
        self.dummy_variable = "dummy_value"
        if ".xes" in log_name:
            log = xes_importer.import_log(log_name)
        else:
            event_log = csv_importer.import_event_stream(log_name)
            log = log_conv_fact.apply(event_log)
        net, marking, final_marking = inductive_miner.apply(log)
        soundness = check_soundness.check_petri_wfnet_and_soundness(net)
        del soundness

        return log, net, marking, final_marking
def execute_script():
    # import the a32f0n00 log
    log = xes_importer.apply(
        os.path.join("..", "tests", "compressed_input_data",
                     "09_a32f0n00.xes.gz"))
    # discover a model using the inductive miner
    net, im, fm = inductive_miner.apply(log)
    # apply the alignments decomposition with a maximal number of border disagreements set to 5
    aligned_traces = dec_align_factory.apply(
        log, net, im, fm, parameters={"thresh_border_agreement": 5})
    #print(aligned_traces)
    # calculate the fitness over the recomposed alignment (use the classical evaluation factory)
    fitness = rep_fit_factory.evaluate(aligned_traces, variant="alignments")
    print(fitness)
Example #23
0
 def test_alignment_pnml(self):
     # to avoid static method warnings in tests,
     # that by construction of the unittest package have to be expressed in such way
     self.dummy_variable = "dummy_value"
     log = xes_importer.import_log(os.path.join(INPUT_DATA_DIR, "running-example.xes"))
     net, marking, final_marking = inductive_miner.apply(log)
     for trace in log:
         cf_result = align_factory.apply(trace, net, marking, final_marking, version=align_factory.VERSION_DIJKSTRA_NO_HEURISTICS)['alignment']
         is_fit = True
         for couple in cf_result:
             if not (couple[0] == couple[1] or couple[0] == ">>" and couple[1] is None):
                 is_fit = False
         if not is_fit:
             raise Exception("should be fit")
Example #24
0
def inductive_miner_petrinet_frequency(log_file):
    net, i_m, f_m = inductive_miner.apply(log_file)
    gviz = pn_vis_factory.apply(net,
                                i_m,
                                f_m,
                                parameters={
                                    "format": "png",
                                    "debug": False
                                },
                                variant="frequency",
                                log=log_file)

    pn_vis_factory.save(gviz, "static/inductive_miner_petnet_frequency.png")
    return "success!"
    def test_inductivedoc1(self):
        # to avoid static method warnings in tests,
        # that by construction of the unittest package have to be expressed in such way
        self.dummy_variable = "dummy_value"
        from pm4py.objects.log.importer.xes import factory as xes_importer
        log = xes_importer.import_log(
            os.path.join("input_data", "running-example.xes"))

        from pm4py.algo.discovery.inductive import factory as inductive_miner
        net, initial_marking, final_marking = inductive_miner.apply(log)
        from pm4py.visualization.petrinet.common import visualize as pn_viz
        gviz = pn_viz.graphviz_visualization(net,
                                             initial_marking=initial_marking,
                                             final_marking=final_marking)
        del gviz
Example #26
0
def execute_script():
    # import the log
    log_path = os.path.join("..", "tests", "input_data", "receipt.xes")
    log = xes_importer.import_log(log_path)
    # apply Inductive Miner
    net, initial_marking, final_marking = inductive_miner.apply(log)
    # get visualization
    variant = "performance"
    parameters_viz = {"aggregationMeasure": "mean", "format": "svg"}
    gviz = pn_vis_factory.apply(net,
                                initial_marking,
                                final_marking,
                                log=log,
                                variant=variant,
                                parameters=parameters_viz)
    pn_vis_factory.view(gviz)
Example #27
0
def execute_script():
    log = xes_importer.apply(
        os.path.join("..", "tests", "input_data", "receipt.xes"))
    log = sorting.sort_timestamp(log)
    net, im, fm = inductive_miner.apply(log)
    log1 = EventLog(log[:500])
    log2 = EventLog(log[len(log) - 500:])
    statistics = element_usage_comparison.compare_element_usage_two_logs(
        net, im, fm, log1, log2)
    gviz = pn_vis_factory.apply(net,
                                im,
                                fm,
                                variant="frequency",
                                aggregated_statistics=statistics,
                                parameters={"format": "svg"})
    pn_vis_factory.view(gviz)
Example #28
0
 def test_evaluation_pm1(self):
     # to avoid static method warnings in tests,
     # that by construction of the unittest package have to be expressed in such way
     self.dummy_variable = "dummy_value"
     log = xes_importer.import_log(
         os.path.join(INPUT_DATA_DIR, "running-example.xes"))
     net, marking, final_marking = inductive_miner.apply(log)
     fitness = fitness_factory.apply(log, net, marking, final_marking)
     precision = precision_factory.apply(log, net, marking, final_marking)
     generalization = generalization_factory.apply(log, net, marking,
                                                   final_marking)
     simplicity = simplicity_factory.apply(net)
     del fitness
     del precision
     del generalization
     del simplicity
Example #29
0
def execute_script():
    log_path = os.path.join("..", "tests", "input_data", "running-example.xes")
    log = xes_importer.import_log(log_path)
    print("loaded log")
    net, marking, final_marking = inductive_factory.apply(log)
    for place in marking:
        print("initial marking " + place.name)
    for place in final_marking:
        print("final marking " + place.name)
    gviz = pn_vis_factory.apply(net,
                                marking,
                                final_marking,
                                parameters={"format": "svg"})
    pn_vis_factory.view(gviz)
    print("started token replay")
    aligned_traces = token_replay.apply(log, net, marking, final_marking)
    fit_traces = [x for x in aligned_traces if x['trace_is_fit']]
    perc_fitness = 0.00
    if len(aligned_traces) > 0:
        perc_fitness = len(fit_traces) / len(aligned_traces)
    print("perc_fitness=", perc_fitness)
def execute_script():
    log = xes_importer.import_log(
        os.path.join("..", "tests", "input_data", "receipt.xes"))
    filtered_log = auto_filter.auto_filter.apply_auto_filter(log)
    net, initial_marking, final_marking = inductive_miner.apply(filtered_log)
    replayed_traces, place_fitness, trans_fitness, unwanted_activities = token_based_replay.apply(
        log,
        net,
        initial_marking,
        final_marking,
        parameters={
            "disable_variants": True,
            "enable_pltr_fitness": True
        })
    trans_diagnostics = duration_diagnostics.diagnose_from_trans_fitness(
        log, trans_fitness)
    act_diagnostics = duration_diagnostics.diagnose_from_notexisting_activities(
        log, unwanted_activities)
    for trans in trans_diagnostics:
        print(trans, trans_diagnostics[trans])
    for act in act_diagnostics:
        print(act, act_diagnostics[act])