1
0
Fork 0
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
PyCTBN/test_trajectorygenerator.py

41 lines
1.8 KiB

import unittest
import random
from PyCTBN.PyCTBN.structure_graph.trajectory import Trajectory
from PyCTBN.PyCTBN.structure_graph.trajectory_generator import TrajectoryGenerator
from PyCTBN.PyCTBN.utility.json_importer import JsonImporter
class TestTrajectoryGenerator(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.j1 = JsonImporter("./PyCTBN/test_data/networks_and_trajectories_binary_data_01_3.json", "samples", "dyn.str", "variables", "Time", "Name")
def test_init(self):
tg = TrajectoryGenerator(self.j1)
self.assertEqual(len(tg._vnames), len(self.j1.variables))
self.assertIsInstance(tg._vnames, list)
self.assertIsInstance(tg._parents, dict)
self.assertIsInstance(tg._cims, dict)
self.assertListEqual(list(tg._parents.keys()), tg._vnames)
self.assertListEqual(list(tg._cims.keys()), tg._vnames)
def test_generated_trajectory(self):
tg = TrajectoryGenerator(self.j1)
end_time = random.randint(5, 100)
sigma = tg.CTBN_Sample(end_time)
traj = Trajectory(self.j1.build_list_of_samples_array(sigma), len(self.j1.sorter) + 1)
self.assertLessEqual(traj.times[len(traj.times) - 1], end_time)
for index in range(len(traj.times)):
if index > 0:
self.assertLess(traj.times[index - 1], traj.times[index])
diff = abs(sum(traj.trajectory[index - 1]) - sum(traj.trajectory[index]))
self.assertEqual(diff, 1)
def test_generated_trajectory_max_tr(self):
tg = TrajectoryGenerator(self.j1)
n_tr = random.randint(5, 100)
sigma = tg.CTBN_Sample(max_tr = n_tr)
traj = Trajectory(self.j1.build_list_of_samples_array(sigma), len(self.j1.sorter) + 1)
self.assertEqual(len(traj.times), n_tr + 1)
unittest.main()