-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_polymoment.py
112 lines (97 loc) · 3.4 KB
/
test_polymoment.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from polymoment import PolyMoment
def test_gaussian_distribution():
"""Test Gaussian distribution"""
polymoment = PolyMoment(
poly='x0',
dist={
'x0': {
'distribution': 'normal',
'type': 'symmetrical',
'translation': 'm0',
'scale': 's0'
}
}
)
# mean, var, skew, kurt
assert polymoment.mean().__str__() == 'm0'
assert polymoment.var().__str__() == 's0**2'
assert polymoment.skew().__str__() == '0'
assert polymoment.kurt().__str__() == '3'
def test_laplace_distribution():
"""Test Laplace distribution"""
polymoment = PolyMoment(
poly='x0',
dist={
'x0': {
'distribution': 'laplace',
'type': 'symmetrical',
'translation': 'm0',
'scale': 's0'
}
}
)
# mean, var, skew, kurt
assert polymoment.mean().__str__() == 'm0'
assert polymoment.var().__str__() == '2*s0**2'
assert polymoment.skew().__str__() == '0'
assert polymoment.kurt().__str__() == '6'
def test_weibull_distribution():
"""Test Weibull distribution"""
polymoment = PolyMoment(
poly='x0',
dist={
'x0': {
'distribution': 'weibull',
'type': 'one_sided_right',
'translation': 'm0',
'scale': 's0',
'beta1': 'b0',
}
}
)
# mean, var, skew, kurt
assert polymoment.mean().__str__() == 'm0 + s0*gamma(1 + 1/b0)'
assert polymoment.var().__str__() == 's0**2*(-gamma(1 + 1/b0)**2 + gamma(1 + 2/b0))'
assert polymoment.skew().__str__() == '-s0*(2*gamma(1 + 1/b0)**3 - 3*gamma(1 + 1/b0)*gamma(1 + 2/b0) + gamma(1 + ' \
'3/b0))/(sqrt(-s0**2*(gamma(1 + 1/b0)**2 - gamma(1 + 2/b0)))*(gamma(1 + ' \
'1/b0)**2 - gamma(1 + 2/b0)))'
assert polymoment.kurt().__str__() == '(-3*gamma(1 + 1/b0)**4 + 6*gamma(1 + 1/b0)**2*gamma(1 + 2/b0) - 4*gamma(1 ' \
'+ 1/b0)*gamma(1 + 3/b0) + gamma(1 + 4/b0))/(gamma(1 + 1/b0)**2 - gamma(1 +' \
' 2/b0))**2'
def test_uniform_distribution():
"""Test uniform distribution"""
polymoment = PolyMoment(
poly='x0',
dist={
'x0': {
'distribution': 'uniform',
'type': 'one_sided_right',
'translation': 'm0',
'scale': 's0'
}
}
)
# mean, var, skew, kurt
assert polymoment.mean().__str__() == 'm0 + s0/2'
assert polymoment.var().__str__() == 's0**2/12'
assert polymoment.skew().__str__() == '0'
assert polymoment.kurt().__str__() == '9/5'
def test_gamma_distribution():
"""Test gamma distribution"""
polymoment = PolyMoment(
poly='x0',
dist={
'x0': {
'distribution': 'gamma',
'type': 'one_sided_right',
'translation': 'm0',
'scale': 's0',
'beta1': 'b0'
}
}
)
# mean, var, skew, kurt
assert polymoment.mean().__str__() == 'b0*s0 + m0'
assert polymoment.var().__str__() == 'b0*s0**2'
assert polymoment.skew().__str__() == '2*s0/sqrt(b0*s0**2)'
assert polymoment.kurt().__str__() == '3 + 6/b0'