Moments

JumpDiff.moments.moments(timeseries: numpy.ndarray, bw: float = None, bins: numpy.ndarray = None, power: int = 6, lag: list = [1], correction: bool = True, norm: bool = False, kernel: callable = None, tol: float = 1e-10, conv_method: str = 'auto', verbose: bool = False) → numpy.ndarray

Estimates the moments of the Kramers─Moyal expansion from a timeseries using a Nadaraya─Watson kernel estimator method. These later can be turned into the drift and diffusion coefficients after normalisation.

Parameters:
  • timeseries (np.ndarray) – A 1-dimensional timeseries.
  • bw (float) – Desired bandwidth of the kernel. A value of 1 occupies the full space of the bin space. Recommended are values 0.005 < bw < 0.4.
  • bins (np.ndarray (default None)) – The number of bins for each dimension, defaults to np.array([5000]). This is the underlying space for the Kramers─Moyal conditional moments.
  • power (int (default 6)) – Upper limit of the the Kramers─Moyal conditional moments to calculate. It will generate all Kramers─Moyal conditional moments up to power.
  • lag (list (default 1)) – Calculates the Kramers─Moyal conditional moments at each indicated lag, i.e., for timeseries[::lag[]]. Defaults to 1, the shortest timestep in the data.
  • corrections (bool (default True)) – Implements the second-order corrections of the Kramers─Moyal conditional moments directly
  • norm (bool (default False)) – Sets the normalisation. False returns the Kramers─Moyal conditional moments, and True returns the Kramers─Moyal coefficients.
  • kernel (callable (default None)) –

    Kernel used to convolute with the Kramers─Moyal conditional moments. To select example an Epanechnikov kernel use

    kernel = kernels.epanechnikov

    If None the Epanechnikov kernel will be used.

  • tol (float (default 1e-10)) – Round to zero absolute values smaller than tol, after convolutions.
  • conv_method (str (default auto)) – A string indicating which method to use to calculate the convolution. docs.scipy.org/doc/scipy/reference/generated/scipy.signal.convolve.
  • verbose (bool (default False)) – If True will report on the bandwidth used.
Returns:

  • edges (np.ndarray) – The bin edges with shape (D,bins.shape) of the calculated moments.
  • moments (np.ndarray) – The calculated moments from the Kramers─Moyal expansion of the timeseries at each lag. To extract the selected orders of the moments, use moments[i,:,j], with i the order according to powers, j the lag (if any given).

JumpDiff.moments.corrections(m, power)

The moments function will by default apply the corrections. You can turn the corrections off in that fuction by setting corrections = False.

Second-order corrections of the Kramers─Moyal coefficients (conditional moments), given by

\[\begin{split}F_1 &= M_1,\\ F_2 &= \frac{1}{2}\! \left(M_2-M_1^2\right ), \\ F_3 &= \frac{1}{6}\! \left( M_3-3M_1M_2+3M_1^3 \right ), \\ F_4 &= \frac{1}{24}\! \left(M_4-4M_1M_3+18M_1^2M_2-3M_2^2 -15M_1^4 \right) , \\ F_5 &= \frac{1}{120}\!\left(M_5 -5 M_1 M_4 +30 M_1^2 M_3 -150 M_1^3 M_2 +45 M_1 M_2^2-10 M_2 M_3 + 105 M_1^5 \right) \\ F_6 &= \frac{1} {720}\! \left (M_6 -6 M_1 M_5 + 45 M_1^2 M_4 -300 M_1^3 M_3 +1575 M_1^4 M_2-675 M_1^2 M_2^2 \right. \\ & \qquad \left . \ +180 M_1 M_2 M_3+45 M_2^3 -15 M_2 M_4-10 M_3^2 - 945 M_1^6\right ) \, ,\end{split}\]

with the prefactor the normalisation, i.e., the normalised results are the Kramers─Moyal coefficients. If norm is False, this results in the Kramers─Moyal conditional moments.

Parameters:
  • (moments) (m) – The calculated conditional moments from the Kramers─Moyal expansion of the at each lag. To extract the selected orders of the moments use moments[i,:,j], with i the order according to powers, j the lag.
  • power (int) – Upper limit of the Kramers─Moyal conditional moments to calculate. It will generate all Kramers─Moyal conditional moments up to power.
Returns:

F – The corrections of the calculated Kramers─Moyal conditional moments from the Kramers─Moyal expansion of the timeseries at each lag. To extract the selected orders of the moments, use F[i,:,j], with i the order according to powers, j the lag (if any introduced).

Return type:

np.ndarray