Ejemplo n.º 1
0
 def setUp(self):
     self.tests = [
         {
             'distribution':
             cd.PhaseType([[-1.0]], [1.0]),
             'like': [{
                 'alias': [
                     cd.HyperExp([1.0, 1.0], [0.5, 0.5]),
                     cd.HyperExp([1.0] * 4, [0.25] * 4),
                     cd.Exp(1.0),
                     cd.Erlang(1, 1.0)
                 ],
                 'functions': [
                     {
                         'name': 'mean'
                     },
                     {
                         'name': 'var'
                     },
                     {
                         'name': 'std'
                     },
                     {
                         'name': 'moment',
                         'grid': [1, 2, 3],
                         'vectorized': False
                     },
                     {
                         'name': 'pdf',
                         'grid': [0.0, 1.0, 2.0, numpy.inf]
                     },
                     {
                         'name': 'cdf',
                         'grid': [0.0, 1.0, 2.0, numpy.inf]
                     },
                 ]
             }],
             'properties': [
                 {
                     'name': 'S',
                     'value': [[-1.0]]
                 },
                 {
                     'name': 'subgenerator',
                     'value': [[-1.0]]
                 },
                 {
                     'name': 'pmf0',
                     'value': [1.0]
                 },
                 {
                     'name': 'order',
                     'value': 1
                 },
             ],
             'functions': [
                 # {'name': 'generate', 'args': (10000,), 'precision': 1,
                 #  'generator': True,
                 #  'calls': [
                 #      {'call': numpy.mean, 'as_function': 'mean'},
                 #      {'call': numpy.std, 'as_function': 'std'},
                 #      {'call': numpy.var, 'as_function': 'var'},
                 #  ]},
                 # {'name': 'sample', 'kwargs': {'shape': (20000,)},
                 #  'precision': 1, 'calls': [
                 #     {'call': numpy.mean, 'as_function': 'mean'},
                 #     {'call': numpy.std, 'as_function': 'std'},
                 #     {'call': lambda x: x.shape, 'as_value': (20000,)}
                 # ]},
                 # {'name': 'sample', 'kwargs': {'shape': (4, 1)},
                 #  'precision': 1, 'calls': [
                 #     {'call': lambda x: x.shape, 'as_value': (4, 1)}
                 # ]},
                 # {'name': 'sample', 'kwargs': {'shape': (3, 4, 5)},
                 #  'precision': 1, 'calls': [
                 #     {'call': lambda x: x.shape, 'as_value': (3, 4, 5)}
                 # ]},
             ],
         },
         {
             'distribution':
             cd.PhaseType([[-1.0, 1.0], [0.0, -1.0]], [1.0, 0]),
             'like': [{
                 'alias': [cd.Erlang(2, 1.0)],
                 'functions': [
                     {
                         'name': 'mean'
                     },
                     {
                         'name': 'var'
                     },
                     {
                         'name': 'std'
                     },
                     {
                         'name': 'moment',
                         'grid': [1, 2, 3],
                         'vectorized': False
                     },
                     {
                         'name': 'pdf',
                         'grid': [0.0, 1.0, 2.0, numpy.inf]
                     },
                     {
                         'name': 'cdf',
                         'grid': [0.0, 1.0, 2.0, numpy.inf]
                     },
                 ]
             }],
             'properties': [
                 {
                     'name': 'S',
                     'value': [[-1.0, 1.0], [0.0, -1.0]]
                 },
                 {
                     'name': 'subgenerator',
                     'value': [[-1.0, 1.0], [0.0, -1.0]]
                 },
                 {
                     'name': 'pmf0',
                     'value': [1.0, 0]
                 },
                 {
                     'name': 'order',
                     'value': 2
                 },
             ],
         },
     ]
Ejemplo n.º 2
0
 def test_fail_creation_with_zero_or_negative_rate(self):
     rates = [0.0, -1.0, -2.0, -numpy.inf]
     for rate in rates:
         with self.assertRaises(ValueError):
             cd.Erlang(shape=1, rate=rate)
Ejemplo n.º 3
0
 def test_fail_creation_wht_zero_or_negative_shape(self):
     shapes = [0, -1, -2, -numpy.inf]
     for shape in shapes:
         with self.assertRaises(ValueError):
             cd.Erlang(shape=shape, rate=1.0)
Ejemplo n.º 4
0
 def test_fail_creation_with_non_integer_shape(self):
     shapes = [1.5, 2.5, numpy.inf]
     for shape in shapes:
         with self.assertRaises(ValueError):
             cd.Erlang(shape=shape, rate=1.0)
Ejemplo n.º 5
0
 def setUp(self):
     self.tests = [{
         'distribution':
         cd.Erlang(shape=1, rate=1.0),
         'like': [{
             'alias': [cd.Exp(1.0)],
             'functions': [{
                 'name': 'mean'
             }, {
                 'name': 'var'
             }, {
                 'name': 'std'
             }, {
                 'name': 'moment',
                 'grid': [1, 2, 3]
             }, {
                 'name': 'pdf',
                 'grid': [0.0, 1.0, 2.0, numpy.inf]
             }, {
                 'name': 'cdf',
                 'grid': [0.0, 1.0, 2.0, numpy.inf]
             }]
         }],
         'properties': [{
             'name': 'shape',
             'value': 1
         }, {
             'name': 'rate',
             'value': 1.0
         }],
         'functions': [
             {
                 'name':
                 'generate',
                 'args': (25000, ),
                 'precision':
                 1,
                 'generator':
                 True,
                 'calls': [
                     {
                         'call': numpy.mean,
                         'as_function': 'mean'
                     },
                     {
                         'call': numpy.std,
                         'as_function': 'std'
                     },
                     {
                         'call': numpy.var,
                         'as_function': 'var'
                     },
                 ]
             },
             {
                 'name':
                 'sample',
                 'kwargs': {
                     'shape': (25000, )
                 },
                 'precision':
                 1,
                 'calls': [{
                     'call': numpy.mean,
                     'as_function': 'mean'
                 }, {
                     'call': numpy.std,
                     'as_function': 'std'
                 }, {
                     'call': lambda x: x.shape,
                     'as_value': (25000, )
                 }]
             },
             {
                 'name': 'sample',
                 'kwargs': {
                     'shape': (5, 1)
                 },
                 'precision': 1,
                 'calls': [{
                     'call': lambda x: x.shape,
                     'as_value': (5, 1)
                 }]
             },
             {
                 'name': 'sample',
                 'kwargs': {
                     'shape': (3, 4, 5)
                 },
                 'precision': 1,
                 'calls': [{
                     'call': lambda x: x.shape,
                     'as_value': (3, 4, 5)
                 }]
             },
         ]
     }, {
         'distribution':
         cd.Erlang(shape=1, rate=2.0),
         'like': [{
             'alias': [cd.Exp(2.0)],
             'functions': [
                 {
                     'name': 'mean'
                 },
                 {
                     'name': 'var'
                 },
                 {
                     'name': 'std'
                 },
                 {
                     'name': 'moment',
                     'grid': [1, 2, 3]
                 },
                 {
                     'name': 'pdf',
                     'grid': [0.0, 1.0, 2.0, numpy.inf]
                 },
                 {
                     'name': 'cdf',
                     'grid': [0.0, 1.0, 2.0, numpy.inf]
                 },
             ]
         }],
         'properties': [
             {
                 'name': 'shape',
                 'value': 1
             },
             {
                 'name': 'rate',
                 'value': 2.0
             },
         ]
     }, {
         'distribution':
         cd.Erlang(shape=2, rate=4.0),
         'properties': [
             {
                 'name': 'shape',
                 'value': 2
             },
             {
                 'name': 'rate',
                 'value': 4.0
             },
         ],
         'functions': [
             {
                 'name': 'mean',
                 'value': 0.5
             },
             {
                 'name': 'std',
                 'value': 0.125**0.5
             },
             {
                 'name': 'var',
                 'value': 0.125
             },
             {
                 'name': 'moment',
                 'grid': [(1, 0.5), (2, 0.375)]
             },
             {
                 'name':
                 'pdf',
                 'precision':
                 4,
                 'grid': [(0.0, 0.0), (1.0, 0.29305), (2.0, 0.01073),
                          (numpy.inf, 0)],
             },
             {
                 'name':
                 'cdf',
                 'precision':
                 4,
                 'grid': [(0.0, 0.0), (1.0, 0.90842), (2.0, 0.99698),
                          (numpy.inf, 1.0)]
             },
             {
                 'name':
                 'generate',
                 'args': (25000, ),
                 'precision':
                 1,
                 'generator':
                 True,
                 'calls': [
                     {
                         'call': numpy.mean,
                         'as_function': 'mean'
                     },
                     {
                         'call': numpy.std,
                         'as_function': 'std'
                     },
                     {
                         'call': numpy.var,
                         'as_function': 'var'
                     },
                 ]
             },
         ],
     }]