diff --git a/lib/node_modules/@stdlib/stats/incr/nanstdev/README.md b/lib/node_modules/@stdlib/stats/incr/nanstdev/README.md new file mode 100644 index 000000000000..ab6bea7dfc01 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanstdev/README.md @@ -0,0 +1,147 @@ + + +# incrnanstdev + +> Compute a [corrected sample standard deviation][sample-stdev] incrementally, ignoring `NaN` values. + +
+ +The [corrected sample standard deviation][sample-stdev] is defined as + + + +```math +s = \sqrt{\frac{1}{n-1} \sum_{i=0}^{n-1} ( x_i - \bar{x} )^2} +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanstdev = require( '@stdlib/stats/incr/nanstdev' ); +``` + +#### incrnanstdev( \[mean] ) + +Returns an accumulator function which incrementally computes a [corrected sample standard deviation][sample-stdev], ignoring `NaN` values. + +```javascript +var accumulator = incrnanstdev(); +``` + +If the mean is already known, provide a `mean` argument. + +```javascript +var accumulator = incrnanstdev( 3.0 ); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated [corrected sample standard deviation][sample-stdev]. If not provided an input value `x`, the accumulator function returns the current [corrected sample standard deviation][sample-stdev]. + +```javascript +var accumulator = incrnanstdev(); + +var s = accumulator( 2.0 ); +// returns 0.0 + +s = accumulator( 1.0 ); // => sqrt(((2-1.5)^2+(1-1.5)^2) / (2-1)) +// returns ~0.7071 + +s = accumulator( 3.0 ); // => sqrt(((2-2)^2+(1-2)^2+(3-2)^2) / (3-1)) +// returns 1.0 + +s = accumulator( NaN ); +// returns 1.0 + +s = accumulator(); +// returns 1.0 +``` + +
+ + + +
+ +## 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 + + + +```javascript +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var incrnanstdev = require( '@stdlib/stats/incr/nanstdev' ); + +// Initialize an accumulator: +var accumulator = incrnanstdev(); + +// For each simulated datum, update the sample standard deviation... +var i; +for ( i = 0; i < 100; i++ ) { + accumulator( ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ) ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanstdev/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanstdev/benchmark/benchmark.js new file mode 100644 index 000000000000..2271eec6d9e9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanstdev/benchmark/benchmark.js @@ -0,0 +1,91 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var pkg = require( './../package.json' ).name; +var incrnanstdev = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanstdev(); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::accumulator', function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnanstdev(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu() ); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::accumulator,known_mean', function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnanstdev( 3.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu() ); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/incr/nanstdev/docs/img/equation_corrected_sample_standard_deviation.svg b/lib/node_modules/@stdlib/stats/incr/nanstdev/docs/img/equation_corrected_sample_standard_deviation.svg new file mode 100644 index 000000000000..6af85c9d5732 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanstdev/docs/img/equation_corrected_sample_standard_deviation.svg @@ -0,0 +1,73 @@ + +s equals StartRoot StartFraction 1 Over n minus 1 EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts left-parenthesis x Subscript i Baseline minus x overbar right-parenthesis squared EndRoot + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanstdev/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanstdev/docs/repl.txt new file mode 100644 index 000000000000..2579e6046dba --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanstdev/docs/repl.txt @@ -0,0 +1,36 @@ + +{{alias}}( [mean] ) + Returns an accumulator function which incrementally computes a corrected + sample standard deviation, ignoring `NaN` values. + + If provided a value, the accumulator function returns an updated corrected + sample standard deviation. If not provided a value, the accumulator function + returns the current corrected sample standard deviation. + + Parameters + ---------- + mean: number (optional) + Known mean. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var s = accumulator() + null + > s = accumulator( 2.0 ) + 0.0 + > s = accumulator( -5.0 ) + ~4.95 + > s = accumulator( NaN ) + ~4.95 + > s = accumulator() + ~4.95 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanstdev/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanstdev/docs/types/index.d.ts new file mode 100644 index 000000000000..8ffed06b436d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanstdev/docs/types/index.d.ts @@ -0,0 +1,58 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* If provided a value, returns an updated corrected sample standard deviation; otherwise, returns the current corrected sample standard deviation. +* +* @param x - value +* @returns corrected sample standard deviation +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a corrected sample standard deviation, ignoring `NaN` values. +* +* @param mu - known mean +* @returns accumulator function +* +* @example +* var accumulator = incrnanstdev(); +* +* var s = accumulator(); +* // returns null +* +* s = accumulator( 2.0 ); +* // returns 0.0 +* +* s = accumulator( -5.0 ); +* // returns ~4.95 +* +* s = accumulator( NaN ); +* // returns ~4.95 +* +* s = accumulator(); +* // returns ~4.95 +*/ +declare function incrnanstdev( mu?: number ): accumulator; + + +// EXPORTS // + +export = incrnanstdev; diff --git a/lib/node_modules/@stdlib/stats/incr/nanstdev/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanstdev/docs/types/test.ts new file mode 100644 index 000000000000..6f118274d871 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanstdev/docs/types/test.ts @@ -0,0 +1,60 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import incrnanstdev = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanstdev(); // $ExpectType accumulator + incrnanstdev( 0.0 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided invalid arguments... +{ + incrnanstdev( '5' ); // $ExpectError + incrnanstdev( true ); // $ExpectError + incrnanstdev( false ); // $ExpectError + incrnanstdev( null ); // $ExpectError + incrnanstdev( [] ); // $ExpectError + incrnanstdev( {} ); // $ExpectError + incrnanstdev( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanstdev(); + + acc(); // $ExpectType number | null + acc( 3.14 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrnanstdev(); + + acc( '5' ); // $ExpectError + acc( true ); // $ExpectError + acc( false ); // $ExpectError + acc( null ); // $ExpectError + acc( [] ); // $ExpectError + acc( {} ); // $ExpectError + acc( ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanstdev/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanstdev/examples/index.js new file mode 100644 index 000000000000..8277cce35734 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanstdev/examples/index.js @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var incrnanstdev = require( './../lib' ); + +// Initialize an accumulator: +var accumulator = incrnanstdev(); + +// For each simulated datum, update the corrected sample standard deviation... +console.log( '\nValue\tSigma\n' ); +var v; +var i; +for ( i = 0; i < 100; i++ ) { + v = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); + console.log( '%d\t%d', v.toFixed( 4 ), accumulator( v ).toFixed( 4 ) ); +} +console.log( '\nFinal standard deviation: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanstdev/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanstdev/lib/index.js new file mode 100644 index 000000000000..a8ac1d807f61 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanstdev/lib/index.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute a corrected sample standard deviation incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanstdev +* +* @example +* var incrstdev = require( '@stdlib/stats/incr/nanstdev' ); +* +* var accumulator = incrnanstdev(); +* +* var s = accumulator(); +* // returns null +* +* s = accumulator( 2.0 ); +* // returns 0.0 +* +* s = accumulator( -5.0 ); +* // returns ~4.95 +* +* s = accumulator( NaN ); +* // returns ~4.95 +* +* s = accumulator(); +* // returns ~4.95 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanstdev/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanstdev/lib/main.js new file mode 100644 index 000000000000..226dcacc8e09 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanstdev/lib/main.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrstdev = require( '@stdlib/stats/incr/stdev' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a corrected sample standard deviation, ignoring `NaN` values. +* +* @param {number} [mean] - mean value +* @throws {TypeError} must provide a number +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanstdev(); +* +* var s = accumulator(); +* // returns null +* +* s = accumulator( 2.0 ); +* // returns 0.0 +* +* s = accumulator( -5.0 ); +* // returns ~4.95 +* +* s = accumulator( NaN ); +* // returns ~4.95 +* +* s = accumulator(); +* // returns ~4.95 +* +* @example +* var accumulator = incrnanstdev( 3.0 ); +*/ +function incrnanstdev( mean ) { + var stdev; + if ( arguments.length ) { + stdev = incrstdev( mean ); + } else { + stdev = incrstdev(); + } + return accumulator; + + /** + * If provided a value, the accumulator function returns an updated corrected sample standard deviation. If not provided a value, the accumulator function returns the current corrected sample standard deviation. + * + * @private + * @param {number} [x] - new value + * @returns {(number|null)} corrected sample standard deviation or null + */ + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) ) { + return stdev(); + } + return stdev( x ); + } +} + + +// EXPORTS // + +module.exports = incrnanstdev; diff --git a/lib/node_modules/@stdlib/stats/incr/nanstdev/package.json b/lib/node_modules/@stdlib/stats/incr/nanstdev/package.json new file mode 100644 index 000000000000..774c5d911bcf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanstdev/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/stats/incr/nanstdev", + "version": "0.0.0", + "description": "Compute a corrected sample standard deviation incrementally, ignoring NaN values.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "variance", + "sample variance", + "var", + "dispersion", + "standard deviation", + "stdev", + "corrected", + "central tendency", + "incremental", + "accumulator" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanstdev/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanstdev/test/test.js new file mode 100644 index 000000000000..f27d7d1e5b83 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanstdev/test/test.js @@ -0,0 +1,273 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var incrnanstdev = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanstdev, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanstdev(), 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an accumulator function (known mean)', function test( t ) { + t.equal( typeof incrnanstdev( 3.0 ), 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided a non-numeric value', function test( t ) { + var values; + var i; + + values = [ + '5', + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + incrnanstdev( value ); + }; + } +}); + +tape( 'the accumulator function incrementally computes a corrected sample standard deviation', function test( t ) { + var expected; + var actual; + var data; + var acc; + var i; + + data = [ 2.0, 3.0, 2.0, 4.0, 3.0, 4.0 ]; + + // Check against Julia: + expected = [ + 0.0, + sqrt( 0.5 ), + sqrt( 0.33333333333333337 ), + sqrt( 0.9166666666666666 ), + sqrt( 0.7 ), + sqrt( 0.8 ) + ]; + + acc = incrnanstdev(); + + actual = []; + for ( i = 0; i < data.length; i++ ) { + actual.push( acc( data[ i ] ) ); + } + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes a corrected sample standard deviation (known mean)', function test( t ) { + var expected; + var actual; + var data; + var acc; + var i; + + data = [ 2.0, 3.0, 2.0, 4.0, 3.0, 4.0 ]; + + // Test against Julia: + expected =[ + sqrt( 1.0 ), + sqrt( 0.5 ), + sqrt( 0.6666666666666666 ), + sqrt( 0.75 ), + sqrt( 0.6 ), + sqrt( 0.6666666666666666 ) + ]; + + acc = incrnanstdev( 3.0 ); + + actual = []; + for ( i = 0; i < data.length; i++ ) { + actual.push( acc( data[ i ] ) ); + } + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current corrected sample deviation', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, 3.0, 1.0 ]; + acc = incrnanstdev(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), 1.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current corrected sample deviation (known mean)', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, 3.0, 1.0 ]; + acc = incrnanstdev( 2.0 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), sqrt( 0.6666666666666666 ), 'returns expected value' ); + t.end(); +}); + +tape( 'the corrected sample standard deviation is `null` until at least 1 datum has been provided (unknown mean)', function test( t ) { + var acc; + var s; + + acc = incrnanstdev(); + + s = acc(); + t.equal( s, null, 'returns expected value' ); + + s = acc( 3.0 ); + t.notEqual( s, null, 'returns expected value' ); + + s = acc(); + t.notEqual( s, null, 'returns expected value' ); + + t.end(); +}); + +tape( 'the corrected sample standard deviation is `null` until at least 1 datum has been provided (known mean)', function test( t ) { + var acc; + var s; + + acc = incrnanstdev( 3.0 ); + + s = acc(); + t.equal( s, null, 'returns expected value' ); + + s = acc( 3.0 ); + t.notEqual( s, null, 'returns expected value' ); + + s = acc(); + t.notEqual( s, null, 'returns expected value' ); + + t.end(); +}); + +tape( 'the corrected sample standard deviation is `0` until at least 2 datums have been provided (unknown mean)', function test( t ) { + var acc; + var s; + + acc = incrnanstdev(); + + s = acc( 2.0 ); + t.equal( s, 0.0, 'returns expected value' ); + + s = acc(); + t.equal( s, 0.0, 'returns expected value' ); + + s = acc( 3.0 ); + t.notEqual( s, 0.0, 'returns expected value' ); + + s = acc(); + t.notEqual( s, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `NaN`, the accumulator function returns the current corrected sample standard deviation (unknown mean)', function test( t ) { + var expected; + var actual; + var data; + var acc; + var i; + + data = [ 2.0, 3.0, NaN, 2.0, 4.0, 3.0, 4.0 ]; + + // Check against Julia: + expected = [ + 0.0, + sqrt( 0.5 ), + sqrt( 0.5 ), + sqrt( 0.33333333333333337 ), + sqrt( 0.9166666666666666 ), + sqrt( 0.7 ), + sqrt( 0.8 ) + ]; + + acc = incrnanstdev(); + + actual = []; + for ( i = 0; i < data.length; i++ ) { + actual.push( acc( data[ i ] ) ); + } + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `NaN`, the accumulator function returns the current corrected sample standard deviation (known mean)', function test( t ) { + var expected; + var actual; + var data; + var acc; + var i; + + data = [ 2.0, 3.0, NaN, 2.0, 4.0, 3.0, 4.0 ]; + + // Test against Julia: + expected =[ + sqrt( 1.0 ), + sqrt( 0.5 ), + sqrt( 0.5 ), + sqrt( 0.6666666666666666 ), + sqrt( 0.75 ), + sqrt( 0.6 ), + sqrt( 0.6666666666666666 ) + ]; + + acc = incrnanstdev( 3.0 ); + + actual = []; + for ( i = 0; i < data.length; i++ ) { + actual.push( acc( data[ i ] ) ); + } + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +});