tests/kde.test.js
/**
 * @param kernel The kernel function
 * @param h Kernel smoothing parameter (bandwidth)
 * 
 * @returns The kernel density estimation of the given
 * sample at the given location
 */
@param kernel The kernel function
@param h Kernel smoothing parameter (bandwidth)

@returns The kernel density estimation of the given
sample at the given location
@param kernel The kernel function @param h Kernel smoothing parameter ( bandwidth ) @returns The kernel density estimation of the given sample at the given location
function kde(kernel, sample, h, x) {
    const n = sample.length;
    const hNorm = 1 / h;
    const kNorm = 1 / (n * h);
    let sum = 0;
    for (let i = 0; i < n; i++) {
        sum += kNorm * kernel(hNorm * (sample[i] - x));
    }
    return sum;
}
function kde ( kernel , sample , h , x ) { const n = sample . length ; const hNorm = 1 / h ; const kNorm = 1 / ( n * h ) ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += kNorm * kernel ( hNorm * ( sample [ i ] - x ) ) ; } return sum ; }
@param kernel The kernel function
 @param h Kernel smoothing parameter (bandwidth)
@param kernel The kernel function @param h Kernel smoothing parameter ( bandwidth )