-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/hotfixes' into release
- Loading branch information
Showing
15 changed files
with
188 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import pm4py | ||
|
||
|
||
def execute_script(): | ||
# example where the log skeleton is manullay built, and not automatically discovered from the log. | ||
|
||
log = pm4py.read_xes("../tests/input_data/running-example.xes") | ||
|
||
log_skeleton = {"always_after": set(), "always_before": set(), "equivalence": set(), "never_together": set(), | ||
"directly_follows": set(), "activ_freq": dict()} | ||
|
||
for act in pm4py.get_event_attribute_values(log, "concept:name"): | ||
# initially sets that every activity of the log can occur from 0 to 10 times | ||
# (without this constraints, conformance checking will signal deviations for every event) | ||
log_skeleton["activ_freq"][act] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} | ||
|
||
# sets that the 'reinitiate request' activity should not occur (so it occurs 0 times) | ||
log_skeleton["activ_freq"]["reinitiate request"] = {0} | ||
|
||
# sets that the 'pay compensation' activity should occur somewhen after the 'decide' activity. | ||
log_skeleton["always_after"].add(('decide', 'pay compensation')) | ||
|
||
# gets the conformance checking results. The first describes for each case of the log the exact deviations | ||
detailed_conf_results = pm4py.conformance_log_skeleton(log, log_skeleton) | ||
print(detailed_conf_results) | ||
|
||
# the second provides a summary (as a dataframe) of the fitness per case | ||
summary_df = pm4py.conformance_log_skeleton(log, log_skeleton, return_diagnostics_dataframe=True) | ||
print(summary_df) | ||
|
||
|
||
if __name__ == "__main__": | ||
execute_script() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pm4py | ||
|
||
|
||
def execute_script(): | ||
# example on how stochastic Petri nets are defined, discovered and used in pm4py | ||
log = pm4py.read_xes("../tests/input_data/running-example.xes", return_legacy_log_object=True) | ||
|
||
# first, we use a traditional process discovery algorithm (the inductive miner) to discover | ||
# a sound workflow net from the event log | ||
net, im, fm = pm4py.discover_petri_net_inductive(log) | ||
|
||
# then, we can either define manually the distributions on the stochastic Petri net, or discover them from the log | ||
# in the following lines, we automatically discover the stochastic map from the log | ||
from pm4py.algo.simulation.montecarlo.utils import replay | ||
smap0 = replay.get_map_from_log_and_net(log, net, im, fm) | ||
|
||
# each transition of the original Petri net is associated to a stochastic variable, having a priority, a weight | ||
# and a stochastic distribution on the firing times. | ||
for trans in smap0: | ||
print("\n") | ||
print(trans) | ||
print(dir(smap0[trans])) | ||
# priority says: if in a marking a transition with higher priority | ||
# is enabled, it should be considered before all the other transitions | ||
# with lower priority disregarding the weight | ||
print(smap0[trans].get_priority()) | ||
# weight sets the probability to fire the transition among all the | ||
# transitions with the same priority | ||
print(smap0[trans].get_weight()) | ||
# sets the random variable (independently from the weight) | ||
print(smap0[trans].random_variable) | ||
|
||
# as an alternative to discover the stochastic map from the log, we can define manually the stochastic map | ||
# (for example, we set all the invisible to zero firing times, and the other transitions' execution times | ||
# is set to a normal with average 1 and standard deviation 1 | ||
from pm4py.objects.random_variables.normal.random_variable import Normal | ||
from pm4py.objects.random_variables.constant0.random_variable import Constant0 | ||
|
||
smap = {} | ||
for t in net.transitions: | ||
if t.label == "register request" or t.label is None: | ||
v = Constant0() | ||
else: | ||
v = Normal(mu=1, sigma=1) | ||
smap[t] = v | ||
|
||
# eventually, we can use the stochastic Petri net with a specialized algorithm, | ||
# such as the stochastic playout | ||
from pm4py.algo.simulation.playout.petri_net.variants import stochastic_playout | ||
ret_log = stochastic_playout.apply(net, im, fm, parameters={"stochastic_map": smap0}) | ||
print(ret_log) | ||
|
||
|
||
if __name__ == "__main__": | ||
execute_script() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pm4py | ||
from pm4py.algo.clustering.trace_attribute_driven import algorithm as clust_algorithm | ||
|
||
|
||
def recursive_print_clusters(cluster_tree, rec_depth=0): | ||
if rec_depth > 0: | ||
# print the values belonging to the current part of the tree | ||
# (this allows filtering the event log on a given part of the tree) | ||
print("\t"*rec_depth, cluster_tree["name"].split("-")) | ||
|
||
for child in cluster_tree["children"]: | ||
recursive_print_clusters(child, rec_depth+1) | ||
|
||
if not cluster_tree["children"]: | ||
# there are no children, explicitly tell that | ||
print("\t"*(rec_depth+1), "END") | ||
|
||
|
||
def execute_script(): | ||
log = pm4py.read_xes("../tests/input_data/receipt.xes", return_legacy_log_object=True) | ||
log = pm4py.sample_cases(log, num_cases=20) | ||
# perform hierarchical clustering on the 'responsible' attribute of the log | ||
cluster_tree = clust_algorithm.apply(log, "responsible")[0] | ||
recursive_print_clusters(cluster_tree) | ||
|
||
|
||
if __name__ == "__main__": | ||
execute_script() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters