mining.alpha: the self-loop filter checks only the first activity and runs after the maximality step #15

Open
opened 2026-10-06 13:47:01 +00:00 by ffrauenberger · 1 comment
Owner

Severity: critical (whole activities silently disappear from the Alpha model, depending only on trace order)

Where

  • app/mining_algorithms/alpha_mining.py:66-95, :280-287

Problem

  1. Pairs (A, B) that contain a self-loop activity should be removed from YL. The helper only tests the first activity of A and of B:
    def __contains(a, b):
        for i in a:              # i = A, then B  (tuples of activities)
            for j in b:          # j = self-loop activity
                if j == i[0]:    # only the first activity of the tuple is checked
                    return True
    
    A pair like (("x","b"), ("c",)) with self-loop activity b survives. In the classic α-algorithm all members of A and B must satisfy a # a, so this pair must be removed. The result is wrong places in the Petri net, and activities can vanish from it (see below).
  2. generate_set_yl does yl_set = xl_set and then calls discard on it, which mutates self.xl_set in place. After mining, self.xl_set no longer contains XL. Nothing reads xl_set afterwards today, so this has no visible effect yet.

Steps to reproduce

  1. Open the application
  2. Import a log in which an activity b has a self-loop and occurs in a multi-activity set of XL, e.g. as ("x","b")
  3. Mine with the Alpha Miner and inspect the places of the Petri net (and xl_set afterwards)

Expected behavior

All pairs containing a self-loop activity in A or B are excluded from YL, and xl_set is unchanged after computing YL.

Actual behavior

Pairs whose self-loop activity is not the first element survive and produce wrong places. xl_set is reduced to YL.

Corrections from the review

  • The main cause is the filter order. The maximality step (:72-76) runs before the self-loop removal (:81-94). By then the smaller pairs without the self-loop activity are already gone. Example: XL {(a)→(x), (a)→(x,b), (x)→(c), (x,b)→(c), …} with self-loop b. Maximality drops (a)→(x) and (x)→(c). Removing (a)→(x,b) and (x,b)→(c) afterwards leaves nothing for x.
  • Activities vanish. nodes_to_draw holds only YL members, start and end activities (:120-125). So x disappears from the net. Whether this happens depends only on the order of traces in the log.
  • The fix proposed in the first draft is wrong. Applied after maximality, the any(...) check removes the only remaining pairs in every case.
  • Self-loop activities are dropped from the net even after the fix. Classic α cannot show length-1 loops; α+ re-attaches them. Implement that, or at least warn the user.

Reproduced with the same traces in two orders: {(a,x,c):5, (a,b,b,c):1, (a,b,b,b,c):1, (a,b,b,b,b,c):1}, and the same with (a,x,c) last. In the second order, YL is empty and the net has only a and c.

