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/tests/structure_graph/test_networkgenerator.py

40 lines
1.6 KiB

#!/usr/bin/env python3
import unittest
import random
import numpy as np
3 years ago
from pyctbn.legacy.structure_graph.network_generator import NetworkGenerator
class TestNetworkGenerator(unittest.TestCase):
def test_generate_graph(self):
labels = ["U", "V", "W", "X", "Y", "Z"]
card = 3
vals = [card for l in labels]
ng = NetworkGenerator(labels, vals)
4 years ago
ng.generate_graph(0.3)
self.assertEqual(len(labels), len(ng.graph.nodes))
self.assertEqual(len([edge for edge in ng.graph.edges if edge[0] == edge[1]]), 0)
def test_generate_cims(self):
labels = ["U", "V", "W", "X", "Y", "Z"]
card = 3
vals = [card for l in labels]
cim_min = random.uniform(0.5, 5)
cim_max = random.uniform(0.5, 5) + cim_min
ng = NetworkGenerator(labels, vals)
4 years ago
ng.generate_graph(0.3)
ng.generate_cims(cim_min, cim_max)
self.assertEqual(len(ng.cims), len(labels))
self.assertListEqual(list(ng.cims.keys()), labels)
for key in ng.cims:
p_card = ng.graph.get_ordered_by_indx_set_of_parents(key)[2]
comb = ng.graph.build_p_comb_structure_for_a_node(p_card)
self.assertEqual(len(ng.cims[key].actual_cims), len(comb))
for cim in ng.cims[key].actual_cims:
self.assertEqual(sum(c > 0 for c in cim.cim.diagonal()), 0)
for i, row in enumerate(cim.cim):
3 years ago
# self.assertEqual(round(sum(row) - row[i], 8), round(-1 * row[i], 8))
self.assertEqual(sum(c < 0 for c in np.delete(cim.cim[i], i)), 0)
3 years ago
if __name__ == '__main__':
unittest.main()