1
0
Fork 0
master
Pietro 4 years ago
parent df42c4f5c7
commit e000967852
  1. 1
      PyCTBN/PyCTBN/structure_graph/trajectory_generator.py
  2. 11
      PyCTBN/tests/structure_graph/test_trajectorygenerator.py
  3. 33
      test_trajectorygenerator.py

@ -33,7 +33,6 @@ class TrajectoryGenerator(object):
self._cims[v] = sof
def CTBN_Sample(self, t_end):
#Replace v_values with sigma (pandas dataframe)
t = 0
sigma = pd.DataFrame(columns = (["Time"] + self._vnames))
sigma.loc[len(sigma)] = [0] + [0 for v in self._vnames]

@ -0,0 +1,11 @@
import unittest
from ...PyCTBN.structure_graph.trajectory_generator import TrajectoryGenerator
class TestTrajectoryGenerator(unittest.TestCase)
@classmethod
def setUpClass(cls) -> None:
if __name__ == '__main__':
unittest.main()

@ -0,0 +1,33 @@
import unittest
import random
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)
self.assertLessEqual(sigma.loc[len(sigma) - 1].at["Time"], end_time)
for index, row in sigma.iterrows():
if index > 0:
self.assertLess(sigma.loc[index - 1].at["Time"], row.at["Time"])
diff = abs(sum(sigma.loc[index - 1, sigma.columns != "Time"]) -
sum(sigma.loc[index, sigma.columns != "Time"]))
self.assertEqual(diff, 1)
unittest.main()