Beispiel #1
0
class TestAdjacentRegression(TestReferenceRegression):
    _eta = linalg.Vector([2.7, 4.])
    _canonical_link = glm.OrdinalLink(ratio='adjacent')
    _norm = 1 + math.exp(_eta[0] + _eta[1]) + math.exp(_eta[1])
    _mu = linalg.Vector([
        math.exp(_eta[0] + _eta[1]) / _norm,
        math.exp(_eta[1]) / _norm, 1 / _norm
    ])
    _categories = ['C', 'B', 'A']

    @classmethod
    def setUpClass(cls):
        """Test adjacent regression construction"""
        cls.predictor_init()
        oss = core.OrdinalSampleSpace(*cls._categories)
        cls._model = glm.OrdinalRegression(oss, cls._pred, cls._canonical_link)

    def test_conditional(self):
        """Test ordinal regression conditional operator"""
        response_distribution = self._model(*self._x)
        self.assertAlmostEqual(response_distribution.pdf('C'),
                               self._mu[0],
                               places=self._places)
        self.assertAlmostEqual(response_distribution.pdf('B'),
                               self._mu[1],
                               places=self._places)
        self.assertAlmostEqual(response_distribution.pdf('A'),
                               self._mu[2],
                               places=self._places)

    @classmethod
    def tearDownClass(cls):
        """Test adjacent regression deletion"""
        del cls._model
Beispiel #2
0
 def test_get_set_regression(self):
     """Test hierarchical regression get and set regression model"""
     model_root = self._model.get_regression("")
     model_root.predictor = self._pred
     model_root.link = glm.OrdinalLink(ratio='cumulative')
     self._model.set_regression("", model_root)
     model_B = self._model.get_regression("B")
     model_B.predictor = self._pred
     model_B.link = glm.NominalLink(ratio='reference')
     self._model.set_regression("B", model_B)
Beispiel #3
0
class TestSequentialRegression(TestAdjacentRegression):
    _eta = linalg.Vector([2.7, 4.])
    _canonical_link = glm.OrdinalLink(ratio='sequential')
    _norm = [1 + math.exp(_eta[0]), 1 + math.exp(_eta[1])]
    _mu = linalg.Vector([
        math.exp(_eta[0]) / _norm[0],
        math.exp(_eta[1]) / (_norm[0] * _norm[1]), 1 / (_norm[0] * _norm[1])
    ])
    _categories = ['C', 'B', 'A']

    @classmethod
    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)

    @classmethod
    def tearDownClass(cls):
        """Test cumulative regression deletion"""
        del cls._model
Beispiel #4
0
class TestCumulativeRegression(TestAdjacentRegression):
    _eta = linalg.Vector([2.7, 4.])
    _canonical_link = glm.OrdinalLink(ratio='cumulative')
    _norm = [1 + math.exp(_eta[0]), 1 + math.exp(_eta[1])]
    _mu = linalg.Vector([
        math.exp(_eta[0]) / _norm[0],
        math.exp(_eta[1]) / _norm[1] - math.exp(_eta[0]) / _norm[0],
        1 - math.exp(_eta[1]) / _norm[1]
    ])
    _categories = ['C', 'B', 'A']

    @classmethod
    def setUpClass(cls):
        """Test cumulative regression construction"""
        cls.predictor_init()
        cls._model = glm.OrdinalRegression(cls._categories, cls._pred,
                                           cls._canonical_link)

    @classmethod
    def tearDownClass(cls):
        """Test cumulative regression deletion"""
        del cls._model
Beispiel #5
0
 def setUpClass(cls):
     """Test Sequential logistic link construction"""
     cls._link = glm.OrdinalLink(ratio='sequential')      
Beispiel #6
0
 def setUpClass(cls):
     """Test Sequential FLink construction"""
     cls._link = glm.OrdinalLink(ratio='sequential', distribution=cls._dist)      
Beispiel #7
0
 def setUpClass(cls):
     """Test cumulative FLink construction"""
     cls._link = glm.OrdinalLink(ratio='cumulative', distribution=cls._dist)      
Beispiel #8
0
 def setUpClass(cls):
     """Test cumulative logistic link construction"""
     cls._link = glm.OrdinalLink(ratio='cumulative')      
Beispiel #9
0
 def setUpClass(cls):
     """Test adjacent FLink construction"""
     cls._link = glm.OrdinalLink(ratio='adjacent', distribution=cls._dist)      
Beispiel #10
0
 def setUpClass(cls):
     """Test adjacent logistic link construction"""
     cls._link = glm.OrdinalLink(ratio='adjacent')      
Beispiel #11
0
 def setUpClass(cls):
     """Test ordinal canonical link construction"""
     cls._link = glm.OrdinalLink()