UNPKG

distributions-cauchy-quantile

Version:
53 lines (44 loc) 1.2 kB
'use strict'; // MODULES // var deepSet = require( 'utils-deep-set' ).factory, deepGet = require( 'utils-deep-get' ).factory, partial = require( './partial.js' ); // QUANTILE // /** * FUNCTION: quantile( arr, x0, gamma, path[, sep] ) * Evaluates the quantile function for a Cauchy distribution with location parameter `x0` and scale parameter `gamma` for each array element and sets the input array. * * @param {Array} arr - input array * @param {Number} x0 - location parameter * @param {Number} gamma - scale parameter * @param {String} path - key path used when deep getting and setting * @param {String} [sep] - key path separator * @returns {Array} input array */ function quantile( x, x0, gamma, path, sep ) { var len = x.length, opts = {}, dget, dset, fcn, v, i; if ( arguments.length > 4 ) { opts.sep = sep; } if ( len ) { dget = deepGet( path, opts ); dset = deepSet( path, opts ); fcn = partial( x0, gamma ); for ( i = 0; i < len; i++ ) { v = dget( x[ i ] ); if ( typeof v === 'number' ) { dset( x[i], fcn( v ) ); } else { dset( x[i], NaN ); } } } return x; } // end FUNCTION quantile() // EXPORTS // module.exports = quantile;