Old engine for Continuous Time Bayesian Networks. Superseded by reCTBN. 🐍
https://github.com/madlabunimib/PyCTBN
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
3.4 KiB
87 lines
3.4 KiB
4 years ago
|
|
||
4 years ago
|
# License: MIT License
|
||
|
|
||
|
|
||
4 years ago
|
import unittest
|
||
4 years ago
|
import glob
|
||
|
import os
|
||
4 years ago
|
import random
|
||
|
|
||
3 years ago
|
from pyctbn.legacy.utility.json_importer import JsonImporter
|
||
|
from pyctbn.legacy.structure_graph.sample_path import SamplePath
|
||
|
from pyctbn.legacy.structure_graph.trajectory import Trajectory
|
||
|
from pyctbn.legacy.structure_graph.structure import Structure
|
||
4 years ago
|
|
||
|
|
||
|
class TestSamplePath(unittest.TestCase):
|
||
|
|
||
4 years ago
|
@classmethod
|
||
|
def setUpClass(cls) -> None:
|
||
3 years ago
|
cls.read_files = glob.glob(os.path.join('./tests/data', "*.json"))
|
||
4 years ago
|
|
||
|
def test_init_not_initialized_importer(self):
|
||
4 years ago
|
importer = JsonImporter(self.read_files[2], 'samples', 'dyn.str', 'variables', 'Time', 'Name')
|
||
4 years ago
|
self.assertRaises(RuntimeError, SamplePath, importer)
|
||
|
|
||
|
def test_init_not_filled_dataframse(self):
|
||
4 years ago
|
importer = JsonImporter(self.read_files[2], 'samples', 'dyn.str', 'variables', 'Time', 'Name')
|
||
4 years ago
|
importer.import_data(0)
|
||
|
importer.clear_concatenated_frame()
|
||
|
self.assertRaises(RuntimeError, SamplePath, importer)
|
||
4 years ago
|
|
||
4 years ago
|
def test_init(self):
|
||
4 years ago
|
importer = JsonImporter(self.read_files[2], 'samples', 'dyn.str', 'variables', 'Time', 'Name')
|
||
4 years ago
|
importer.import_data(0)
|
||
|
s1 = SamplePath(importer)
|
||
|
self.assertIsNone(s1.trajectories)
|
||
|
self.assertIsNone(s1.structure)
|
||
|
self.assertFalse(s1._importer.concatenated_samples.empty)
|
||
|
self.assertIsNone(s1._total_variables_count)
|
||
|
|
||
|
def test_build_trajectories(self):
|
||
4 years ago
|
importer = JsonImporter(self.read_files[2], 'samples', 'dyn.str', 'variables', 'Time', 'Name')
|
||
4 years ago
|
importer.import_data(0)
|
||
|
s1 = SamplePath(importer)
|
||
4 years ago
|
s1.build_trajectories()
|
||
4 years ago
|
self.assertIsInstance(s1.trajectories, Trajectory)
|
||
|
|
||
|
def test_build_structure(self):
|
||
4 years ago
|
importer = JsonImporter(self.read_files[2], 'samples', 'dyn.str', 'variables', 'Time', 'Name')
|
||
4 years ago
|
importer.import_data(0)
|
||
|
s1 = SamplePath(importer)
|
||
4 years ago
|
s1.build_structure()
|
||
4 years ago
|
self.assertIsInstance(s1.structure, Structure)
|
||
|
self.assertEqual(s1._total_variables_count, len(s1._importer.sorter))
|
||
|
|
||
|
def test_build_structure_bad_sorter(self):
|
||
4 years ago
|
importer = JsonImporter(self.read_files[2], 'samples', 'dyn.str', 'variables', 'Time', 'Name')
|
||
4 years ago
|
importer.import_data(0)
|
||
|
s1 = SamplePath(importer)
|
||
4 years ago
|
importer._sorter[0],importer._sorter[1]= importer._sorter[1],importer._sorter[0]
|
||
|
|
||
4 years ago
|
self.assertRaises(RuntimeError, s1.build_structure)
|
||
|
|
||
|
def test_build_saplepath_no_prior_net_structure(self):
|
||
4 years ago
|
importer = JsonImporter(self.read_files[2], 'samples', 'dyn.str', 'variables', 'Time', 'Name')
|
||
4 years ago
|
importer.import_data(0)
|
||
|
importer._df_structure = None
|
||
|
s1 = SamplePath(importer)
|
||
|
s1.build_trajectories()
|
||
|
s1.build_structure()
|
||
|
self.assertFalse(s1.structure.edges)
|
||
|
|
||
4 years ago
|
def test_buid_samplepath_no_variables(self):
|
||
4 years ago
|
importer = JsonImporter(self.read_files[2], 'samples', 'dyn.str', 'variables', 'Time', 'Name')
|
||
4 years ago
|
importer.import_data(0)
|
||
|
importer._df_variables = None
|
||
|
self.assertRaises(RuntimeError, SamplePath, importer)
|
||
4 years ago
|
|
||
4 years ago
|
def test_buid_samplepath_no_concatenated_samples(self):
|
||
4 years ago
|
importer = JsonImporter(self.read_files[2], 'samples', 'dyn.str', 'variables', 'Time', 'Name')
|
||
4 years ago
|
importer.import_data(0)
|
||
|
importer._concatenated_samples = None
|
||
|
self.assertRaises(RuntimeError, SamplePath, importer)
|
||
4 years ago
|
|
||
|
if __name__ == '__main__':
|
||
|
unittest.main()
|