@@ -47,7 +47,7 @@ def tqdm(iterable=None, *args, **kwargs):
4747from pm4py .objects .genetic_matrix .obj import GeneticMatrix
4848
4949# typing
50- from typing import Any , Iterable , Optional , Union
50+ from typing import Any , Dict , Iterable , List , Optional , Tuple , Union
5151from pandas .core .frame import DataFrame
5252from pm4py .objects .log .obj import EventLog , EventStream
5353from pm4py .objects .petri_net .obj import PetriNet , Marking
@@ -56,8 +56,8 @@ def tqdm(iterable=None, *args, **kwargs):
5656
5757def apply (
5858 log : Union [EventLog , EventStream , DataFrame ],
59- parameters : Optional [dict [Union [str , Parameters ], Any ]] = None ,
60- ) -> tuple [PetriNet , Marking , Marking ]:
59+ parameters : Optional [Dict [Union [str , Parameters ], Any ]] = None ,
60+ ) -> Tuple [PetriNet , Marking , Marking ]:
6161 """
6262 Discovers a Petri net using Genetic Miner
6363
@@ -178,7 +178,7 @@ def apply(
178178 log_csv .writerow ([datetime .now (), len (history )] + fitness )
179179 return matrix2petrinet (GeneticMatrix (* population [0 ], T ))
180180
181- def individuals (log : Union [DataFrame , EventLog ], sample_size = 1 , T = None , keys : dict [str ,str ] = {"activity_key" :xes .DEFAULT_NAME_KEY , "timestamp_key" :xes .DEFAULT_TIMESTAMP_KEY , "case_id_key" :constants .CASE_CONCEPT_NAME }) -> list [Individual ]:
181+ def individuals (log : Union [DataFrame , EventLog ], sample_size = 1 , T = None , keys : Dict [str , str ] = {"activity_key" :xes .DEFAULT_NAME_KEY , "timestamp_key" :xes .DEFAULT_TIMESTAMP_KEY , "case_id_key" :constants .CASE_CONCEPT_NAME }) -> List [Individual ]:
182182 if not T :
183183 T = tuple (log [keys ['activity_key' ]].unique ())
184184 # polyfill for itertools.pairwise (requires Python 3.10+)
@@ -217,14 +217,14 @@ def pairwise(iterable):
217217 return samples
218218
219219def tournament (
220- population : list [Individual ],
220+ population : List [Individual ],
221221 log : Union [DataFrame , EventLog ],
222222 T ,
223223 sort = True ,
224224 activity_key : str = xes .DEFAULT_NAME_KEY ,
225225 timestamp_key : str = xes .DEFAULT_TIMESTAMP_KEY ,
226226 case_id_key : str = constants .CASE_CONCEPT_NAME ,
227- ) -> tuple [ list [Individual ], list [float ]]:
227+ ) -> Tuple [ List [Individual ], List [float ]]:
228228 """sort=True: sort descending by fitness (i.e. best first)"""
229229 # @src 6.2. Fitness Calculation; https://doi.org/10.1007/11494744_5
230230 fitness = []
@@ -260,7 +260,7 @@ def tournament(
260260 population , fitness = list (population ), list (fitness )
261261 return (population , fitness )
262262
263- def sample_parents (population : list [Individual ], fitness : list [float ], elitism_min_sample : int ):
263+ def sample_parents (population : List [Individual ], fitness : List [float ], elitism_min_sample : int ):
264264 population_fitness = tuple (zip (population , fitness ))
265265 parent1 = sorted (
266266 random .sample (population_fitness , k = elitism_min_sample ),
@@ -277,7 +277,7 @@ def sample_parents(population: list[Individual], fitness: list[float], elitism_m
277277 )[0 ][0 ]
278278 return (parent1 , parent2 )
279279
280- def crossover (parent1 : Individual , parent2 : Individual , T : list [str ]) -> tuple [Individual ,Individual ]:
280+ def crossover (parent1 : Individual , parent2 : Individual , T : List [str ]) -> Tuple [Individual , Individual ]:
281281 # @src 6.3. Genetic Operations: Crossover; https://doi.org/10.1007/11494744_5
282282 # 1. cross-over point
283283 t = random .choice (T )
@@ -344,7 +344,7 @@ def mutate(individual: Individual, rate: float = 0.01) -> Individual:
344344 O [t ] = rand_partition (itertools .chain (* O [t ]))
345345 return (I ,O )
346346
347- def repair (I : InputMap , O : OutputMap , C : numpy .ndarray , T : list [str ]) -> Individual :
347+ def repair (I : InputMap , O : OutputMap , C : numpy .ndarray , T : List [str ]) -> Individual :
348348 """
349349 Merging partitions until petri-net is (coherent) workflow net
350350 see last requirement in 4. Causal Matrix, Def. 4; https://doi.org/10.1007/11494744_5
0 commit comments