finitediff.grid package

Submodules

finitediff.grid.make module

finitediff.grid.make.adapted_grid(xstart, xstop, cb, grid_additions=(50, 50), **kwargs)[source]

” Creates an adapted (1D) grid by subsequent subgrid insertions.

Parameters:

xstart : float

xstop : float

cb : callbable

Function to be evaluated (note that noise is handled poorly).

grid_additions : iterable of ints (even numbers)

Sequence specifying how many gridpoints to add each time.

**kwargs : see refine_grid().

finitediff.grid.plotting module

finitediff.grid.plotting.plot_convergence(key, values, cb, metric=None, xstart=0, xstop=2, **kwargs)[source]

finitediff.grid.rebalance module

finitediff.grid.rebalance.combine_grids(grids, **kwargs)[source]

Combines multiple grids and prunes them using pre_pruning mask

Parameters:

grids : iterable of array_like grids

** : dict

Keyword arguments passed on to pre_pruning_mask

Returns:

Strictly increasing monotonic array

finitediff.grid.rebalance.grid_pruning_mask(grid, err, ndrop=None, protect_sparse=None, pow_err=2, pow_dx=2)[source]

Returns a mask for grid pruning.

Parameters:

grid : array

err : array

ndrop : int

If not provided taken as 25% of grid size (rounded upward).

protect_sparse : int

If not provided taken as 25% of grid size (rounded upward).

pow_err : number

Exponent of error in weighting.

pow_dx : number

Exponent of grid spacing in weighting.

finitediff.grid.rebalance.pre_pruning_mask(grid, rtol=1e-12, atol=0.0)[source]

Returns a mask for grid pruning.

Any grid spacing smaller than rtol*gridvalue + atol will be pruned. In general the value on the right is removed unless it is the last point in the grid.

Parameters:

grid : array

rtol : float

atol : float

Returns:

NumPy array of numpy.bool_ (to be used as mask).

finitediff.grid.rebalance.rebalanced_grid(grid, err, base=0.25, num=None, resolution_factor=10, smooth_fact=1.0)[source]

finitediff.grid.refine module

finitediff.grid.refine.refine_grid(grid, cb, grid_additions=(50, 50), ntrail=2, blurs=((), ()), metric=None, atol=None, rtol=None, extremum_refinement=None, snr=False)[source]

Refines an existing grid by adding points to it.

Parameters:

grid : array

cb : callbable

Function to be evaluated (note that noise is handled poorly).

grid_additions : iterable of ints (even numbers)

Sequence specifying how many gridpoints to add each time.

ntrail : int (>= 2)

Number of points to include in the look-ahead extrapolation.

blurs : pair of iterables of ints (of same length)

Blur fractions of absolute residuals to neighbors.

atol : float

Absolute tolerance to be fulfilled by all absolute residuals for early exit.

rtol : float

Relative tolerance to be fulfilled by all absolute residuals for early exit.

extremum_refinement : locator (callable), n (int), predicate (callable)

Between each grid addition a callable for locating the extremum (e.g. np.argmax) can be evaluated. The integer specifies how many gridpoints that should be inserted on each side (one side if on boundary) of the extremum.

snr : bool

Use signal-to-noise ratio the lower the grid-addition-weight of potential noise.

Returns:

(grid, errors)

finitediff.grid.util module

finitediff.grid.util.grid_error(grid, y, ntrail=2)[source]

Estimates error at each grid point from extrapolation.

Extrapolates from left (‘fw’) or from right (‘bw’).

Parameters:

grid : array

y : array

ntrail : int

Number of points to include in the look-ahead extrapolation.

finitediff.grid.util.locate_discontinuity(grid, y, consider, trnsfm=<function <lambda>>, ntrail=2)[source]
finitediff.grid.util.pool_discontinuity_approx(loc_res, consistency_criterion=10)[source]