Fix

  • Remove pairs that contain a self-loop activity before the maximality step. Either filter a copy of XL first in generate_set_yl, or skip such subsets in generate_set_xl (:46-60). The second matches the classic definition (a # a for all members) and also makes the subset enumeration smaller (#37).
  • Check all members: any(x in self_loop for x in A) or any(x in self_loop for x in B).
  • Start YL from a copy: yl_set = set(xl_set).
  • Compute self_loop once in _calculate_filtered_model_state (:298-309).

Check

New tests/mining_algorithms/alpha_mining_test.py (no Alpha tests exist):

  • YL for the two logs above is {(('a',),('x',)), (('x',),('c',))} in both trace orders
  • xl_set is unchanged after generate_set_yl
  • x is a transition of the Petri net after generate_graph

Use frequencies that survive the default filters, or set the thresholds to 0.


from issues/BUG-015-alpha-miner-self-loop-filter-checks-only-first-element.md (code analysis of commit 6bcc646, 2026-10-03), corrected by the review in verdicts-claude/BUG-015-alpha-miner-self-loop-filter-checks-only-first-element.md

**Severity:** critical (whole activities silently disappear from the Alpha model, depending only on trace order) ## Where - `app/mining_algorithms/alpha_mining.py:66-95`, `:280-287` ## Problem 1. Pairs `(A, B)` that contain a self-loop activity should be removed from YL. The helper only tests the **first** activity of `A` and of `B`: ```python def __contains(a, b): for i in a: # i = A, then B (tuples of activities) for j in b: # j = self-loop activity if j == i[0]: # only the first activity of the tuple is checked return True ``` A pair like `(("x","b"), ("c",))` with self-loop activity `b` survives. In the classic α-algorithm all members of `A` and `B` must satisfy `a # a`, so this pair must be removed. The result is wrong places in the Petri net, and activities can vanish from it (see below). 2. `generate_set_yl` does `yl_set = xl_set` and then calls `discard` on it, which mutates `self.xl_set` in place. After mining, `self.xl_set` no longer contains XL. Nothing reads `xl_set` afterwards today, so this has no visible effect yet. ### Steps to reproduce 1. Open the application 2. Import a log in which an activity `b` has a self-loop and occurs in a multi-activity set of XL, e.g. as `("x","b")` 3. Mine with the Alpha Miner and inspect the places of the Petri net (and `xl_set` afterwards) ### Expected behavior All pairs containing a self-loop activity in `A` or `B` are excluded from YL, and `xl_set` is unchanged after computing YL. ### Actual behavior Pairs whose self-loop activity is not the first element survive and produce wrong places. `xl_set` is reduced to YL. ### Corrections from the review - **The main cause is the filter order.** The maximality step (`:72-76`) runs before the self-loop removal (`:81-94`). By then the smaller pairs without the self-loop activity are already gone. Example: XL `{(a)→(x), (a)→(x,b), (x)→(c), (x,b)→(c), …}` with self-loop `b`. Maximality drops `(a)→(x)` and `(x)→(c)`. Removing `(a)→(x,b)` and `(x,b)→(c)` afterwards leaves nothing for `x`. - **Activities vanish.** `nodes_to_draw` holds only YL members, start and end activities (`:120-125`). So `x` disappears from the net. Whether this happens depends only on the order of traces in the log. - **The fix proposed in the first draft is wrong.** Applied after maximality, the `any(...)` check removes the only remaining pairs in every case. - Self-loop activities are dropped from the net even after the fix. Classic α cannot show length-1 loops; α+ re-attaches them. Implement that, or at least warn the user. Reproduced with the same traces in two orders: `{(a,x,c):5, (a,b,b,c):1, (a,b,b,b,c):1, (a,b,b,b,b,c):1}`, and the same with `(a,x,c)` last. In the second order, YL is empty and the net has only `a` and `c`. ## Fix - Remove pairs that contain a self-loop activity **before** the maximality step. Either filter a copy of XL first in `generate_set_yl`, or skip such subsets in `generate_set_xl` (`:46-60`). The second matches the classic definition (`a # a` for all members) and also makes the subset enumeration smaller (#37). - Check all members: `any(x in self_loop for x in A) or any(x in self_loop for x in B)`. - Start YL from a copy: `yl_set = set(xl_set)`. - Compute `self_loop` once in `_calculate_filtered_model_state` (`:298-309`). ## Check New `tests/mining_algorithms/alpha_mining_test.py` (no Alpha tests exist): - YL for the two logs above is `{(('a',),('x',)), (('x',),('c',))}` in both trace orders - `xl_set` is unchanged after `generate_set_yl` - `x` is a transition of the Petri net after `generate_graph` Use frequencies that survive the default filters, or set the thresholds to 0. --- from `issues/BUG-015-alpha-miner-self-loop-filter-checks-only-first-element.md` (code analysis of commit 6bcc646, 2026-10-03), corrected by the review in `verdicts-claude/BUG-015-alpha-miner-self-loop-filter-checks-only-first-element.md`
Author
Owner

Reviewed by Codex (GPT-6) against origin/main 6bcc646eb464.

Review: partially correct.

Reproduced the two trace-order outcomes: one order retains pairs containing (x,b), while the other has empty YL and loses x. The main corrections and filter-before-maximality fix are supported. One statement is too broad: self-loop activities are not always dropped even after that fix. nodes_to_draw explicitly unions start and end activities (lines 120–123), so a self-loop activity that is also a boundary activity can still be drawn. Drawing it does not make its length-one-loop behavior correct; α+ support or a warning is still needed.

Code references: app/mining_algorithms/alpha_mining.py:120, app/mining_algorithms/alpha_mining.py:66.

Reviewed by **Codex (GPT-6)** against origin/main [`6bcc646eb464`](https://code.swisdata.eu/ffrauenberger/ProcessIntel/commit/6bcc646eb464e0dd897228b5e49867f65d7255c4). **Review: partially correct.** Reproduced the two trace-order outcomes: one order retains pairs containing `(x,b)`, while the other has empty YL and loses `x`. The main corrections and filter-before-maximality fix are supported. One statement is too broad: self-loop activities are not **always** dropped even after that fix. `nodes_to_draw` explicitly unions start and end activities (lines 120–123), so a self-loop activity that is also a boundary activity can still be drawn. Drawing it does not make its length-one-loop behavior correct; α+ support or a warning is still needed. Code references: [app/mining_algorithms/alpha_mining.py:120](https://code.swisdata.eu/ffrauenberger/ProcessIntel/src/commit/6bcc646eb464e0dd897228b5e49867f65d7255c4/app/mining_algorithms/alpha_mining.py#L120), [app/mining_algorithms/alpha_mining.py:66](https://code.swisdata.eu/ffrauenberger/ProcessIntel/src/commit/6bcc646eb464e0dd897228b5e49867f65d7255c4/app/mining_algorithms/alpha_mining.py#L66).
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ffrauenberger/ProcessIntel#15
No description provided.