Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

incrnangmean

Compute a geometric mean incrementally, ignoring NaN values.

The geometric mean is defined as the nth root of a product of n numbers.

$$\biggl( \prod_{i=0}^{n-1} x_i \biggr)^{\frac{1}{n}} = \sqrt[n]{x_0 x_1 \cdots x_{n-1}}$$

Usage

var incrnangmean = require( '@stdlib/stats/incr/nangmean' );

incrnangmean()

Returns an accumulator function which incrementally computes a geometric mean, ignoring NaN values.

var accumulator = incrnangmean();

accumulator( [x] )

If provided an input value x, the accumulator function returns an updated geometric mean. If not provided an input value x, the accumulator function returns the current geometric mean.

var accumulator = incrnangmean();

var prod = accumulator( 2.0 );
// returns 2.0

prod = accumulator( 1.0 );
// returns ~1.414

prod = accumulator( NaN );
// returns ~1.414

prod = accumulator( 3.0 );
// returns ~1.817

prod = accumulator();
// returns ~1.817

Notes

  • 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 bernoulli = require( '@stdlib/random/base/bernoulli' );
var uniform = require( '@stdlib/random/base/uniform' );
var incrnangmean = require( '@stdlib/stats/incr/nangmean' );

var accumulator;
var v;
var i;

// Initialize an accumulator:
accumulator = incrnangmean();

// For each simulated value, update the geometric mean...
for ( i = 0; i < 100; i++ ) {
    if ( bernoulli( 0.2 ) ) {
        v = NaN;
    } else {
        v = uniform( 0.0, 100.0 );
    }
    accumulator( v );
}
console.log( accumulator() );