Skip to content

auto_math_kernel_density_and_coherence_2

github-actions[bot] edited this page Nov 14, 2025 · 1 revision

Snippet from Math-Kernel-Density-and-Coherence.md

def silverman_bandwidth(X: np.ndarray) -> float:
    """
    Compute optimal bandwidth via Silverman's rule of thumb.
    
    Args:
        X: Data matrix (n x d).
    
    Returns:
        Optimal bandwidth h.
    """
    n, d = X.shape
    sigma = np.std(X, axis=0).mean()
    h = 1.06 * sigma * n ** (-1 / (d + 4))
    return h

# Example
traces = np.random.randn(100, 3)
h_opt = silverman_bandwidth(traces)
print(f"Optimal h = {h_opt:.3f}")

Clone this wiki locally