distributions-normal-pdf
Version:
Normal distribution probability density function (PDF)
38 lines (29 loc) • 844 B
JavaScript
;
// MODULES //
var partial = require( './partial.js' );
// PDF //
/**
* FUNCTION: pdf( out, matrix, mu, sigma )
* Evaluates the probability density function (PDF) for a Normal distribution with mean `mu` and standard deviation `sigma` for each matrix element.
*
* @param {Matrix} out - output matrix
* @param {Matrix} arr - input matrix
* @param {Number} mu - mean
* @param {Number} sigma - standard deviation
* @returns {Matrix} output matrix
*/
function pdf( y, x, mu, sigma ) {
var len = x.length,
fcn,
i;
if ( y.length !== len ) {
throw new Error( 'pdf()::invalid input arguments. Input and output matrices must be the same length.' );
}
fcn = partial( mu, sigma );
for ( i = 0; i < len; i++ ) {
y.data[ i ] = fcn( x.data[ i ] );
}
return y;
} // end FUNCTION pdf()
// EXPORTS //
module.exports = pdf;