commit 39bf13cf5b687de64c1966d43890c0c7558efd90 Author: meliurwen Date: Tue Feb 7 12:39:58 2023 +0100 First working version diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..53ee37d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "PyCTBN"] + path = deps/PyCTBN + url = ../PyCTBN.git + branch = master diff --git a/benchmark.py b/benchmark.py new file mode 100755 index 0000000..ee75db3 --- /dev/null +++ b/benchmark.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +import glob +import os + +from pyctbn.legacy import JsonImporter +from pyctbn.legacy import SamplePath +from pyctbn.legacy import StructureConstraintBasedEstimator + + +def structure_constraint_based_estimation_example(): + # + read_files = glob.glob(os.path.join('./', "*.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.import_data(0) + # construct a SamplePath Object passing a filled AbstractImporter object + s1 = SamplePath(importer=importer) + # build the trajectories + s1.build_trajectories() + # build the information about the net + s1.build_structure() + # construct a StructureEstimator object passing a correctly build SamplePath object + # 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) + # call the algorithm to estimate the structure + se1.estimate_structure() + # obtain the adjacency matrix of the estimated structure + print(se1.adjacency_matrix()) + # save the estimated structure to a json file + # (remember to specify the path AND the .json extension).... + se1.save_results('./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') + +structure_constraint_based_estimation_example() diff --git a/deps/PyCTBN b/deps/PyCTBN new file mode 160000 index 0000000..4ef741e --- /dev/null +++ b/deps/PyCTBN @@ -0,0 +1 @@ +Subproject commit 4ef741e7f77351d7c80c48d4dc617c3735e422eb