-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmetropolis_hasting_tests.py
executable file
·38 lines (30 loc) · 1.4 KB
/
metropolis_hasting_tests.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
import unittest
from metropolis_hasting import MetropolisHasting1D
class MetropolisTest(unittest.TestCase):
""" Tests for the class MetropolisHasting1D """
def test_good_distrib(self):
"""Input a good sequence for MH initialization."""
distrib = [(3,1), (4,1), (6,3), (7,5), (12, 2), (17,1)]
MetropolisHasting1D(distrib, 2, burning_steps=10)
def test_duplicate_value_distrib(self):
"""Input a bad sequence with duplicate x value
Must raise an exception
"""
distrib = [(3,1), (4,1), (6,3), (7,5), (12, 2), (17,1), (17,2)]
with self.assertRaises(Exception):
MetropolisHasting1D(distrib, 2, burning_steps=10)
def test_unordered_value_distrib(self):
"""Input a bad sequence with unordered x values
Must raise an exception
"""
distrib = [(3,1), (4,1), (6,3), (7,5), (12, 2), (17,1), (4,2)]
with self.assertRaises(Exception):
MetropolisHasting1D(distrib, 2, burning_steps=10)
def test_model_distribution(self):
"""Init a distribution with steps with round values"""
distrib = [(3,1), (4,1), (6,3), (7,5), (12, 2), (17,1)]
metro = MetropolisHasting1D(distrib, 2, burning_steps=10)
self.assertEqual(metro.distribution,
[(3,1), (5,2), (7,5), (9, 3.8), (11,2.6), (13, 1.8), (15, 1.4), (17,1)])
if __name__ == '__main__':
unittest.main()