pm4py.conformance.fitness_alignments#

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

Calculate the fitness using alignments. The output dictionary contains the following keys: - 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).

Alignment-based replay aims to find one of the best alignments between the trace and the model. For each trace, the output of an alignment is a list of pairs where the first element is an event (from the trace) or » and the second element is a transition (from the model) or ». Each pair can be classified as follows:

  • Sync move: The event and transition labels correspond, advancing both the trace and the model simultaneously.

  • Move on log: The transition is », indicating a replay move in the trace that is not mirrored in the model. This move is unfit and signals a deviation.

  • Move on model: The event is », indicating a replay move in the model not mirrored in the trace. These can be further classified as:
    • Moves on model involving hidden transitions: Even if it’s not a sync move, the move is fit.

    • Moves on model not involving hidden transitions: The move is unfit and signals a deviation.

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 alignments, the percentage of traces that are completely fit is returned, along with a fitness value calculated as the average of the fitness values of the individual traces.

Parameters:
  • log – Event log.

  • petri_net (PetriNet) – Petri net.

  • initial_marking (Marking) – Initial marking.

  • final_marking (Marking) – Final marking.

  • multi_processing (bool) – Boolean to enable multiprocessing (default is constants.ENABLE_MULTIPROCESSING_DEFAULT).

  • 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”).

  • variant_str – Variant specification.

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_alignments = pm4py.fitness_alignments(

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