Пример #1
0
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
Пример #2
0
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
Пример #3
0
 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)
Пример #4
0
 def setUpClass(cls):
     """Test cumulative regression construction"""
     cls.predictor_init()
     oss = core.OrdinalSampleSpace(*cls._categories)
     cls._model = glm.OrdinalRegression(oss, cls._pred, cls._canonical_link)
Пример #5
0
 def setUpClass(cls):
     """Test ordinal sample space construction"""
     cls._space = core.OrdinalSampleSpace('C', 'B', 'A')