Skip to content

Commit 29c9e0f

Browse files
committed
Added comments and changed logic
1 parent d5dfc94 commit 29c9e0f

File tree

4 files changed

+418
-257
lines changed

4 files changed

+418
-257
lines changed

explainer/explainer_regex.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ def counterfactual_expl(self, trace):
214214
if self.minimal_solution:
215215
self.adherent_trace = None
216216
length_of_trace = len(trace)
217-
print(length_of_trace)
218217
delta = 1 # Starting with an increment of 1
219218
while not self.adherent_trace:
220219
self.contradiction_by_length(length_of_trace)
@@ -363,12 +362,17 @@ def determine_conformance_rate(self, event_log, constraints=None):
363362
return (len_log - non_conformant) / len_log
364363

365364
def determine_fitness_rate(self, event_log, constraints=None):
365+
"""
366+
Determines the fitness rate of the event log based on given constraints.
367+
368+
:param event_log: The event log to analyze.
369+
:param constraints: The constraints to check against the event log. If None, use self.constraints.
370+
:return: The fitness rate as a float between 0 and 1.
371+
"""
366372
if not self.constraints and not constraints:
367373
return "The explainer have no constraints"
368374
if constraints == None:
369375
constraints = self.constraints
370-
if len(constraints) == 0:
371-
print("hej")
372376
conformant = 0
373377
for con in constraints:
374378
for trace, count in event_log.log.items():
@@ -377,6 +381,14 @@ def determine_fitness_rate(self, event_log, constraints=None):
377381
return conformant / (len(event_log) * len(constraints))
378382

379383
def variant_ctrb_to_fitness(self, event_log, trace, constraints=None):
384+
"""
385+
Determines the contribution of a specific trace variant to the fitness of the event log.
386+
387+
:param event_log: The event log to analyze.
388+
:param trace: The trace variant to calculate its contribution.
389+
:param constraints: The constraints to check against the event log. If None, use self.constraints.
390+
:return: The contribution of the trace variant to the fitness as a float.
391+
"""
380392
if not self.constraints and not constraints:
381393
return "The explainer have no constraints"
382394
if not constraints:
@@ -445,6 +457,14 @@ def constraint_ctrb_to_conformance(self, log, constraints, index):
445457
return sum(sub_ctrbs)
446458

447459
def constraint_ctrb_to_fitness(self, log, constraints, index):
460+
"""
461+
Determines the Shapley value-based contribution of a constraint to the overall conformance rate.
462+
463+
:param log: The event log, where keys are strings and values are counts of trace variants.
464+
:param constraints: A list of constraints (regexp strings).
465+
:param index: The index of the constraint in the constraints list.
466+
:return: The contribution of the constraint to the overall conformance rate as a float.
467+
"""
448468
if len(constraints) < index:
449469
raise Exception("Constraint not in constraint list.")
450470
if not self.constraints and not constraints:

0 commit comments

Comments
 (0)