Optimal bandwidth#

To import the following functions:

from maddlib import optimal_bandwidth

Generate bandwidth search space#

optimal_bandwidth.generate_bandwidths(N)#

Return N relevant values of bandwidth.

Parameters:

N (int) – The number of relevant and distinct values of h.

Returns:

The bandwidth 1-d vector

Return type:

numpy.ndarray

Find the optimal bandwidth range#

optimal_bandwidth.calculate_std(y, start, end)#

Return the standard deviation in the index interval [start, end] of y..

Parameters:
  • y (List or np.ndarray of shape (n, 1)) – The list of data in which to calculate the standard deviation.

  • start (int) – The initial index.

  • end (int) – The final index.

Returns:

The standard deviation

Return type:

float

The optimal_bandwidth.find_stable_interval() depends on the previous one, optimal_bandwidth.calculate_std().

optimal_bandwidth.find_stable_interval(h_list, madd_list, n0=None, n1=None, min_interval_length=None, min_nb_points=50)#

Return the bandwidth interval within which the MADD results are stable.

Parameters:
  • h_list (List or np.ndarray of shape (n, 1)) – The list of bandwidth values.

  • madd_list (List or np.ndarray of shape (n, 1)) – The list of MADD results for each bandwidth values.

  • n0 (int) – The number of samples in the group 0.

  • n1 (int) – The number of samples in the group 1.

  • min_interval_length (float) – The minimum length for the bandwidth interval to consider.

  • min_nb_points (int) – The minimum number of points to consider in the bandwidth interval.

Returns:

Dictionary of the results

Return type:

dict

Display optimal bandwidth range#

optimal_bandwidth.plot_stable_interval(h_list, madd_list, show_stable=True, indexes=None, show_order=False, n0=None, n1=None, zoom='None', legend=True, ylim=None)#

Return a plot of MADD results according to the bandwidth.

Parameters:
  • h_list (List or np.ndarray of shape (n, 1)) – The list of bandwidth values.

  • madd_list (List or np.ndarray of shape (n, 1)) – The list of MADD results for each bandwidth values.

  • show_stable (boolean) – To show the stable interval or not.

  • indexes (tuple) – The indexes (initial, final) of the stable interval (to compute with find_stable_interval()).

  • show_order (boolean) – To show informational bandwidth values or not.

  • n0 (int) – The number of samples in the group 0.

  • n1 (int) – The number of samples in the group 1.

  • zoom (str or 2-tuple) – To specify some zoom options.

  • legend (boolean) – To show the legend or not.

  • ylim (2-tuple) – To specify the y-axis values to show.

Returns:

Plot

Return type:

matplotlib.figure.Figure