def run_estimate_radius(data, dists, sample, d, rmin, rmax, ntry, run_parallel,<EOL>search_space='<STR_LIT>', rad_bw_ratio=<NUM_LIT>):
<EOL>global DIST<EOL>global X<EOL>dists = dists.tocsr()<EOL>dists.data[dists.data > rmax] = <NUM_LIT:0.0><EOL>dists.eliminate_zeros()<EOL>DIST = dists<EOL>X = data<EOL>n, dim = X.shape<EOL>t0 = time.time()<EOL>if run_parallel:<EOL><INDENT>ncpu = mp.cpu_count() <EOL>processes = int(min(ntry, ncpu))<EOL>print('<STR_LIT>' + str(processes) + '<STR_LIT>')<EOL>results = multi_process_radius_search(d, sample, rmin, rmax, ntry, processes, search_space, rad_bw_ratio)<EOL><DEDENT>else:<EOL><INDENT>results = radius_search(d, sample, rmin, rmax, ntry, search_space, rad_bw_ratio)<EOL><DEDENT>t1 = time.time()<EOL>print('<STR_LIT>' + str(t1 - t0) + '<STR_LIT>')<EOL>return(results)<EOL>
This function is used to estimate the bandwidth, h, of the Gaussian Kernel:
    exp(-||x_i - x_j||/h^2)


The "radius" refers to the truncation constant which we take to be
rad_bw_ratio * h and this is the parameter over which we will iterate.

We use the method of: https://arxiv.org/abs/1406.0118

Parameters
----------
data : numpy array,
    Original data set for which we are estimating the bandwidth
dists : scipy.csr_matrix,
    A CSR matrix containing pairwise distances from data up to rmax
sample : np.array,
    subset of data points over which to evaluate the radii
d : int,
    dimension over which to evaluate the radii (smaller usually better)
rmin : float,
    smallest radius ( = rad_bw_ratio * bandwidth) to consider
rmax : float,
    largest radius ( = rad_bw_ratio * bandwidth) to consider
ntry : int,
    number of radii between rmax and rmin to try
run_parallel : bool,
    whether to run the analysis in parallel over radii
search_space : str,
    either 'linspace' or 'logspace', choose to search in log or linear space
rad_bw_ratio : float,
    the ratio of radius and kernel bandwidth, default to be 3 (radius = 3*h)

Returns
-------
results : np.array (2d)
    first column is the set of radii and the second column is the distortion
    (smaller is better)