tests/kde.test.js
/**
 * A cost function for Maximum likelihood cross-validation
 * of a density estimate
 */
A cost function for Maximum likelihood cross-validation
of a density estimate
A cost function for Maximum likelihood cross - validation of a density estimate
function mlcv(kernel, sample, h) {
    const n = sample.length;
    const hNorm = 1 / h;
    let cvSum = 0;
    for (let i = 0; i < n; i++) {
        const xi = sample[i];
        let q = 0;
        for (let j = 0; j < n; j++) {
            q += kernel(hNorm * (sample[j] - xi));
        }
        cvSum += Math.log(q - kernel(0));
    }
    return (1 / n) * cvSum - Math.log((n - 1) * h);
}
function mlcv ( kernel , sample , h ) { const n = sample . length ; const hNorm = 1 / h ; let cvSum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { const xi = sample [ i ] ; let q = 0 ; for ( let j = 0 ; j < n ; j ++ ) { q += kernel ( hNorm * ( sample [ j ] - xi ) ) ; } cvSum += Math . log ( q - kernel ( 0 ) ) ; } return ( 1 / n ) * cvSum - Math . log ( ( n - 1 ) * h ) ; }
A cost function for Maximum likelihood cross-validation
 of a density estimate
A cost function for Maximum likelihood cross - validation of a density estimate