def test_tangiblereachabilitygraph_calc(self): # to avoid static method warnings in tests, # that by construction of the unittest package have to be expressed in such way self.dummy_variable = "dummy_value" input_log = os.path.join(INPUT_DATA_DIR, "running-example.xes") log = xes_importer.import_log(input_log) net, initial_marking, final_marking = alpha_miner.apply(log) s_map = stochastic_map.get_map_from_log_and_net(log, net, initial_marking, final_marking) reachab_graph = construct_reachability_graph(net, initial_marking) tang_reach_graph = tangible_reachability.get_tangible_reachability_from_reachability(reachab_graph, s_map) viz = ts_vis_factory.apply(tang_reach_graph, parameters={"format": "svg", "show_labels": True}) del viz # gets the Q matrix assuming exponential distributions q_matrix = ctmc.get_q_matrix_from_tangible_exponential(tang_reach_graph, s_map) # pick a state to start from states = sorted(list(tang_reach_graph.states), key=lambda x: x.name) state = states[0] transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(tang_reach_graph, q_matrix, state, 86400) del transient_result transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(tang_reach_graph, q_matrix, state, 864000) del transient_result steady_state = ctmc.steadystate_analysis_from_tangible_q_matrix(tang_reach_graph, q_matrix) del steady_state
def apply(df, delay, parameters=None): """ Perform CTMC simulation on a dataframe Parameters ------------- df Dataframe delay Delay parameters Possible parameters of the algorithm Returns ------------- graph Case duration graph """ if parameters is None: parameters = {} tang_reach_graph, transient_analysis, fillcolors = ctmc.transient_analysis_from_dataframe( df, delay, parameters=parameters) viz = ts_vis_factory.apply(tang_reach_graph, parameters={ "format": "svg", "force_names": transient_analysis, "fillcolors": fillcolors }) gviz_base64 = base64.b64encode(str(viz).encode('utf-8')) return get_base64_from_gviz(viz), gviz_base64
def execute_script(): # log_path = "C:/Users/bas/Documents/tue/svn/private/logs/ilp_test_2_abcd_acbd.xes" log_path = os.path.join("..", "tests", "input_data", "running-example.xes") log = xes_importer.import_log(log_path) ts = ts_factory.apply(log) viz = ts_vis_factory.apply(ts, parameters={"format": "svg"}) ts_vis_factory.view(viz)
def execute_script(): log_path = os.path.join("..", "tests", "input_data", "running-example.xes") log = xes_importer.apply(log_path) # obtain Petri net through Alpha Miner net, initial_marking, final_marking = alpha_miner.apply(log) # obtain stochastic information for transitions in the model s_map = stochastic_map.get_map_from_log_and_net( log, net, initial_marking, final_marking, force_distribution="EXPONENTIAL") # export the current stochastic Petri net petri_exporter.export_net(net, initial_marking, "example.pnml", final_marking=final_marking, stochastic_map=s_map) # re-import the current stochastic Petri net from file net, initial_marking, final_marking, s_map = petri_importer.import_net( "example.pnml", return_stochastic_information=True) # remove temporary file os.remove("example.pnml") # gets the reachability graph from the Petri net reachab_graph = construct_reachability_graph(net, initial_marking) # get the tangible reachability graph from the reachability graph and the stochastic map tang_reach_graph = tangible_reachability.get_tangible_reachability_from_reachability( reachab_graph, s_map) # visualize the tangible reachability graph on the screen viz = ts_vis_factory.apply(tang_reach_graph, parameters={ "format": "svg", "show_labels": True, "show_names": True }) ts_vis_factory.view(viz) # gets the Q matrix assuming exponential distributions q_matrix = ctmc.get_q_matrix_from_tangible_exponential( tang_reach_graph, s_map) # pick a state to start from states = sorted(list(tang_reach_graph.states), key=lambda x: x.name) state = states[0] print("\n\nstarting from state = ", state.name) # do transient analysis after 1 day transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state( tang_reach_graph, q_matrix, state, 86400) print("\nprobability for each state after 1 day = ", transient_result) # do transient analysis after 10 days transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state( tang_reach_graph, q_matrix, state, 864000) print("\nprobability for each state after 10 days = ", transient_result) # do transient analysis after 100 days transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state( tang_reach_graph, q_matrix, state, 8640000) print("\nprobability for each state after 100 days = ", transient_result) steady_state = ctmc.steadystate_analysis_from_tangible_q_matrix( tang_reach_graph, q_matrix) print("\nsteady state = ", steady_state)
def execute_script(): log_path = os.path.join("..", "tests", "input_data", "running-example.csv") dataframe = pandas_df_imp.import_dataframe_from_path(log_path) activities_count = dict(dataframe.groupby("concept:name").size()) [dfg_frequency, dfg_performance] = df_statistics.get_dfg_graph(dataframe, measure="both", perf_aggregation_key="mean") net, initial_marking, final_marking = alpha_miner.apply_dfg(dfg_frequency) spaths = get_shortest_paths(net) aggregated_statistics = get_decorations_from_dfg_spaths_acticount(net, dfg_performance, spaths, activities_count, variant="performance") # obtain stochastic information for transitions in the model s_map = stochastic_map.get_map_exponential_from_aggstatistics(aggregated_statistics) # gets the reachability graph from the Petri net reachab_graph = construct_reachability_graph(net, initial_marking) # get the tangible reachability graph from the reachability graph and the stochastic map tang_reach_graph = tangible_reachability.get_tangible_reachability_from_reachability(reachab_graph, s_map) # visualize the tangible reachability graph on the screen viz = ts_vis_factory.apply(tang_reach_graph, parameters={"format": "svg", "show_labels": True, "show_names": True}) ts_vis_factory.view(viz) # gets the Q matrix assuming exponential distributions q_matrix = ctmc.get_q_matrix_from_tangible_exponential(tang_reach_graph, s_map) # pick a state to start from states = sorted(list(tang_reach_graph.states), key=lambda x: x.name) state = states[0] print("\n\nstarting from state = ", state.name) # do transient analysis after 1 day transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(tang_reach_graph, q_matrix, state, 86400) print("\nprobability for each state after 1 day = ", transient_result) # do transient analysis after 10 days transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(tang_reach_graph, q_matrix, state, 864000) print("\nprobability for each state after 10 days = ", transient_result) # do transient analysis after 100 days transient_result = ctmc.transient_analysis_from_tangible_q_matrix_and_single_state(tang_reach_graph, q_matrix, state, 8640000) print("\nprobability for each state after 100 days = ", transient_result) steady_state = ctmc.steadystate_analysis_from_tangible_q_matrix(tang_reach_graph, q_matrix) print("\nsteady state = ", steady_state)
def show(model, tel, file_name, parameters): ''' Show model and its quality measures :param model: model type (transition system, state based region, DFG miner, alpha miner) :param tel: input log :param file_name: img file name to show model :param parameters: parmater for transition system (afreq, sfreq) :return: ''' tel_flag = False if isinstance(tel[0][0], tel_event): tel_flag = True if model in ['ts', 'sbr']: if tel_flag: output_file_path = os.path.join( "static", "images", file_name[:file_name.find('.')] + '_' + model + '_' + str(parameters['afreq_thresh']) + '_' + str(parameters['sfreq_thresh']) + ".png") else: output_file_path = os.path.join( "static", "images", "2" + "_" + file_name[:file_name.find('.')] + '_' + model + '_' + str(parameters[PARAM_KEY_DIRECTION]) + '_' + str(parameters[PARAM_KEY_WINDOW]) + "_" + str(parameters[PARAM_KEY_VIEW]) + ".png") auto = utils.discover_annotated_automaton(tel, parameters=parameters) max_thresh = {} max_afreq = 0 max_sfreq = 0 if tel_flag: for trans in auto.transitions: max_afreq = max(max_afreq, trans.afreq) for state in auto.states: max_sfreq = max(max_sfreq, state.sfreq) max_thresh['afreq'] = max_afreq max_thresh['sfreq'] = max_sfreq if model == 'ts': result = {} gviz = vis_factory.apply(auto) vis_factory.save(gviz, output_file_path) result['num of transitions'] = len(auto.transitions) result['num of states'] = len(auto.states) else: net, im, fm = sb.petri_net_synthesis(auto) gviz = petri_vis_factory.apply(net, im, fm) petri_vis_factory.save(gviz, output_file_path) result = evaluation(net, im, fm, tel) else: if tel_flag: output_file_path = os.path.join( "static", "images", file_name[:file_name.find('.')] + '_' + model + '_' + ".png") else: output_file_path = os.path.join( "static", "images", "2" + file_name[:file_name.find('.')] + '_' + model + '_' + ".png") if model == 'alpha': if isinstance(tel[0][0], Event): net, im, fm = trans_alpha(tel) else: net, im, fm = alpha_miner.apply(tel) gviz = petri_vis_factory.apply(net, im, fm) petri_vis_factory.save(gviz, output_file_path) result = evaluation(net, im, fm, tel) else: dfg = dfg_factory.apply(tel) if tel_flag: dfg_tel = inductive_revise.get_dfg_graph_trans(tel) #dfg = dfg_tel + dfg dfg = dfg_tel gviz = dfg_vis_factory.apply(dfg, log=tel) dfg_vis_factory.save(gviz, output_file_path) result = dict( sorted(dfg.items(), key=operator.itemgetter(1), reverse=True)) max_thresh = None return output_file_path, result, max_thresh
from translucent_event_log.objects.tel.importer.xes.iterparse_tel import import_tel import os from translucent_event_log.objects.tel.importer.xes.utils import log_to_tel from translucent_event_log.objects.tel.utils import tel_set_enabled from pm4py.algo.discovery.alpha import factory as alpha_miner from pm4py.visualization.petrinet import factory as vis_factory from pm4py.visualization.transition_system import factory as trans_vis_factory from pm4py.algo.discovery.transition_system import factory as trans_factory from translucent_event_log.objects.tel import utils from translucent_event_log.algo.discover_petrinet import state_based_region as sb input_file_path = os.path.join("input_data", "test_logs", "running_10_tel.xes") log = import_tel(input_file_path) tel = tel_set_enabled(log) auto = utils.discover_annotated_automaton(tel) gviz = trans_vis_factory.apply(auto) trans_vis_factory.view(gviz) #show automaton auto_2 = trans_factory.apply(log) nett, im, fm = sb.petri_net_synthesis(auto) net, i, f = sb.petri_net_synthesis(auto_2) # gviz = vis_factory.apply(nett, im, fm) vis_factory.view(gviz) # gviz = vis_factory.apply(net, i, f) # vis_factory.view(gviz)
import os from tests.translucent_event_log_new.objects.tel.importer.xes.utils import log_to_tel from pm4py.algo.discovery.alpha import factory as alpha_miner from tests.translucent_event_log_new.objects.tel.utils import tel_set_enabled from pm4py.visualization.transition_system import factory as vis_factory from pm4py.visualization.petrinet import factory as petri_factory from tests.translucent_event_log_new.algo.discover_automaton import utils from datetime import timedelta from tests.translucent_event_log_new.algo.discover_petrinet import state_based_region as sb input_file_path = os.path.join("input_data", "running-example_tel.xes") log = import_tel(input_file_path) tel = tel_set_enabled(log) auto = utils.discover_annotated_automaton(tel) gviz = vis_factory.apply(auto) vis_factory.view(gviz) #show automaton auto = utils.discover_annotated_automaton(tel, parameters={ 'sfreq_thresh': 2, 'afreq_thresh': 3 }) gviz = vis_factory.apply(auto) vis_factory.view(gviz) #show automaton nett, im, fm = sb.petri_net_synthesis(auto) # gviz = petri_factory.apply(nett, im, fm) petri_factory.view(gviz)