pm4py / pm4py-core

Public repository for the PM4Py (Process Mining for Python) project.
https://pm4py.fit.fraunhofer.de
GNU General Public License v3.0
722 stars 286 forks source link

Handle hidden transitions in token based replay #355

Closed s-kimel closed 1 year ago

s-kimel commented 1 year ago
import pm4py
import pandas as pd
from pm4py.objects.conversion.log import converter as log_converter

df = pd.DataFrame({
    'case:concept:name': ['A','A','A','A',
                          'B','B','B','B',
                          'C','C','C',
                          'D','D','D'],
    'concept:name': ['Task 1', 'Task 2', 'Task 3', 'Task 5',
                     'Task 1', 'Task 2', 'Task 4', 'Task 5',
                     'Task 1', 'Task 3', 'Task 5',
                     'Task 1', 'Task 2', 'Task 5']
})

When I do conformance checking with token based replay, it flags the traces with Task 3 as not fitting the model in the trace_is_fit key of the output.

event_log = log_converter.apply(df)
net, im, fm = pm4py.discover_petri_net_heuristics(event_log, dependency_threshold=0)
pm4py.conformance_diagnostics_token_based_replay(event_log, net, im, fm)

If I check the fitness, I also get that only once trace is fit with the model (25% of traces fit).

pm4py.fitness_token_based_replay(event_log, net, im, fm)

All traces do fit the model, but the ones where the hidden transition needs to fire are marked as not fitting. I saw that this was an issue with token based replay that was resolved in pm4py in this paper. I also see this in the docs

In PM4Py there is an implementation of a token replayer that is able to go across hidden transitions (calculating shortest paths between places) and can be used with any Petri net model with unique visible transitions and hidden transitions. When a visible transition needs to be fired and not all places in the preset are provided with the correct number of tokens, starting from the current marking it is checked if for some place there is a sequence of hidden transitions that could be fired in order to enable the visible transition. The hidden transitions are then fired and a marking that permits to enable the visible transition is reached.

I saw this function which may do what I want, but I was not sure how to use it and could not find any examples: pm4py.algo.conformance.tokenreplay.variants.token_replay.apply_hidden_trans I am not sure what functions to use to get the output desired, which in this example would be that all trace_is_fit values would be True and the perc_fit_traces value would be 100.0.

fit-alessandro-berti commented 1 year ago

Dear @s-kimel image

In this Petri net, Task 3 is dead, because it requires a token both in intplace_Task 1 and splace_in_Task 3_Task 2_0 and this is impossible to obtain.

Hence all the cases containing Task 3 are impossible to replay. Also the last case, Task 1, Task 2 and Task 5, is impossible to replay in the Petri net without leaving a remaining token in splace_in_Task 3_Task 2_0.

The fitness provided by the approach is therefore correct in my opinion

s-kimel commented 1 year ago

@fit-alessandro-berti You are correct. I am sorry about not noticing that. In the example above, I can get a model that has hidden transitions with pm4py.discover_petri_net_inductive(event_log) that does produce the desired results because the model does not have the same issues with transitions begin dead or having remaining tokens.

Sorry again about missing the reason I was getting the results I was getting. I appreciate your reply!