mining.genetic: replace the GeneticMining class with a pure, seeded function #72

Open
opened 2026-10-09 12:22:05 +00:00 by ffrauenberger · 0 comments
Owner

Severity: improvement (part of #66; the miner's result depends on the history of its instance and on the global random state)
Requested by: the user (2026-10-09)

Where

  • app/mining_algorithms/genetic_mining.py:31-60 — GeneticMining(BaseMining); the constructor sets eight GA parameters, dependency_matrix, best_individual, start_measures, end_measures and petri_net on self.
  • app/mining_algorithms/genetic_mining.py:62-169 — generate_graph resets the results on self, writes all parameters to self, then fills dependency_matrix, the measures and best_individual.
  • app/mining_algorithms/genetic_mining.py:422, :455, :522 — best_individual, self.graph and self.petri_net are set from inside helper methods.
  • app/mining_algorithms/genetic_mining.py:389, :480, :562-572, :613-615, :712-732, :807, :842, :871-883, :943 — the module-level random and np.random are used directly; there is no seed.
  • app/mining_algorithms/genetic_mining.py:1067-1086 — getters for the GA parameters.
  • app/ui/genetic_miner_ui/genetic_miner_controller.py:62-83, :196-201 — the controller reads the getters, fitness_threshold and get_graph() from the instance.

Problem

The genetic miner keeps its parameters, its population results and its graph on the instance, and helper methods write best_individual and the graph as a side effect. It also draws from the global random generators. So two runs with the same input give different graphs, and a test cannot pin the result.

Fix

Follow the plan in #66 (code#write-simple-functional-code):

  • mine_genetic(log, params) -> MiningResult, with params holding the GA parameters, the shared filter thresholds and a seed.
  • Create one random.Random(seed) and one numpy.random.Generator from the seed, and pass them to the selection, crossover, mutation and individual creation functions. Do not use the module-level random or np.random.
  • The dependency matrix, start and end measures and the best individual become return values, not fields.
  • MiningResult holds the graph, the Petri net, the best individual's fitness and the effective parameters.
  • Use the pure helpers for the shared steps of BaseMining (#66).
  • Let GeneticMining delegate to mine_genetic until the controller has moved, then remove it.

Related: #17 (measures ignore trace frequencies) and #39 (runtime) touch the same code.

Check

  • A unit test calls mine_genetic twice with the same log, params and seed and gets equal results.
  • A test runs it with other params first, then with the first params again, and gets the same result as on a fresh call.
  • git grep -nE "class GeneticMining|^\s*(import random|random\.|np\.random\.)" app/mining_algorithms/genetic_mining.py returns nothing.

from a session on 2026-10-09, split from #66

**Severity:** improvement (part of #66; the miner's result depends on the history of its instance and on the global random state) **Requested by:** the user (2026-10-09) ## Where - `app/mining_algorithms/genetic_mining.py:31-60` — `GeneticMining(BaseMining)`; the constructor sets eight GA parameters, `dependency_matrix`, `best_individual`, `start_measures`, `end_measures` and `petri_net` on `self`. - `app/mining_algorithms/genetic_mining.py:62-169` — `generate_graph` resets the results on `self`, writes all parameters to `self`, then fills `dependency_matrix`, the measures and `best_individual`. - `app/mining_algorithms/genetic_mining.py:422`, `:455`, `:522` — `best_individual`, `self.graph` and `self.petri_net` are set from inside helper methods. - `app/mining_algorithms/genetic_mining.py:389`, `:480`, `:562-572`, `:613-615`, `:712-732`, `:807`, `:842`, `:871-883`, `:943` — the module-level `random` and `np.random` are used directly; there is no seed. - `app/mining_algorithms/genetic_mining.py:1067-1086` — getters for the GA parameters. - `app/ui/genetic_miner_ui/genetic_miner_controller.py:62-83`, `:196-201` — the controller reads the getters, `fitness_threshold` and `get_graph()` from the instance. ## Problem The genetic miner keeps its parameters, its population results and its graph on the instance, and helper methods write `best_individual` and the graph as a side effect. It also draws from the global random generators. So two runs with the same input give different graphs, and a test cannot pin the result. ## Fix Follow the plan in #66 (`code#write-simple-functional-code`): - `mine_genetic(log, params) -> MiningResult`, with `params` holding the GA parameters, the shared filter thresholds and a `seed`. - Create one `random.Random(seed)` and one `numpy.random.Generator` from the seed, and pass them to the selection, crossover, mutation and individual creation functions. Do not use the module-level `random` or `np.random`. - The dependency matrix, start and end measures and the best individual become return values, not fields. - `MiningResult` holds the graph, the Petri net, the best individual's fitness and the effective parameters. - Use the pure helpers for the shared steps of `BaseMining` (#66). - Let `GeneticMining` delegate to `mine_genetic` until the controller has moved, then remove it. Related: #17 (measures ignore trace frequencies) and #39 (runtime) touch the same code. ## Check - A unit test calls `mine_genetic` twice with the same log, params and seed and gets equal results. - A test runs it with other params first, then with the first params again, and gets the same result as on a fresh call. - `git grep -nE "class GeneticMining|^\s*(import random|random\.|np\.random\.)" app/mining_algorithms/genetic_mining.py` returns nothing. --- from a session on 2026-10-09, split from #66
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#72
No description provided.