10
10
from scipy .linalg import norm
11
11
from sortedcontainers import SortedSet
12
12
13
+ import adaptive .learner .integrator_coeffs as coeff
13
14
from adaptive .learner .base_learner import BaseLearner
14
15
from adaptive .notebook_integration import ensure_holoviews
15
16
from adaptive .utils import cache_latest , restore
16
17
17
- from .integrator_coeffs import (
18
- T_left ,
19
- T_right ,
20
- V_inv ,
21
- Vcond ,
22
- alpha ,
23
- b_def ,
24
- eps ,
25
- gamma ,
26
- hint ,
27
- min_sep ,
28
- ndiv_max ,
29
- ns ,
30
- xi ,
31
- )
32
-
33
18
34
19
def _downdate (c , nans , depth ):
35
20
# This is algorithm 5 from the thesis of Pedro Gonnet.
36
- b = b_def [depth ].copy ()
37
- m = ns [depth ] - 1
21
+ b = coeff . b_def [depth ].copy ()
22
+ m = coeff . ns [depth ] - 1
38
23
for i in nans :
39
- b [m + 1 ] /= alpha [m ]
40
- xii = xi [depth ][i ]
41
- b [m ] = (b [m ] + xii * b [m + 1 ]) / alpha [m - 1 ]
24
+ b [m + 1 ] /= coeff . alpha [m ]
25
+ xii = coeff . xi [depth ][i ]
26
+ b [m ] = (b [m ] + xii * b [m + 1 ]) / coeff . alpha [m - 1 ]
42
27
for j in range (m - 1 , 0 , - 1 ):
43
- b [j ] = (b [j ] + xii * b [j + 1 ] - gamma [j + 1 ] * b [j + 2 ]) / alpha [j - 1 ]
28
+ b [j ] = (
29
+ b [j ] + xii * b [j + 1 ] - coeff .gamma [j + 1 ] * b [j + 2 ]
30
+ ) / coeff .alpha [j - 1 ]
44
31
b = b [1 :]
45
32
46
33
c [:m ] -= c [m ] / b [m ] * b [:m ]
@@ -62,7 +49,7 @@ def _zero_nans(fx):
62
49
def _calc_coeffs (fx , depth ):
63
50
"""Caution: this function modifies fx."""
64
51
nans = _zero_nans (fx )
65
- c_new = V_inv [depth ] @ fx
52
+ c_new = coeff . V_inv [depth ] @ fx
66
53
if nans :
67
54
fx [nans ] = np .nan
68
55
c_new = _downdate (c_new , nans , depth )
@@ -168,11 +155,11 @@ def T(self):
168
155
left = self .a == self .parent .a
169
156
right = self .b == self .parent .b
170
157
assert left != right
171
- return T_left if left else T_right
158
+ return coeff . T_left if left else coeff . T_right
172
159
173
160
def refinement_complete (self , depth ):
174
161
"""The interval has all the y-values to calculate the intergral."""
175
- if len (self .data ) < ns [depth ]:
162
+ if len (self .data ) < coeff . ns [depth ]:
176
163
return False
177
164
return all (p in self .data for p in self .points (depth ))
178
165
@@ -181,7 +168,7 @@ def points(self, depth=None):
181
168
depth = self .depth
182
169
a = self .a
183
170
b = self .b
184
- return (a + b ) / 2 + (b - a ) * xi [depth ] / 2
171
+ return (a + b ) / 2 + (b - a ) * coeff . xi [depth ] / 2
185
172
186
173
def refine (self ):
187
174
self .depth += 1
@@ -234,7 +221,7 @@ def calc_ndiv(self):
234
221
div = self .parent .c00 and self .c00 / self .parent .c00 > 2
235
222
self .ndiv += div
236
223
237
- if self .ndiv > ndiv_max and 2 * self .ndiv > self .rdepth :
224
+ if self .ndiv > coeff . ndiv_max and 2 * self .ndiv > self .rdepth :
238
225
raise DivergentIntegralError
239
226
240
227
if div :
@@ -243,7 +230,7 @@ def calc_ndiv(self):
243
230
244
231
def update_ndiv_recursively (self ):
245
232
self .ndiv += 1
246
- if self .ndiv > ndiv_max and 2 * self .ndiv > self .rdepth :
233
+ if self .ndiv > coeff . ndiv_max and 2 * self .ndiv > self .rdepth :
247
234
raise DivergentIntegralError
248
235
249
236
for child in self .children :
@@ -276,21 +263,23 @@ def complete_process(self, depth):
276
263
if depth :
277
264
# Refine
278
265
c_diff = self .calc_err (c_old )
279
- force_split = c_diff > hint * norm (self .c )
266
+ force_split = c_diff > coeff . hint * norm (self .c )
280
267
else :
281
268
# Split
282
269
self .c00 = self .c [0 ]
283
270
284
271
if self .parent .depth_complete is not None :
285
- c_old = self .T [:, : ns [self .parent .depth_complete ]] @ self .parent .c
272
+ c_old = (
273
+ self .T [:, : coeff .ns [self .parent .depth_complete ]] @ self .parent .c
274
+ )
286
275
self .calc_err (c_old )
287
276
self .calc_ndiv ()
288
277
289
278
for child in self .children :
290
279
if child .depth_complete is not None :
291
280
child .calc_ndiv ()
292
281
if child .depth_complete == 0 :
293
- c_old = child .T [:, : ns [self .depth_complete ]] @ self .c
282
+ c_old = child .T [:, : coeff . ns [self .depth_complete ]] @ self .c
294
283
child .calc_err (c_old )
295
284
296
285
if self .done_leaves is not None and not len (self .done_leaves ):
@@ -320,7 +309,7 @@ def complete_process(self, depth):
320
309
ival .done_leaves -= old_leaves
321
310
ival = ival .parent
322
311
323
- remove = self .err < (abs (self .igral ) * eps * Vcond [depth ])
312
+ remove = self .err < (abs (self .igral ) * coeff . eps * coeff . Vcond [depth ])
324
313
325
314
return force_split , remove
326
315
@@ -496,8 +485,8 @@ def _fill_stack(self):
496
485
points = ival .points ()
497
486
498
487
if (
499
- points [1 ] - points [0 ] < points [0 ] * min_sep
500
- or points [- 1 ] - points [- 2 ] < points [- 2 ] * min_sep
488
+ points [1 ] - points [0 ] < points [0 ] * coeff . min_sep
489
+ or points [- 1 ] - points [- 2 ] < points [- 2 ] * coeff . min_sep
501
490
):
502
491
self .ivals .remove (ival )
503
492
elif ival .depth == 3 or force_split :
0 commit comments