# Functions¶

Documentation for all the functions in kramersmoyal.

## Kramers—Moyal coefficients¶

kramersmoyal.kmc.km(timeseries: numpy.ndarray, bins: numpy.ndarray, powers: numpy.ndarray, kernel: callable = <function epanechnikov>, bw: float = None, tol: float = 1e-10, conv_method: str = 'auto') → numpy.ndarray

Estimates the Kramers─Moyal coefficients from a timeseries using a kernel estimator method. km can calculate the Kramers─Moyal coefficients for a timeseries of any dimension, up to any desired power.

Parameters: timeseries (np.ndarray) – The D-dimensional timeseries (N, D). The timeseries of length N and dimensions D. bins (np.ndarray) – The number of bins for each dimension. This is the underlying space for the Kramers-Moyal coefficients. In 1-dimension a choice as bins = np.array([6000]) is recommended. In 2-dimensions bins = np.array([300,300]) is recommended. powers (np.ndarray) – Powers for the operation of calculating the Kramers─Moyal coefficients, which need to match dimensions of the timeseries. In 1-dimension the first four Kramers-Moyal coefficients can be found via powers = np.array([0],[1],[2],[3],[4]). In 2 dimensions take into account each dimension, as powers = np.array([0,0],[0,1],[1,0],[1,1],[0,2],[2,0],[2,2], [0,3],[3,0],[3,3],[0,4],[4,0],[4,4]) 
kernel: callable (default epanechnikov)

Kernel used to convolute with the Kramers-Moyal coefficients. To select for example a Gaussian kernel use

kernel = kernels.gaussian
bw: float (default None)
Desired bandwidth of the kernel. A value of 1 occupies the full space of the bin space. Recommended are values 0.005 < bw < 0.5.
tol: float (default 1e-10)
Round to zero absolute values smaller than tol, after the convolutions.
conv_method: str (default auto)
A string indicating which method to use to calculate the convolution. https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.convolve.html
Returns: kmc (np.ndarray) – The calculated Kramers-Moyal coefficients in accordance to the timeseries dimensions in (D,bins.shape) shape. To extract the selected orders of the kmc, use kmc[i,…], with i the order according to powers edges (np.ndarray) – The bin edges with shape (D,bins.shape) of the calculated Kramers-Moyal coefficients

## Kernels¶

kramersmoyal.kernels.kernel(kernel_func)

Transforms a kernel function into a scaled kernel function (for a certain bandwidth bw)

Currently implemented kernels are:
Epanechnikov, Gaussian, Uniform, Triangular, Quartic

For a good overview of various kernels see https://en.wikipedia.org/wiki/Kernel_(statistics)

kramersmoyal.kernels.epanechnikov(x: numpy.ndarray, dims: int) → numpy.ndarray

The Epanechnikov kernel in dimensions dims.

kramersmoyal.kernels.gaussian(x: numpy.ndarray, dims: int) → numpy.ndarray

Gaussian kernel in dimensions dims.

kramersmoyal.kernels.uniform(x: numpy.ndarray, dims: int) → numpy.ndarray

Uniform, or rectangular kernel in dimensions dims.

kramersmoyal.kernels.triagular(x: numpy.ndarray, dims: int) → numpy.ndarray

Triagular kernel in dimensions dims.

kramersmoyal.kernels.quartic(x: numpy.ndarray, dims: int) → numpy.ndarray

Quartic, or biweight kernel in dimensions dims.

## Helping functions¶

### Binning function¶

The binning function has no documentation