class TestHierarchicalSampleSpace(unittest.TestCase): _sample_space1 = core.OrdinalSampleSpace('C', 'B', 'A') _sample_space2 = core.NominalSampleSpace('Ba', 'Bb', 'Bc') _sample_space3 = core.NominalSampleSpace('Bca', 'Bcb') @classmethod def setUpClass(cls): """Test hierarchical sample space construction""" cls._space = core.HierarchicalSampleSpace(cls._sample_space1) def test_partition(self): """Test hierarchical sample space partition""" self.assertEqual( self._space.values, ['A', 'B', 'C']) # list of (lexicographically ordered) values self._space.partition('B', self._sample_space2) self.assertEqual( self._space.values, ['A', 'Ba', 'Bb', 'Bc', 'C' ]) # list of (lexicographically ordered) values after partition self._space.partition('Bc', self._sample_space3) self.assertEqual( self._space.values, ['A', 'Ba', 'Bb', 'Bca', 'Bcb', 'C' ]) # list of (lexicographically ordered) values after partition @classmethod def tearDownClass(cls): """Test hierarchical sample space deletion""" del cls._space
def setUpClass(cls): """Test multivariate data construction""" cls._data_ordinal = data.load('retinopathy') cls._data_hierarchical = data.load('retinopathy') sample_spaces = [] ss1 = core.NominalSampleSpace(['0', '12']) ss2 = core.NominalSampleSpace(['1', '2']) hss = core.HierarchicalSampleSpace(ss1) hss.partition('12', ss2) sample_spaces.append(hss) sample_spaces.append(core.controls.ZZ) for i in [0, 1, 2]: sample_spaces.append(core.controls.RR) cls._data_hierarchical.RET.sample_space = hss
class TestHierarchical(unittest.TestCase, AbstractTestUnivariateDistribution): _ordinal_space = core.OrdinalSampleSpace('C', 'B', 'A') _nominal_space = core.NominalSampleSpace('Ba', 'Bb', 'Bc') _hierarchical_space = core.HierarchicalSampleSpace(_ordinal_space) _hierarchical_space.partition('B', _nominal_space) _places = 10 @classmethod def setUpClass(cls): """Test hierarchical distribution construction""" cls._dist = core.HierarchicalDistribution(cls._hierarchical_space) def test_internal_ldf(self): """Test internal log pdf of hierarchical distribution""" self.assertAlmostEqual(self._dist.pdf('C'), float(1 / 3), places=self._places) self.assertAlmostEqual(self._dist.pdf('Ba'), float(1 / 9), places=self._places) self.assertAlmostEqual(self._dist.internal_pdf('B'), float(1 / 3), places=self._places) @classmethod def tearDownClass(cls): """Test hierarchical distribution deletion""" del cls._dist
def setUpClass(cls): """Test reference regression construction""" cls.predictor_init() nss = core.NominalSampleSpace(*cls._categories) cls._model = glm.NominalRegression(nss, cls._pred, cls._canonical_link)
def hierarchical_sample_space_init(cls): ordinal_space = core.OrdinalSampleSpace(*cls._categories_root) nominal_space = core.NominalSampleSpace(*cls._categories_B) cls._hss = core.HierarchicalSampleSpace(ordinal_space) cls._hss.partition('B', nominal_space)
def setUpClass(cls): """Test nominal sample space construction""" cls._space = core.NominalSampleSpace('C', 'B', 'A')