pm4py.conformance.fitness_token_based_replay#

pm4py.conformance.fitness_token_based_replay(log: EventLog | DataFrame, petri_net: PetriNet, initial_marking: Marking, final_marking: Marking, activity_key: str = 'concept:name', timestamp_key: str = 'time:timestamp', case_id_key: str = 'case:concept:name') Dict[str, float][source]#

Calculate the fitness using token-based replay. The fitness is calculated on a log-based level. The output dictionary contains the following keys: - perc_fit_traces: Percentage of fit traces (from 0.0 to 100.0). - average_trace_fitness: Average of the trace fitnesses (between 0.0 and 1.0). - log_fitness: Overall fitness of the log (between 0.0 and 1.0). - percentage_of_fitting_traces: Percentage of fit traces (from 0.0 to 100.0).

Token-based replay matches a trace against a Petri net model, starting from the initial marking, to discover which transitions are executed and in which places there are remaining or missing tokens for the given process instance. Token-based replay is useful for conformance checking: a trace fits the model if, during its execution, all transitions can be fired without the need to insert any missing tokens. If reaching the final marking is imposed, a trace fits if it reaches the final marking without any missing or remaining tokens.

In PM4Py, the token replayer implementation can handle hidden transitions by calculating the shortest paths between places. It can be used with any Petri net model that has unique visible transitions and hidden transitions. When a visible transition needs to be fired and not all places in its preset have the correct number of tokens, the current marking is checked to see if any hidden transitions can be fired to enable the visible transition. The hidden transitions are then fired, reaching a marking that permits the firing of the visible transition.

The approach is described in: Berti, Alessandro, and Wil MP van der Aalst. “Reviving Token-based Replay: Increasing Speed While Improving Diagnostics.” ATAED@ Petri Nets/ACSD. 2019.

The calculation of replay fitness aims to assess how much of the behavior in the log is admitted by the process model. Two methods are proposed to calculate replay fitness, based on token-based replay and alignments respectively.

For token-based replay, the percentage of traces that are completely fit is returned, along with a fitness value calculated as indicated in the referenced contribution.

Parameters:
  • log – Event log.

  • petri_net (PetriNet) – Petri net.

  • initial_marking (Marking) – Initial marking.

  • final_marking (Marking) – Final marking.

  • activity_key (str) – Attribute to be used for the activity (default is “concept:name”).

  • timestamp_key (str) – Attribute to be used for the timestamp (default is “time:timestamp”).

  • case_id_key (str) – Attribute to be used as the case identifier (default is “case:concept:name”).

Returns:

A dictionary containing fitness metrics.

Return type:

Dict[str, float]

Example:

```python import pm4py

net, im, fm = pm4py.discover_petri_net_inductive(

dataframe, activity_key=’concept:name’, case_id_key=’case:concept:name’, timestamp_key=’time:timestamp’

) fitness_tbr = pm4py.fitness_token_based_replay(

dataframe, net, im, fm, activity_key=’concept:name’, case_id_key=’case:concept:name’, timestamp_key=’time:timestamp’