radage.helper module

radage.helper.botev(x, n=None)[source]

Botev et al. bandwidth selection algorithm.

See Botev, Grotowski, and Kroese (2010) for details, in particular page 2932 doi: 10.1214/10-AOS799

Largely drawn from the MATLAB implementation by Botev, available at: http://web1.maths.unsw.edu.au/~zdravkobotev/php/kde_m.php

Parameters:
  • x (array_like) – Data for which to estimate the bandwidth.

  • n (int, optional) – Number of gridded coordinates, must be power of 2. If None, 1024. By default None.

Returns:

Bandwidth for the given data.

Return type:

float

radage.helper.epa_kern(u)[source]

Epanechnikov kernel function.

Parameters:

u (array_like) – Array of values at which to evaluate the kernel function.

Returns:

Values of the kernel function at the given points.

Return type:

array_like

radage.helper.gauss_kern(u)[source]

Gaussian kernel function.

Parameters:

u (array_like) – Array of values at which to evaluate the kernel function.

Returns:

Values of the kernel function at the given points.

Return type:

array_like

radage.helper.kde_base(x, x_eval, bw='adaptive', kernel='gauss', w=None, n_steps=1)[source]

Kernel density estimation.

If number of data are fewer than 30, use Scott’s rule for initial bandwidth estimation.

Parameters:
  • x (array_like) – Observed data points.

  • x_eval (array_like) – Points at which to evaluate the KDE.

  • bw (str or float, optional) – Bandwidth, by default ‘adaptive’. Valid strings are ‘adaptive’, ‘scott’, ‘botev’

  • kernel (str, optional) – Kernel function to use, by default ‘epa’. Valid strings are ‘epa’, ‘gauss’.

  • w (array-like, optional) – Observation weights, by default None. If None, all weights are set to 1. Must be the same length as x.

  • n_steps (int, optional) – Number of steps for adaptive bandwidth estimation, by default 1.

Returns:

f_hat – Kernel density estimate at the given points.

Return type:

array_like

radage.helper.patch_dict_validator(patch_dict, n)[source]

Validate patch_dict and returns list for styling of plotted patches.

Parameters:
  • patch_dict (dict or list) – If a dictionary, same style will be used for all patches. If a list of dictionaries, must have length equal to n, and each dictionary will be used for each patch.

  • n (int) – Number of patches to style

Returns:

patch_dict – validated list

Return type:

list