forked from notani/python-glad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gladtest.py
62 lines (51 loc) · 2.04 KB
/
gladtest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import logging
import numpy as np
import unittest
import glad
verbose = False
debug = True
logger = None
class TestGLAD(unittest.TestCase):
def setUp(self):
self.data = glad.load_data('./data/data.txt')
def test_EM(self):
self.data.alpha = self.data.priorAlpha.copy()
self.data.beta = self.data.priorBeta.copy()
glad.EStep(self.data)
np.testing.assert_allclose(self.data.probZ[:5, 1],
[1.000000,1.000000,0.000000,0.000000,0.000000],
atol=1e-3)
np.testing.assert_allclose(self.data.probZ[:5, 0],
[0.000000,0.000000,1.000000,1.000000,1.000000],
atol=1e-3)
Q = glad.computeQ(self.data)
np.testing.assert_allclose(Q, -15490.194235, atol=1e-3)
dQdAlpha, dQdBeta = glad.gradientQ(self.data)
np.testing.assert_allclose(dQdAlpha[:5],
[-623.990996,-621.437809,-526.274895,-556.247219,-553.387000],
atol=1e-3)
np.testing.assert_allclose(dQdBeta[:5],
[-4.789440,-4.789440,-10.226004,-4.789440,-2.071159],
atol=1e-3)
def init_logger():
global logger
logger = logging.getLogger('GLADTest')
logger.setLevel(logging.DEBUG)
log_fmt = '%(asctime)s/%(name)s[%(levelname)s]: %(message)s'
logging.basicConfig(format=log_fmt)
glad.init_logger()
if __name__ == '__main__':
init_logger()
parser = argparse.ArgumentParser()
# parser.add_argument('filename')
parser.add_argument('-v', '--verbose', action='store_true', default=False)
parser.add_argument('-d', '--debug', action='store_true', default=False)
args = parser.parse_args()
logger.info('Start Unit Test')
unittest.main()
suite = unittest.TestLoader().loadTestsFromTestCase(TestGLAD)
unittest.TextTestRunner(verbosity=2).run(suite)
exit(0)