@stdlib/stats-incr-nanmaxabs
v0.1.1
Published
Compute a maximum absolute value incrementally, ignoring NaN values.
Downloads
29
Readme
incrnanmaxabs
Compute a maximum absolute value incrementally, ignoring
NaNvalues.
Installation
npm install @stdlib/stats-incr-nanmaxabsUsage
var incrnanmaxabs = require( '@stdlib/stats-incr-nanmaxabs' );incrnanmaxabs()
Returns an accumulator function which incrementally computes a maximum absolute value, ignoring NaN values.
var accumulator = incrnanmaxabs();accumulator( [x] )
If provided an input value x, the accumulator function returns an updated maximum absolute value. If not provided an input value x, the accumulator function returns the current maximum absolute value.
var accumulator = incrnanmaxabs();
var max = accumulator( 2.0 );
// returns 2.0
max = accumulator( 1.0 );
// returns 2.0
max = accumulator( NaN );
// returns 2.0
max = accumulator( -3.0 );
// returns 3.0
max = accumulator();
// returns 3.0Notes
- Input values are not type checked. If non-numeric inputs are possible, you are advised to type check and handle accordingly before passing the value to the accumulator function.
Examples
var uniform = require( '@stdlib/random-base-uniform' );
var bernoulli = require( '@stdlib/random-base-bernoulli' );
var incrnanmaxabs = require( '@stdlib/stats-incr-nanmaxabs' );
// Initialize an accumulator:
var accumulator = incrnanmaxabs();
// For each simulated datum, update the max absolute value...
var i;
for ( i = 0; i < 100; i++ ) {
accumulator( ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( -50.0, 50.0 ) );
}
console.log( accumulator() );Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
