tests/mle.test.js
/**
 * @returns the negative log likelihood of the given sample
 * for the normal distribution of the given mean and variance
 */
@returns the negative log likelihood of the given sample
for the normal distribution of the given mean and variance
@returns the negative log likelihood of the given sample for the normal distribution of the given mean and variance
function negLogL(xs, loc, scale) {
    const n = xs.length;
    const a = (n / 2) * Math.log(2 * Math.PI);
    const b = (n / 2) * Math.log(scale ** 2);
    const c = (1 / (2 * (scale ** 2)))
    let sum = 0;
    for (let i = 0; i < n; i++) {
        sum += (xs[i] - loc) ** 2;
    }
    return -a - b - (c * sum);
}
function negLogL ( xs , loc , scale ) { const n = xs . length ; const a = ( n / 2 ) * Math . log ( 2 * Math . PI ) ; const b = ( n / 2 ) * Math . log ( scale ** 2 ) ; const c = ( 1 / ( 2 * ( scale ** 2 ) ) ) let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += ( xs [ i ] - loc ) ** 2 ; } return - a - b - ( c * sum ) ; }
@returns the negative log likelihood of the given sample
 for the normal distribution of the given mean and variance
@returns the negative log likelihood of the given sample for the normal distribution of the given mean and variance