discretize_kernel: Create a "Discretized" Migration Function from a Continuous...

Description Usage Arguments Value

Description

Given a function kern(r) that gives per-individual migration rates and a resolution, returns the (approximate) function giving per-individual migration rates *per unit area* from squares of side length 'resolution' centered at distance r. (This depends on the direction the cell is in, but the result averages over directions.)

Usage

1
2
discretize_kernel(kern, res, radius, sigma = 1, fact = 10, sim = ((kern(1)
  == exp(-1/2)/(2 * pi)) && (fact > 10)))

Arguments

kern

The migration rate function.

res

The resolution of the grid.

radius

The maximum distance to extrapolate out to.

sigma

Distance scaling for kernel.

fact

The number of divisions of each grid cell side when approximating the integral.

sim

Whether to obtain the result by Monte Carlo integration (currently only implemented for the Gaussian kernel).

Value

A function as output by 'approxfun()', determined by numerical integration. If the required number of grid cells in the approximation is too large, falls back on Monte Carlo integration.

The result is designed to be used in migration_matrix, which scales input to the kernel by sigma and assumes that the kernel is a density function, so multiplies the value by the area of a cell; so the resulting function scales as a density function, and takes input in units of sigma.

For good results, the 'fine' grid used in numerical integration should be smaller than sigma; since the fine grid has a scale of res/fact, you should set fact >= 3 * res / sigma, say.


petrelharp/landsim documentation built on May 25, 2019, 2:53 a.m.