[docs]defmedian_heuristic(x:Union[Shaped[Array," n d"],Shaped[Array," n"],Shaped[Array,""],float,int],)->Shaped[Array,""]:""" Compute the median heuristic for setting kernel bandwidth. Analysis of the performance of the median heuristic can be found in :cite:`garreau2018median`. :param x: Input array of vectors :return: Bandwidth parameter, computed from the median heuristic, as a zero-dimensional array """# Format inputsx=_atleast_2d_consistent(x)# Calculate square distances as an upper triangular matrixsquare_distances=jnp.triu(pairwise(squared_distance)(x,x),k=1)# Calculate the median of the square distancesmedian_square_distance=jnp.median(square_distances[jnp.triu_indices_from(square_distances,k=1)])returnjnp.sqrt(median_square_distance/2.0)