From c77d7a23bb2dec62c713fef9833f94a2b0e95f31 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Tue, 7 Feb 2023 14:36:44 +0100 Subject: [PATCH] Added `memory_profiler` and placed data and results in proper directories --- .gitignore | 8 ++++++++ benchmark.py | 32 +++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6df8c65 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ + +venv/ +.venv/ + +data/ +res/ + +*.dat diff --git a/benchmark.py b/benchmark.py index ee75db3..a4578b9 100755 --- a/benchmark.py +++ b/benchmark.py @@ -2,19 +2,27 @@ import glob import os +from pathlib import Path +from memory_profiler import profile from pyctbn.legacy import JsonImporter from pyctbn.legacy import SamplePath from pyctbn.legacy import StructureConstraintBasedEstimator - +@profile def structure_constraint_based_estimation_example(): + Path("./data").mkdir(parents=True, exist_ok=True) # - read_files = glob.glob(os.path.join('./', "*.json")) + read_files = glob.glob(os.path.join("./data/", "*.json")) # - importer = JsonImporter(file_path=read_files[0], samples_label='samples', - structure_label='dyn.str', variables_label='variables', - time_key='Time', variables_key='Name') + importer = JsonImporter( + file_path=read_files[0], + samples_label='samples', + structure_label='dyn.str', + variables_label='variables', + time_key='Time', + variables_key='Name' + ) # importer.import_data(0) # construct a SamplePath Object passing a filled AbstractImporter object @@ -27,17 +35,23 @@ def structure_constraint_based_estimation_example(): # and the independence tests significance, if you have prior knowledge about # the net structure create a list of tuples # that contains them and pass it as known_edges parameter - se1 = StructureConstraintBasedEstimator(sample_path=s1, exp_test_alfa=0.1, chi_test_alfa=0.1, - known_edges=[], thumb_threshold=25) + se1 = StructureConstraintBasedEstimator( + sample_path=s1, + exp_test_alfa=0.1, + chi_test_alfa=0.1, + known_edges=[], + thumb_threshold=25 + ) # call the algorithm to estimate the structure se1.estimate_structure() # obtain the adjacency matrix of the estimated structure print(se1.adjacency_matrix()) + Path("./res").mkdir(parents=True, exist_ok=True) # save the estimated structure to a json file # (remember to specify the path AND the .json extension).... - se1.save_results('./results0.json') + se1.save_results("./res/results0.json") # ...or save it also in a graphical model fashion # (remember to specify the path AND the .png extension) - se1.save_plot_estimated_structure_graph('./result0.png') + se1.save_plot_estimated_structure_graph("./res/result0.png") structure_constraint_based_estimation_example()