Added `memory_profiler` and placed data and results in proper directories

master
Meliurwen 2 years ago
parent 39bf13cf5b
commit c77d7a23bb
Signed by: meliurwen
GPG Key ID: 818A8B35E9F1CE10
  1. 8
      .gitignore
  2. 32
      benchmark.py

8
.gitignore vendored

@ -0,0 +1,8 @@
venv/
.venv/
data/
res/
*.dat

@ -2,19 +2,27 @@
import glob import glob
import os import os
from pathlib import Path
from memory_profiler import profile
from pyctbn.legacy import JsonImporter from pyctbn.legacy import JsonImporter
from pyctbn.legacy import SamplePath from pyctbn.legacy import SamplePath
from pyctbn.legacy import StructureConstraintBasedEstimator from pyctbn.legacy import StructureConstraintBasedEstimator
@profile
def structure_constraint_based_estimation_example(): def structure_constraint_based_estimation_example():
Path("./data").mkdir(parents=True, exist_ok=True)
# <read the json files in ./data path> # <read the json files in ./data path>
read_files = glob.glob(os.path.join('./', "*.json")) read_files = glob.glob(os.path.join("./data/", "*.json"))
# <initialize a JsonImporter object for the first file> # <initialize a JsonImporter object for the first file>
importer = JsonImporter(file_path=read_files[0], samples_label='samples', importer = JsonImporter(
structure_label='dyn.str', variables_label='variables', file_path=read_files[0],
time_key='Time', variables_key='Name') samples_label='samples',
structure_label='dyn.str',
variables_label='variables',
time_key='Time',
variables_key='Name'
)
# <import the data at index 0 of the outer json array> # <import the data at index 0 of the outer json array>
importer.import_data(0) importer.import_data(0)
# construct a SamplePath Object passing a filled AbstractImporter object # 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 # and the independence tests significance, if you have prior knowledge about
# the net structure create a list of tuples # the net structure create a list of tuples
# that contains them and pass it as known_edges parameter # 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, se1 = StructureConstraintBasedEstimator(
known_edges=[], thumb_threshold=25) 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 # call the algorithm to estimate the structure
se1.estimate_structure() se1.estimate_structure()
# obtain the adjacency matrix of the estimated structure # obtain the adjacency matrix of the estimated structure
print(se1.adjacency_matrix()) print(se1.adjacency_matrix())
Path("./res").mkdir(parents=True, exist_ok=True)
# save the estimated structure to a json file # save the estimated structure to a json file
# (remember to specify the path AND the .json extension).... # (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 # ...or save it also in a graphical model fashion
# (remember to specify the path AND the .png extension) # (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() structure_constraint_based_estimation_example()

Loading…
Cancel
Save