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.
83 lines
2.8 KiB
83 lines
2.8 KiB
4 years ago
|
import sys
|
||
4 years ago
|
sys.path.append("../../classes/")
|
||
4 years ago
|
import unittest
|
||
4 years ago
|
import numpy as np
|
||
4 years ago
|
import structure_graph.structure as st
|
||
4 years ago
|
|
||
|
|
||
|
class TestStructure(unittest.TestCase):
|
||
4 years ago
|
@classmethod
|
||
|
def setUpClass(cls):
|
||
|
cls.labels = ['X','Y','Z']
|
||
|
cls.indxs = np.array([0,1,2])
|
||
|
cls.vals = np.array([3,3,3])
|
||
|
cls.edges = [('X','Z'),('Y','Z'), ('Z','Y')]
|
||
|
cls.vars_numb = len(cls.labels)
|
||
4 years ago
|
|
||
|
def test_init(self):
|
||
4 years ago
|
s1 = st.Structure(self.labels, self.indxs, self.vals, self.edges, self.vars_numb)
|
||
|
self.assertListEqual(self.labels,s1.nodes_labels)
|
||
4 years ago
|
self.assertIsInstance(s1.nodes_indexes, np.ndarray)
|
||
4 years ago
|
self.assertTrue(np.array_equal(self.indxs, s1.nodes_indexes))
|
||
4 years ago
|
self.assertIsInstance(s1.nodes_values, np.ndarray)
|
||
4 years ago
|
self.assertTrue(np.array_equal(self.vals, s1.nodes_values))
|
||
|
self.assertListEqual(self.edges, s1.edges)
|
||
|
self.assertEqual(self.vars_numb, s1.total_variables_number)
|
||
4 years ago
|
|
||
|
def test_get_node_id(self):
|
||
4 years ago
|
s1 = st.Structure(self.labels, self.indxs, self.vals, self.edges, self.vars_numb)
|
||
|
for indx, var in enumerate(self.labels):
|
||
4 years ago
|
self.assertEqual(var, s1.get_node_id(indx))
|
||
|
|
||
|
def test_get_node_indx(self):
|
||
4 years ago
|
l2 = self.labels[:]
|
||
|
l2.remove('Y')
|
||
|
i2 = self.indxs.copy()
|
||
|
np.delete(i2, 1)
|
||
|
v2 = self.vals.copy()
|
||
|
np.delete(v2, 1)
|
||
|
e2 = [('X','Z')]
|
||
|
n2 = self.vars_numb - 1
|
||
|
s1 = st.Structure(l2, i2, v2, e2, n2)
|
||
|
for indx, var in zip(i2, l2):
|
||
4 years ago
|
self.assertEqual(indx, s1.get_node_indx(var))
|
||
|
|
||
4 years ago
|
def test_get_positional_node_indx(self):
|
||
4 years ago
|
l2 = self.labels[:]
|
||
|
l2.remove('Y')
|
||
|
i2 = self.indxs.copy()
|
||
|
np.delete(i2, 1)
|
||
|
v2 = self.vals.copy()
|
||
|
np.delete(v2, 1)
|
||
|
e2 = [('X', 'Z')]
|
||
|
n2 = self.vars_numb - 1
|
||
|
s1 = st.Structure(l2, i2, v2, e2, n2)
|
||
|
for indx, var in enumerate(s1.nodes_labels):
|
||
4 years ago
|
self.assertEqual(indx, s1.get_positional_node_indx(var))
|
||
|
|
||
4 years ago
|
def test_get_states_number(self):
|
||
4 years ago
|
l2 = self.labels[:]
|
||
|
l2.remove('Y')
|
||
|
i2 = self.indxs.copy()
|
||
|
np.delete(i2, 1)
|
||
|
v2 = self.vals.copy()
|
||
|
np.delete(v2, 1)
|
||
|
e2 = [('X', 'Z')]
|
||
|
n2 = self.vars_numb - 1
|
||
|
s1 = st.Structure(l2, i2, v2, e2, n2)
|
||
|
for val, node in zip(v2, l2):
|
||
|
self.assertEqual(val, s1.get_states_number(node))
|
||
4 years ago
|
|
||
4 years ago
|
def test_equality(self):
|
||
|
s1 = st.Structure(self.labels, self.indxs, self.vals, self.edges, self.vars_numb)
|
||
|
s2 = st.Structure(self.labels, self.indxs, self.vals, self.edges, self.vars_numb)
|
||
|
self.assertEqual(s1, s2)
|
||
|
|
||
|
def test_repr(self):
|
||
|
s1 = st.Structure(self.labels, self.indxs, self.vals, self.edges, self.vars_numb)
|
||
|
print(s1)
|
||
|
|
||
4 years ago
|
|
||
4 years ago
|
if __name__ == '__main__':
|
||
|
unittest.main()
|