@@ -16,23 +16,24 @@ def test__make_boot_index():
16
16
@pytest .fixture
17
17
def plot_data ():
18
18
data = numpy .array ([
19
- 3.113 , 3.606 , 4.046 , 4.046 , 4.710 , 6.140 , 6.978 ,
20
- 2.000 , 4.200 , 4.620 , 5.570 , 5.660 , 5.860 , 6.650 ,
21
- 6.780 , 6.790 , 7.500 , 7.500 , 7.500 , 8.630 , 8.710 ,
22
- 8.990 , 9.850 , 10.820 , 11.250 , 11.250 , 12.200 , 14.920 ,
23
- 16.770 , 17.810 , 19.160 , 19.190 , 19.640 , 20.180 , 22.970 ,
19
+ 3.113 , 3.606 , 4.046 , 4.046 , 4.710 , 6.140 , 6.978 ,
20
+ 2.000 , 4.200 , 4.620 , 5.570 , 5.660 , 5.860 , 6.650 ,
21
+ 6.780 , 6.790 , 7.500 , 7.500 , 7.500 , 8.630 , 8.710 ,
22
+ 8.990 , 9.850 , 10.820 , 11.250 , 11.250 , 12.200 , 14.920 ,
23
+ 16.770 , 17.810 , 19.160 , 19.190 , 19.640 , 20.180 , 22.970 ,
24
24
])
25
25
return data
26
26
27
27
28
28
@pytest .mark .parametrize (('fitlogs' , 'known_yhat' ), [
29
29
(None , numpy .array ([0.7887 , 3.8946 , 7.0005 , 10.1065 , 13.2124 , 16.3183 ])),
30
30
('x' , numpy .array ([0.2711 , 1.2784 , 1.5988 , 1.7953 , 1.9373 , 2.0487 ])),
31
- ('y' , numpy .array ([2.2006e+00 , 4.9139e+01 , 1.0972e+03 , 2.4501e+04 , 5.4711e+05 , 1.2217e+07 ])),
31
+ ('y' , numpy .array ([2.2006e+00 , 4.9139e+01 , 1.0972e+03 ,
32
+ 2.4501e+04 , 5.4711e+05 , 1.2217e+07 ])),
32
33
('both' , numpy .array ([1.3114 , 3.5908 , 4.9472 , 6.0211 , 6.9402 , 7.7577 ])),
33
34
])
34
35
def test__fit_simple (plot_data , fitlogs , known_yhat ):
35
- x = numpy .arange (1 , len (plot_data )+ 1 )
36
+ x = numpy .arange (1 , len (plot_data ) + 1 )
36
37
known_results = {'slope' : 0.5177 , 'intercept' : 0.2711 }
37
38
xhat = x [::6 ]
38
39
yhat , results = algo ._fit_simple (x , plot_data , xhat , fitlogs = fitlogs )
@@ -43,19 +44,22 @@ def test__fit_simple(plot_data, fitlogs, known_yhat):
43
44
44
45
@pytest .mark .parametrize (('fitlogs' , 'known_lo' , 'known_hi' ), [
45
46
(None , numpy .array ([- 0.7944 , 2.7051 , 6.1974 , 9.2612 , 11.9382 , 14.4290 ]),
46
- numpy .array ([ 2.1447 , 4.8360 , 7.7140 , 10.8646 , 14.1014 , 17.4432 ])),
47
+ numpy .array ([2.1447 , 4.8360 , 7.7140 , 10.8646 , 14.1014 , 17.4432 ])),
47
48
('x' , numpy .array ([- 1.4098 , - 0.2210 , 0.1387 , 0.3585 , 0.5147 , 0.6417 ]),
48
- numpy .array ([ 1.7067 , 2.5661 , 2.8468 , 3.0169 , 3.1400 , 3.2341 ])),
49
- ('y' , numpy .array ([4.5187e-01 , 1.4956e+01 , 4.9145e+02 , 1.0522e+04 , 1.5299e+05 , 1.8468e+06 ]),
50
- numpy .array ([8.5396e+00 , 1.2596e+02 , 2.2396e+03 , 5.2290e+04 , 1.3310e+06 , 3.7627e+07 ])),
51
- ('both' , numpy .array ([0.2442 , 0.8017 , 1.1488 , 1.4312 , 1.6731 , 1.8997 ]),
52
- numpy .array ([5.5107 , 13.0148 , 17.232 , 20.4285 , 23.1035 , 25.3843 ])),
49
+ numpy .array ([1.7067 , 2.5661 , 2.8468 , 3.0169 , 3.1400 , 3.2341 ])),
50
+ ('y' , numpy .array ([4.5187e-01 , 1.4956e+01 , 4.9145e+02 ,
51
+ 1.0522e+04 , 1.5299e+05 , 1.8468e+06 ]),
52
+ numpy .array ([8.5396e+00 , 1.2596e+02 , 2.2396e+03 ,
53
+ 5.2290e+04 , 1.3310e+06 , 3.7627e+07 ])),
54
+ ('both' , numpy .array ([0.2442 , 0.8017 , 1.1488 , 1.4312 , 1.6731 , 1.8997 ]),
55
+ numpy .array ([5.5107 , 13.0148 , 17.232 , 20.4285 , 23.1035 , 25.3843 ])),
53
56
])
54
57
def test__bs_fit (plot_data , fitlogs , known_lo , known_hi ):
55
58
numpy .random .seed (0 )
56
- x = numpy .arange (1 , len (plot_data )+ 1 )
59
+ x = numpy .arange (1 , len (plot_data ) + 1 )
57
60
xhat = x [::6 ]
58
- yhat_lo , yhat_hi = algo ._bs_fit (x , plot_data , xhat , fitlogs = fitlogs , niter = 1000 )
61
+ yhat_lo , yhat_hi = algo ._bs_fit (x , plot_data , xhat ,
62
+ fitlogs = fitlogs , niter = 1000 )
59
63
60
64
nptest .assert_allclose (yhat_lo , known_lo , rtol = 0.001 )
61
65
nptest .assert_allclose (yhat_hi , known_hi , rtol = 0.001 )
@@ -68,58 +72,57 @@ def setup(self):
68
72
self .intercept = 3.5
69
73
70
74
self .known_ylinlin = numpy .array ([
71
- 5.5 , 6.5 , 7.5 , 8.5 , 9.5 , 10.5 , 11.5 , 12.5 , 13.5 ,
72
- 14.5 , 15.5 , 16.5 , 17.5 , 18.5 , 19.5 , 20.5 , 21.5 , 22.5 ,
73
- 23.5 , 24.5
75
+ 5.5 , 6.5 , 7.5 , 8.5 , 9.5 , 10.5 , 11.5 , 12.5 , 13.5 ,
76
+ 14.5 , 15.5 , 16.5 , 17.5 , 18.5 , 19.5 , 20.5 , 21.5 , 22.5 ,
77
+ 23.5 , 24.5
74
78
])
75
79
76
-
77
80
self .known_yloglin = numpy .array ([
78
- 3.5 , 4.31093022 , 4.88629436 , 5.33258146 , 5.69722458 ,
79
- 6.00552594 , 6.27258872 , 6.50815479 , 6.71887582 , 6.90949618 ,
80
- 7.08351894 , 7.24360435 , 7.3918203 , 7.52980604 , 7.65888308 ,
81
- 7.78013233 , 7.89444915 , 8.0025836 , 8.10517019 , 8.20275051
81
+ 3.50000000 , 4.31093022 , 4.88629436 , 5.33258146 , 5.69722458 ,
82
+ 6.00552594 , 6.27258872 , 6.50815479 , 6.71887582 , 6.90949618 ,
83
+ 7.08351894 , 7.24360435 , 7.39182030 , 7.52980604 , 7.65888308 ,
84
+ 7.78013233 , 7.89444915 , 8.00258360 , 8.10517019 , 8.20275051
82
85
])
83
86
84
87
self .known_yloglog = numpy .array ([
85
- 33.11545196 , 74.50976691 , 132.46180783 , 206.97157474 ,
86
- 298.03906763 , 405.66428649 , 529.84723134 , 670.58790216 ,
87
- 827.88629897 , 1001.74242175 , 1192.15627051 , 1399.12784525 ,
88
- 1622.65714598 , 1862.74417268 , 2119.38892536 , 2392.59140402 ,
89
- 2682.35160865 , 2988.66953927 , 3311.54519587 , 3650.97857845
88
+ 33.11545196 , 74.50976691 , 132.46180783 , 206.97157474 ,
89
+ 298.03906763 , 405.66428649 , 529.84723134 , 670.58790216 ,
90
+ 827.88629897 , 1001.74242175 , 1192.15627051 , 1399.12784525 ,
91
+ 1622.65714598 , 1862.74417268 , 2119.38892536 , 2392.59140402 ,
92
+ 2682.35160865 , 2988.66953927 , 3311.54519587 , 3650.97857845
90
93
])
91
94
92
95
self .known_ylinlog = numpy .array ([
93
- 2.44691932e+02 , 6.65141633e+02 , 1.80804241e+03 ,
94
- 4.91476884e+03 , 1.33597268e+04 , 3.63155027e+04 ,
95
- 9.87157710e+04 , 2.68337287e+05 , 7.29416370e+05 ,
96
- 1.98275926e+06 , 5.38969848e+06 , 1.46507194e+07 ,
97
- 3.98247844e+07 , 1.08254988e+08 , 2.94267566e+08 ,
98
- 7.99902177e+08 , 2.17435955e+09 , 5.91052206e+09 ,
99
- 1.60664647e+10 , 4.36731791e+10
100
- ])
96
+ 2.44691932e+02 , 6.65141633e+02 , 1.80804241e+03 ,
97
+ 4.91476884e+03 , 1.33597268e+04 , 3.63155027e+04 ,
98
+ 9.87157710e+04 , 2.68337287e+05 , 7.29416370e+05 ,
99
+ 1.98275926e+06 , 5.38969848e+06 , 1.46507194e+07 ,
100
+ 3.98247844e+07 , 1.08254988e+08 , 2.94267566e+08 ,
101
+ 7.99902177e+08 , 2.17435955e+09 , 5.91052206e+09 ,
102
+ 1.60664647e+10 , 4.36731791e+10
103
+ ])
101
104
102
105
def test_linlin (self ):
103
106
ylinlin = algo ._estimate_from_fit (self .x , self .slope , self .intercept ,
104
- xlog = False , ylog = False )
107
+ xlog = False , ylog = False )
105
108
nptest .assert_array_almost_equal (ylinlin , self .known_ylinlin )
106
109
107
110
def test_loglin (self ):
108
111
yloglin = algo ._estimate_from_fit (self .x , self .slope , self .intercept ,
109
- xlog = True , ylog = False )
112
+ xlog = True , ylog = False )
110
113
nptest .assert_array_almost_equal (yloglin , self .known_yloglin )
111
114
112
115
def test_loglog (self ):
113
116
yloglog = algo ._estimate_from_fit (self .x , self .slope , self .intercept ,
114
- xlog = True , ylog = True )
117
+ xlog = True , ylog = True )
115
118
nptest .assert_array_almost_equal (yloglog , self .known_yloglog )
116
119
117
120
def test_linlog (self ):
118
121
ylinlog = algo ._estimate_from_fit (self .x , self .slope , self .intercept ,
119
- xlog = False , ylog = True )
120
- percent_diff = numpy .abs (ylinlog - self .known_ylinlog ) / self .known_ylinlog
122
+ xlog = False , ylog = True )
123
+ diff = numpy .abs (ylinlog - self .known_ylinlog ) / self .known_ylinlog
121
124
nptest .assert_array_almost_equal (
122
- percent_diff ,
125
+ diff ,
123
126
numpy .zeros (self .x .shape [0 ]),
124
127
decimal = 5
125
128
)
0 commit comments