@@ -16,23 +16,24 @@ def test__make_boot_index():
1616@pytest .fixture
1717def plot_data ():
1818 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 ,
2424 ])
2525 return data
2626
2727
2828@pytest .mark .parametrize (('fitlogs' , 'known_yhat' ), [
2929 (None , numpy .array ([0.7887 , 3.8946 , 7.0005 , 10.1065 , 13.2124 , 16.3183 ])),
3030 ('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 ])),
3233 ('both' , numpy .array ([1.3114 , 3.5908 , 4.9472 , 6.0211 , 6.9402 , 7.7577 ])),
3334])
3435def 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 )
3637 known_results = {'slope' : 0.5177 , 'intercept' : 0.2711 }
3738 xhat = x [::6 ]
3839 yhat , results = algo ._fit_simple (x , plot_data , xhat , fitlogs = fitlogs )
@@ -43,19 +44,22 @@ def test__fit_simple(plot_data, fitlogs, known_yhat):
4344
4445@pytest .mark .parametrize (('fitlogs' , 'known_lo' , 'known_hi' ), [
4546 (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 ])),
4748 ('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 ])),
5356])
5457def test__bs_fit (plot_data , fitlogs , known_lo , known_hi ):
5558 numpy .random .seed (0 )
56- x = numpy .arange (1 , len (plot_data )+ 1 )
59+ x = numpy .arange (1 , len (plot_data ) + 1 )
5760 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 )
5963
6064 nptest .assert_allclose (yhat_lo , known_lo , rtol = 0.001 )
6165 nptest .assert_allclose (yhat_hi , known_hi , rtol = 0.001 )
@@ -68,58 +72,57 @@ def setup(self):
6872 self .intercept = 3.5
6973
7074 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
7478 ])
7579
76-
7780 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
8285 ])
8386
8487 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
9093 ])
9194
9295 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+ ])
101104
102105 def test_linlin (self ):
103106 ylinlin = algo ._estimate_from_fit (self .x , self .slope , self .intercept ,
104- xlog = False , ylog = False )
107+ xlog = False , ylog = False )
105108 nptest .assert_array_almost_equal (ylinlin , self .known_ylinlin )
106109
107110 def test_loglin (self ):
108111 yloglin = algo ._estimate_from_fit (self .x , self .slope , self .intercept ,
109- xlog = True , ylog = False )
112+ xlog = True , ylog = False )
110113 nptest .assert_array_almost_equal (yloglin , self .known_yloglin )
111114
112115 def test_loglog (self ):
113116 yloglog = algo ._estimate_from_fit (self .x , self .slope , self .intercept ,
114- xlog = True , ylog = True )
117+ xlog = True , ylog = True )
115118 nptest .assert_array_almost_equal (yloglog , self .known_yloglog )
116119
117120 def test_linlog (self ):
118121 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
121124 nptest .assert_array_almost_equal (
122- percent_diff ,
125+ diff ,
123126 numpy .zeros (self .x .shape [0 ]),
124127 decimal = 5
125128 )
0 commit comments