From 093582109c03a692eb83fc0c2f661cbebe2e28b1 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Tue, 1 Jul 2025 11:19:50 +0500 Subject: [PATCH 01/32] feat: add `blas/ext/base/ndarray/sindex-of` PR-URL: https://github.com/stdlib-js/stdlib/pull/7529 Ref: https://github.com/stdlib-js/stdlib/issues/2656 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../blas/ext/base/ndarray/sindex-of/README.md | 159 ++++++++++++++++++ .../ndarray/sindex-of/benchmark/benchmark.js | 112 ++++++++++++ .../ext/base/ndarray/sindex-of/docs/repl.txt | 41 +++++ .../ndarray/sindex-of/docs/types/index.d.ts | 56 ++++++ .../base/ndarray/sindex-of/docs/types/test.ts | 70 ++++++++ .../base/ndarray/sindex-of/examples/index.js | 45 +++++ .../ext/base/ndarray/sindex-of/lib/index.js | 54 ++++++ .../ext/base/ndarray/sindex-of/lib/main.js | 95 +++++++++++ .../ext/base/ndarray/sindex-of/package.json | 65 +++++++ .../ext/base/ndarray/sindex-of/test/test.js | 158 +++++++++++++++++ 10 files changed, 855 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md new file mode 100644 index 000000000000..caad8a6fbd0a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md @@ -0,0 +1,159 @@ + + +# sindexOf + +> Return the first index of a search element in a one-dimensional single-precision floating-point ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var sindexOf = require( '@stdlib/blas/ext/base/ndarray/sindex-of' ); +``` + +#### sindexOf( arrays ) + +Returns the first index of a specified search element in a one-dimensional single-precision floating-point ndarray. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float32' +}); + +var fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' +}); + +var idx = sindexOf( [ x, searchElement, fromIndex ] ); +// returns 3 +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the search element. + - a zero-dimensional ndarray containing the index from which to begin searching. + +If the function is unable to find a search element, the function returns `-1`. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var searchElement = scalar2ndarray( 10.0, { + 'dtype': 'float32' +}); + +var fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' +}); + +var idx = sindexOf( [ x, searchElement, fromIndex ] ); +// returns -1 +``` + +
+ + + +
+ +## Notes + +- If a specified starting search index is negative, the function resolves the starting search index by counting backward from the last element (where `-1` refers to the last element). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var sindexOf = require( '@stdlib/blas/ext/base/ndarray/sindex-of' ); + +var xbuf = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); +var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var searchElement = scalar2ndarray( 80.0, { + 'dtype': 'float32' +}); +console.log( 'Search Element:', ndarraylike2scalar( searchElement ) ); + +var fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' +}); +console.log( 'From Index:', ndarraylike2scalar( fromIndex ) ); + +var idx = sindexOf( [ x, searchElement, fromIndex ] ); +console.log( idx ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/benchmark/benchmark.js new file mode 100644 index 000000000000..918b142482a8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/benchmark/benchmark.js @@ -0,0 +1,112 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var pkg = require( './../package.json' ).name; +var sindexOf = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var searchElement; + var fromIndex; + var xbuf; + var x; + + xbuf = uniform( len, 0.0, 100.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + searchElement = scalar2ndarray( -10.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = sindexOf( [ x, searchElement, fromIndex ] ); + if ( out !== out ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt new file mode 100644 index 000000000000..07304b0db424 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt @@ -0,0 +1,41 @@ + +{{alias}}( arrays ) + Returns the first index of a search element in a one-dimensional single- + precision floating-point ndarray. + + If a specified starting search index is negative, the function resolves the + starting search index by counting backward from the last element (where `-1` + refers to the last element). + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the search element. + - a zero-dimensional ndarray containing the index from which to begin + searching. + + Returns + ------- + out: integer + Index. + + Examples + -------- + > var xbuf = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0 ] ); + > var dt = 'float32'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > var v = {{alias:@stdlib/ndarray/from-scalar}}( 2.0, { 'dtype': dt } ); + > var i = {{alias:@stdlib/ndarray/from-scalar}}( 0, { 'dtype': 'generic' } ); + > {{alias}}( [ x, v, i ] ) + 1 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts new file mode 100644 index 000000000000..b17a1234ae11 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts @@ -0,0 +1,56 @@ +/* +* @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 + +/// + +import { float32ndarray, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Returns the first index of a search element in a one-dimensional single-precision floating-point ndarray. +* +* @param arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element, and a zero-dimensional ndarray containing the index from which to begin searching +* @returns index +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var sindexOf = require( '@stdlib/blas/ext/base/ndarray/sindex-of' ); +* +* var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var searchElement = scalar2ndarray( 2.0, { +* 'dtype': 'float32' +* }); +* +* var fromIndex = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var v = sindexOf( [ x, searchElement, fromIndex ] ); +* // returns 3 +*/ +declare function sindexOf( arrays: [ float32ndarray, typedndarray, typedndarray ] ): number; + + +// EXPORTS // + +export = sindexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/test.ts new file mode 100644 index 000000000000..605065cab5ae --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/test.ts @@ -0,0 +1,70 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import sindexOf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + const searchElement = scalar2ndarray( 0.0, { + 'dtype': 'float32' + }); + const fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + + sindexOf( [ x, searchElement, fromIndex ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + sindexOf( '10' ); // $ExpectError + sindexOf( 10 ); // $ExpectError + sindexOf( true ); // $ExpectError + sindexOf( false ); // $ExpectError + sindexOf( null ); // $ExpectError + sindexOf( undefined ); // $ExpectError + sindexOf( [] ); // $ExpectError + sindexOf( {} ); // $ExpectError + sindexOf( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + const searchElement = scalar2ndarray( 0.0, { + 'dtype': 'float32' + }); + const fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + + sindexOf(); // $ExpectError + sindexOf( [ x, searchElement, fromIndex ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/examples/index.js new file mode 100644 index 000000000000..42496dd072ab --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/examples/index.js @@ -0,0 +1,45 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var sindexOf = require( './../lib' ); + +var xbuf = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); +var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var searchElement = scalar2ndarray( 80.0, { + 'dtype': 'float32' +}); +console.log( 'Search Element:', ndarraylike2scalar( searchElement ) ); + +var fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' +}); +console.log( 'From Index:', ndarraylike2scalar( fromIndex ) ); + +var idx = sindexOf( [ x, searchElement, fromIndex ] ); +console.log( idx ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/index.js new file mode 100644 index 000000000000..5ed07125048d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/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'; + +/** +* Return the first index of a search element in a one-dimensional single-precision floating-point ndarray. +* +* @module @stdlib/blas/ext/base/ndarray/sindex-of +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var sindexOf = require( '@stdlib/blas/ext/base/ndarray/sindex-of' ); +* +* var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var searchElement = scalar2ndarray( 2.0, { +* 'dtype': 'float32' +* }); +* +* var fromIndex = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var v = sindexOf( [ x, searchElement, fromIndex ] ); +* // returns 3 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js new file mode 100644 index 000000000000..b3417b8cb951 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js @@ -0,0 +1,95 @@ +/** +* @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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/blas/ext/base/sindex-of' ).ndarray; +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); + + +// MAIN // + +/** +* Returns the first index of a search element in a one-dimensional single-precision floating-point ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element, and a zero-dimensional ndarray containing the index from which to begin searching +* @returns {integer} index +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var sindexOf = require( '@stdlib/blas/ext/base/ndarray/sindex-of' ); +* +* var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var searchElement = scalar2ndarray( 2.0, { +* 'dtype': 'float32' +* }); +* +* var fromIndex = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var v = sindexOf( [ x, searchElement, fromIndex ] ); +* // returns 3 +*/ +function sindexOf( arrays ) { + var searchElement; + var fromIndex; + var stride; + var offset; + var idx; + var N; + var x; + + x = arrays[ 0 ]; + N = numelDimension( x, 0 ); + searchElement = ndarraylike2scalar( arrays[ 1 ] ); + fromIndex = ndarraylike2scalar( arrays[ 2 ] ); + + if ( fromIndex < 0 ) { + fromIndex += N; + if ( fromIndex < 0 ) { + fromIndex = 0; + } + } else if ( fromIndex >= N ) { + return -1; + } + N -= fromIndex; + stride = getStride( x, 0 ); + offset = getOffset( x ) + ( stride*fromIndex ); + + idx = strided( N, searchElement, getData( x ), stride, offset ); + if ( idx >= 0 ) { + idx += fromIndex; + } + return idx; +} + + +// EXPORTS // + +module.exports = sindexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/package.json new file mode 100644 index 000000000000..21d017200ce3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/sindex-of", + "version": "0.0.0", + "description": "Return the first index of a specified search element in a one-dimensional single-precision floating-point ndarray.", + "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", + "mathematics", + "math", + "blas", + "extended", + "array", + "index", + "search", + "get", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js new file mode 100644 index 000000000000..5d3bb296fabd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js @@ -0,0 +1,158 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var sindexOf = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Float32Array} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'float32', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sindexOf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns the first index of an element which equals a provided search element', function test( t ) { + var searchElement; + var fromIndex; + var actual; + var x; + + x = vector( new Float32Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ), 6, 1, 0 ); + + // Nonnegative fromIndex... + searchElement = scalar2ndarray( 1.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 0, 'returns expected value' ); + + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 2, 'returns expected value' ); + + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 3, 'returns expected value' ); + + searchElement = scalar2ndarray( 4.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, -1, 'returns expected value' ); + + // Negative fromIndex... + searchElement = scalar2ndarray( 3.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 5, 'returns expected value' ); + + searchElement = scalar2ndarray( 3.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( -2, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 4, 'returns expected value' ); + + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( -3, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 3, 'returns expected value' ); + + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( -7, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided a starting search index which is greater than or equal to number of elements in the input ndarray', function test( t ) { + var searchElement; + var fromIndex; + var actual; + var x; + + x = vector( new Float32Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ), 6, 1, 0 ); + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( 7, { + 'dtype': 'generic' + }); + + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); From 53cb5cec01d65b42bccee658c7ed3bd1d6b7c441 Mon Sep 17 00:00:00 2001 From: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> Date: Tue, 1 Jul 2025 11:56:47 +0530 Subject: [PATCH 02/32] docs: fix data type PR-URL: https://github.com/stdlib-js/stdlib/pull/7536 Reviewed-by: Athan Reines --- lib/node_modules/@stdlib/blas/base/dger/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/dger/examples/index.js b/lib/node_modules/@stdlib/blas/base/dger/examples/index.js index 00bd66217fb6..ef84ac0e39cb 100644 --- a/lib/node_modules/@stdlib/blas/base/dger/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/dger/examples/index.js @@ -22,7 +22,7 @@ var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var dger = require( './../lib' ); var opts = { - 'dtype': 'float32' + 'dtype': 'float64' }; var M = 3; From 4ea82ac0995cffd3f126ffc51badb04da502d538 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 1 Jul 2025 03:15:05 -0700 Subject: [PATCH 03/32] test: fix description --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/base/ztest/one-sample/results/to-string/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/to-string/test/test.js b/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/to-string/test/test.js index 041a344d6ed1..f6d01d827719 100644 --- a/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/to-string/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/to-string/test/test.js @@ -99,7 +99,7 @@ tape( 'the function throws an error if provided a `digits` option which is not a } }); -tape( 'the function throws an error if provided a `digits` option which is not a boolean', function test( t ) { +tape( 'the function throws an error if provided a `decision` option which is not a boolean', function test( t ) { var results; var values; var i; From 4b3f6b66882ec35af639463719e8e2fd57bd4d10 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 1 Jul 2025 03:37:37 -0700 Subject: [PATCH 04/32] docs: fix missing periods --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/ztest/one-sample/results/factory/docs/types/index.d.ts | 2 +- .../base/ztest/one-sample/results/float32/docs/types/index.d.ts | 2 +- .../base/ztest/one-sample/results/float64/docs/types/index.d.ts | 2 +- .../one-sample/results/struct-factory/docs/types/index.d.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/factory/docs/types/index.d.ts index 699372c6394e..37d1a2efd0a3 100644 --- a/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/factory/docs/types/index.d.ts @@ -113,7 +113,7 @@ declare class ResultsStruct { ci: T; /** - * Value of the mean under the null hypothesis + * Value of the mean under the null hypothesis. */ nullValue: number; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/float32/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/float32/docs/types/index.d.ts index 828311f4ffa1..e6c8dbcaa6d2 100644 --- a/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/float32/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/float32/docs/types/index.d.ts @@ -113,7 +113,7 @@ declare class ResultsStruct { ci: Float32Array; /** - * Value of the mean under the null hypothesis + * Value of the mean under the null hypothesis. */ nullValue: number; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/float64/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/float64/docs/types/index.d.ts index 253001b6370d..7e6dde235fc3 100644 --- a/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/float64/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/float64/docs/types/index.d.ts @@ -113,7 +113,7 @@ declare class ResultsStruct { ci: Float64Array; /** - * Value of the mean under the null hypothesis + * Value of the mean under the null hypothesis. */ nullValue: number; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/struct-factory/docs/types/index.d.ts index ef4c3df34fe4..86fade46b158 100644 --- a/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ztest/one-sample/results/struct-factory/docs/types/index.d.ts @@ -108,7 +108,7 @@ declare class Struct { ci: T; /** - * Value of the mean under the null hypothesis + * Value of the mean under the null hypothesis. */ nullValue: number; From b01aeba0cb63c8a37967d8f09f3a1a4bebd5aa91 Mon Sep 17 00:00:00 2001 From: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> Date: Tue, 1 Jul 2025 16:19:28 +0530 Subject: [PATCH 05/32] feat: add `stats/base/ztest/two-sample/results` PR-URL: https://github.com/stdlib-js/stdlib/pull/7448 Co-authored-by: Athan Reines Reviewed-by: Athan Reines Co-authored-by: stdlib-bot --- .../two-sample/results/factory/README.md | 153 ++++ .../results/factory/benchmark/benchmark.js | 105 +++ .../two-sample/results/factory/docs/repl.txt | 24 + .../results/factory/docs/types/index.d.ts | 199 +++++ .../results/factory/docs/types/test.ts | 56 ++ .../results/factory/examples/index.js | 59 ++ .../two-sample/results/factory/lib/index.js | 56 ++ .../two-sample/results/factory/lib/main.js | 430 +++++++++++ .../two-sample/results/factory/package.json | 66 ++ .../two-sample/results/factory/test/test.js | 686 ++++++++++++++++++ .../two-sample/results/float32/README.md | 429 +++++++++++ .../results/float32/benchmark/benchmark.js | 70 ++ .../two-sample/results/float32/docs/repl.txt | 29 + .../results/float32/docs/types/index.d.ts | 198 +++++ .../results/float32/docs/types/test.ts | 39 + .../results/float32/examples/index.js | 39 + .../base/ztest/two-sample/results/float32.h | 57 ++ .../two-sample/results/float32/lib/index.js | 54 ++ .../two-sample/results/float32/lib/main.js | 63 ++ .../two-sample/results/float32/manifest.json | 36 + .../two-sample/results/float32/package.json | 67 ++ .../two-sample/results/float32/test/test.js | 507 +++++++++++++ .../two-sample/results/float64/README.md | 429 +++++++++++ .../results/float64/benchmark/benchmark.js | 70 ++ .../two-sample/results/float64/docs/repl.txt | 29 + .../results/float64/docs/types/index.d.ts | 198 +++++ .../results/float64/docs/types/test.ts | 39 + .../results/float64/examples/index.js | 39 + .../base/ztest/two-sample/results/float64.h | 57 ++ .../two-sample/results/float64/lib/index.js | 54 ++ .../two-sample/results/float64/lib/main.js | 63 ++ .../two-sample/results/float64/manifest.json | 36 + .../two-sample/results/float64/package.json | 67 ++ .../two-sample/results/float64/test/test.js | 506 +++++++++++++ .../struct-factory/docs/types/index.d.ts | 4 +- .../two-sample/results/to-json/README.md | 129 ++++ .../results/to-json/benchmark/benchmark.js | 55 ++ .../two-sample/results/to-json/docs/repl.txt | 34 + .../results/to-json/docs/types/index.d.ts | 106 +++ .../results/to-json/docs/types/test.ts | 51 ++ .../results/to-json/examples/index.js | 38 + .../two-sample/results/to-json/lib/index.js | 54 ++ .../two-sample/results/to-json/lib/main.js | 71 ++ .../two-sample/results/to-json/package.json | 64 ++ .../two-sample/results/to-json/test/test.js | 73 ++ .../two-sample/results/to-string/README.md | 153 ++++ .../results/to-string/benchmark/benchmark.js | 55 ++ .../results/to-string/docs/repl.txt | 43 ++ .../results/to-string/docs/types/index.d.ts | 142 ++++ .../results/to-string/docs/types/test.ts | 134 ++++ .../results/to-string/examples/index.js | 38 + .../two-sample/results/to-string/lib/index.js | 54 ++ .../two-sample/results/to-string/lib/main.js | 144 ++++ .../two-sample/results/to-string/package.json | 64 ++ .../two-sample/results/to-string/test/test.js | 431 +++++++++++ 55 files changed, 6944 insertions(+), 2 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/include/stdlib/stats/base/ztest/two-sample/results/float32.h create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/include/stdlib/stats/base/ztest/two-sample/results/float64.h create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/README.md b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/README.md new file mode 100644 index 000000000000..b1c166e85cce --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/README.md @@ -0,0 +1,153 @@ + + +# resultsFactory + +> Create a new constructor for creating a two-sample Z-test results object. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var resultsFactory = require( '@stdlib/stats/base/ztest/two-sample/results/factory' ); +``` + +#### resultsFactory( dtype ) + +Returns a new constructor for creating a two-sample Z-test results object. + +```javascript +var Results = resultsFactory( 'float64' ); +// returns + +var r = new Results(); +// returns +``` + +The function supports the following parameters: + +- **dtype**: floating-point data type for storing floating-point results. Must be either `'float64'` or `'float32'`. + +
+ + + + + +
+ +## Notes + +- A results object is a [`struct`][@stdlib/dstructs/struct] providing a fixed-width composite data structure for storing two-sample Z-test results and providing an ABI-stable data layout for JavaScript-C interoperation. + +
+ + + + + +
+ +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var resultsFactory = require( '@stdlib/stats/base/ztest/two-sample/results/factory' ); + +var Results = resultsFactory( 'float64' ); +var results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); + +Results = resultsFactory( 'float32' ); +results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float32Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' +}); + +str = results.toString({ + 'format': 'linear' +}); +console.log( str ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/benchmark/benchmark.js new file mode 100644 index 000000000000..70e54338bd20 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @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 isFunction = require( '@stdlib/assert/is-function' ); +var isObject = require( '@stdlib/assert/is-object' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 'float64', + 'float32' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = factory( values[ i%values.length ] ); + if ( typeof v !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( !isFunction( v ) ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::constructor,new', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + factory( 'float64' ), + factory( 'float32' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new ( values[ i%values.length ] )(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::constructor,no_new', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + factory( 'float64' ), + factory( 'float32' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = values[ i%values.length ](); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/repl.txt new file mode 100644 index 000000000000..24564f0d59a9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/repl.txt @@ -0,0 +1,24 @@ + +{{alias}}( dtype ) + Returns a constructor for creating a two-sample Z-test results object. + + Parameters + ---------- + dtype: string + Floating-point data type for storing floating-point results. + + Returns + ------- + fcn: Function + Constructor. + + Examples + -------- + > var R = {{alias}}( 'float64' ); + > var r = new R(); + > r.toString( { 'format': 'linear' } ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/index.d.ts new file mode 100644 index 000000000000..446cb9008da3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/index.d.ts @@ -0,0 +1,199 @@ +/* +* @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 + +/** +* Alternative hypothesis. +*/ +type Alternative = 'two-sided' | 'greater' | 'less'; + +/** +* Interface describing test results. +*/ +interface Results { + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected?: boolean; + + /** + * Alternative hypothesis. + */ + alternative?: Alternative; + + /** + * Significance level. + */ + alpha?: number; + + /** + * p-value. + */ + pValue?: number; + + /** + * Test statistic. + */ + statistic?: number; + + /** + * Confidence interval. + */ + ci?: T; + + /** + * Difference in means under the null hypothesis. + */ + nullValue?: number; + + /** + * Sample mean of `x`. + */ + xmean?: number; + + /** + * Sample mean of `y`. + */ + ymean?: number; +} + +/** +* Interface describing a results data structure. +*/ +declare class ResultsStruct { + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns results + */ + constructor( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ); + + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected: boolean; + + /** + * Alternative hypothesis. + */ + alternative: Alternative; + + /** + * Significance level. + */ + alpha: number; + + /** + * p-value. + */ + pValue: number; + + /** + * Test statistic. + */ + statistic: number; + + /** + * Confidence interval. + */ + ci: T; + + /** + * Difference in means under the null hypothesis. + */ + nullValue: number; + + /** + * Sample mean of `x`. + */ + xmean: number; + + /** + * Sample mean of `y`. + */ + ymean: number; + + /** + * Test method. + */ + method: string; +} + +/** +* Interface defining a results constructor which is both "newable" and "callable". +*/ +interface ResultsConstructor { + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns struct + */ + new( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ): ResultsStruct; + + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns struct + */ + ( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ): ResultsStruct; +} + +/** +* Returns a new results constructor for creating a two-sample Z-test results object. +* +* @param dtype - floating-point data type for storing floating-point results +* @returns results constructor +* +* @example +* var Results = resultsFactory( 'float64' ); +* // returns +* +* var r = new Results(); +* // returns +*/ +declare function resultsFactory( dtype: 'float64' ): ResultsConstructor; + +/** +* Returns a constructor for creating a two-sample Z-test results object. +* +* @param dtype - floating-point data type for storing floating-point results +* @returns results constructor +* +* @example +* var Results = resultsFactory( 'float32' ); +* // returns +* +* var r = new Results(); +* // returns +*/ +declare function resultsFactory( dtype: 'float32' ): ResultsConstructor; + + +// EXPORTS // + +export = resultsFactory; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/test.ts new file mode 100644 index 000000000000..ace59c5ae4b9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/docs/types/test.ts @@ -0,0 +1,56 @@ +/* +* @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 resultsFactory = require( './index' ); + + +// TESTS // + +// The function returns a function... +{ + resultsFactory( 'float64' ); // $ExpectType ResultsConstructor + resultsFactory( 'float32' ); // $ExpectType ResultsConstructor +} + +// The compiler throws an error if not provided a supported data type... +{ + resultsFactory( 10 ); // $ExpectError + resultsFactory( true ); // $ExpectError + resultsFactory( false ); // $ExpectError + resultsFactory( null ); // $ExpectError + resultsFactory( undefined ); // $ExpectError + resultsFactory( [] ); // $ExpectError + resultsFactory( {} ); // $ExpectError + resultsFactory( ( x: number ): number => x ); // $ExpectError +} + +// The function returns a function which returns a results object... +{ + const Results = resultsFactory( 'float64' ); + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r1 = new Results( new ArrayBuffer( 80 ) ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r2 = new Results( new ArrayBuffer( 80 ), 8 ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r3 = new Results( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType ResultsStruct +} + +// TODO: add individual parameter tests diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/examples/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/examples/index.js new file mode 100644 index 000000000000..c531fc84c603 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/examples/index.js @@ -0,0 +1,59 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var resultsFactory = require( './../lib' ); + +var Results = resultsFactory( 'float64' ); +var results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); + +Results = resultsFactory( 'float32' ); +results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float32Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' +}); + +str = results.toString({ + 'format': 'linear' +}); +console.log( str ); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/index.js new file mode 100644 index 000000000000..e9d2742dd28f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/index.js @@ -0,0 +1,56 @@ +/** +* @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'; + +/** +* Return a constructor for creating a two-sample Z-test results object. +* +* @module @stdlib/stats/base/ztest/two-sample/results/factory +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var resultsFactory = require( '@stdlib/stats/base/ztest/two-sample/results/factory' ); +* +* var Results = resultsFactory( 'float64' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.0132; +* results.statistic = 2.4773; +* results.xmean = 3.7561; +* results.ymean = 3.0129; +* results.ci = new Float64Array( [ 0.1552, 1.3311 ] ); +* results.rejected = true; +* +* var str = results.toString(); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/main.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/main.js new file mode 100644 index 000000000000..07429bff3022 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/lib/main.js @@ -0,0 +1,430 @@ +/** +* @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. +*/ + +/* eslint-disable no-invalid-this, no-restricted-syntax */ + +'use strict'; + +// MODULES // + +var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); +var isObject = require( '@stdlib/assert/is-object' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var setReadWriteAccessor = require( '@stdlib/utils/define-nonenumerable-read-write-accessor' ); +var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); +var propertyDescriptor = require( '@stdlib/utils/property-descriptor' ); +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var join = require( '@stdlib/array/base/join' ); +var objectAssign = require( '@stdlib/object/assign' ); +var inherit = require( '@stdlib/utils/inherit' ); +var resolveStr = require( '@stdlib/stats/base/ztest/alternative-resolve-str' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var structFactory = require( '@stdlib/stats/base/ztest/two-sample/results/struct-factory' ); +var res2json = require( '@stdlib/stats/base/ztest/two-sample/results/to-json' ); +var res2str = require( '@stdlib/stats/base/ztest/two-sample/results/to-string' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var DTYPES = [ + 'float64', + 'float32' +]; + +var isDataType = contains( DTYPES ); + + +// MAIN // + +/** +* Returns a constructor for creating a two-sample Z-test results object. +* +* @param {string} dtype - storage data type for floating-point values +* @throws {TypeError} first argument must be a supported data type +* @returns {Function} constructor +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var Results = factory( 'float64' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.0132; +* results.statistic = 2.4773; +* results.xmean = 3.7561; +* results.ymean = 3.0129; +* results.ci = new Float64Array( [ 0.1552, 1.3311 ] ); +* results.rejected = true; +* +* var str = results.toString(); +* // returns +*/ +function factory( dtype ) { + var alternativeDescriptor; + var Struct; + + if ( !isDataType( dtype ) ) { + throw new TypeError( format( 'invalid argument. First argument must be one of the following: "%s". Value: `%s`.', join( DTYPES, ', ' ), dtype ) ); + } + + // Create a struct constructor: + Struct = structFactory( dtype ); + + // Cache a reference to a property descriptor on the parent prototype so that we can intercept the return value: + alternativeDescriptor = propertyDescriptor( Struct.prototype, 'alternative' ); + + /** + * Returns a two-sample Z-test results object. + * + * @private + * @constructor + * @param {(ArrayBuffer|Object)} [arg] - underlying byte buffer or a data object + * @param {NonNegativeInteger} [byteOffset] - byte offset + * @param {NonNegativeInteger} [byteLength] - maximum byte length + * @throws {TypeError} first argument must be an ArrayBuffer or a data object + * @returns {Results} results object + */ + function Results( arg, byteOffset, byteLength ) { + var nargs; + var args; + var v; + var i; + + nargs = arguments.length; + if ( !( this instanceof Results ) ) { + if ( nargs === 0 ) { + return new Results(); + } + if ( nargs === 1 ) { + return new Results( arg ); + } + if ( nargs === 2 ) { + return new Results( arg, byteOffset ); + } + return new Results( arg, byteOffset, byteLength ); + } + args = []; + if ( nargs > 0 ) { + if ( isArrayBuffer( arg ) ) { + for ( i = 0; i < nargs; i++ ) { + args.push( arguments[ i ] ); + } + } else if ( isObject( arg ) ) { + if ( hasProp( arg, 'alternative' ) ) { + args.push( objectAssign( {}, arg ) ); + v = resolveEnum( args[ 0 ].alternative ); + args[ 0 ].alternative = ( v === null ) ? NaN : v; + } + } else { + throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer or a data object. Value: `%s`.', arg ) ); + } + } + // Call the parent constructor... + Struct.apply( this, args ); + return this; + } + + /* + * Inherit from the parent constructor. + */ + inherit( Results, Struct ); + + /** + * Constructor name. + * + * @private + * @name name + * @memberof Results + * @readonly + * @type {string} + */ + setReadOnly( Results, 'name', Struct.name ); + + /** + * Alignment. + * + * @private + * @name alignment + * @memberof Results + * @readonly + * @type {PositiveInteger} + */ + setReadOnly( Results, 'alignment', Struct.alignment ); + + /** + * Size (in bytes) of the `struct`. + * + * @private + * @name byteLength + * @memberof Results + * @readonly + * @type {PositiveInteger} + */ + setReadOnly( Results, 'byteLength', Struct.byteLength ); + + /** + * Returns a list of `struct` fields. + * + * @private + * @name fields + * @memberof Results + * @readonly + * @type {Array} + */ + setReadOnlyAccessor( Results, 'fields', function get() { + return Struct.fields; + }); + + /** + * Returns a string corresponding to the `struct` layout. + * + * @private + * @name layout + * @memberof Results + * @readonly + * @type {string} + */ + setReadOnlyAccessor( Results, 'layout', function get() { + return Struct.layout; + }); + + /** + * Returns the underlying byte buffer of a `struct`. + * + * @private + * @name bufferOf + * @memberof Results + * @readonly + * @type {Function} + * @param {Object} obj - struct instance + * @throws {TypeError} must provide a `struct` instance + * @returns {ArrayBuffer} underlying byte buffer + */ + setReadOnly( Results, 'bufferOf', Struct.bufferOf ); + + /** + * Returns the length, in bytes, of the value specified by the provided field name. + * + * @private + * @name byteLengthOf + * @memberof Results + * @readonly + * @type {Function} + * @param {string} name - field name + * @throws {Error} struct must have at least one field + * @throws {TypeError} must provide a recognized field name + * @returns {NonNegativeInteger} byte length + */ + setReadOnly( Results, 'byteLengthOf', Struct.byteLengthOf ); + + /** + * Returns the offset, in bytes, from the beginning of a `struct` to the value specified by the provided field name. + * + * @private + * @name byteOffsetOf + * @memberof Results + * @readonly + * @type {Function} + * @param {string} name - field name + * @throws {Error} struct must have at least one field + * @throws {TypeError} must provide a recognized field name + * @returns {NonNegativeInteger} byte offset + */ + setReadOnly( Results, 'byteOffsetOf', Struct.byteOffsetOf ); + + /** + * Returns the description associated with a provided field name. + * + * @private + * @name descriptionOf + * @memberof Results + * @readonly + * @type {Function} + * @param {string} name - field name + * @throws {Error} struct must have at least one field + * @throws {TypeError} must provide a recognized field name + * @returns {string} description + */ + setReadOnly( Results, 'descriptionOf', Struct.descriptionOf ); + + /** + * Returns a boolean indicating whether a provided value is a `struct` instance. + * + * @private + * @name isStruct + * @memberof Results + * @readonly + * @type {Function} + * @param {*} value - input valueAdd commentMore actions + * @returns {boolean} boolean indicating whether a value is a `struct` instance + */ + setReadOnly( Results, 'isStruct', Struct.isStruct ); + + /** + * Returns the type associated with a provided field name. + * + * @private + * @name typeOf + * @memberof Results + * @readonly + * @type {Function} + * @param {string} name - field nameAdd commentMore actions + * @throws {Error} struct must have at least one field + * @throws {TypeError} must provide a recognized field name + * @returns {(string|Object)} type + */ + setReadOnly( Results, 'typeOf', Struct.typeOf ); + + /** + * Returns the underlying byte buffer of a `struct` as a `DataView`. + * + * @private + * @name viewOf + * @memberof Results + * @readonly + * @type {Function} + * @param {Object} obj - struct instance + * @throws {TypeError} must provide a `struct` instance + * @returns {DataView} view of underlying byte buffer + */ + setReadOnly( Results, 'viewOf', Struct.viewOf ); + + /** + * Test name. + * + * @private + * @name method + * @memberof Results.prototype + * @type {string} + * @default 'Two-sample Z-test' + */ + setReadOnly( Results.prototype, 'method', 'Two-sample Z-test' ); + + /** + * Alternative hypothesis. + * + * @private + * @name alternative + * @memberof Results.prototype + * @type {string} + */ + setReadWriteAccessor( Results.prototype, 'alternative', getAlternative, setAlternative ); + + /** + * Serializes a results object as a string. + * + * ## Notes + * + * - Example output: + * + * ```text + * + * Two-sample Z-test + * + * Alternative hypothesis: True difference in means is less than 1.0 + * + * pValue: 0.0406 + * statistic: 9.9901 + * 95% confidence interval: [9.7821, 10.4451] + * + * Test Decision: Reject null in favor of alternative at 5% significance level + * + * ``` + * + * @private + * @name toString + * @memberof Results.prototype + * @type {Function} + * @param {Options} [opts] - options object + * @param {PositiveInteger} [opts.digits=4] - number of digits after the decimal point + * @param {boolean} [opts.decision=true] - boolean indicating whether to show the test decision + * @throws {TypeError} options argument must be an object + * @throws {TypeError} must provide valid options + * @returns {string} serialized results + */ + setReadOnly( Results.prototype, 'toString', function toString( opts ) { + if ( arguments.length ) { + return res2str( this, opts ); + } + return res2str( this ); + }); + + /** + * Serializes a results object as a JSON object. + * + * ## Notes + * + * - `JSON.stringify()` implicitly calls this method when stringifying a `Results` instance. + * + * @private + * @name toJSON + * @memberof Results.prototype + * @type {Function} + * @returns {Object} serialized object + */ + setReadOnly( Results.prototype, 'toJSON', function toJSON() { + return res2json( this ); + }); + + /** + * Returns a DataView of a results object. + * + * @private + * @name toDataView + * @memberof Results.prototype + * @type {Function} + * @returns {DataView} DataView + */ + setReadOnly( Results.prototype, 'toDataView', function toDataView() { + return Struct.viewOf( this ); + }); + + return Results; + + /** + * Returns the alternative hypothesis. + * + * @private + * @returns {string} alternative hypothesis + */ + function getAlternative() { + return resolveStr( alternativeDescriptor.get.call( this ) ); + } + + /** + * Sets the alternative hypothesis. + * + * @private + * @param {string} value - alternative hypothesis + */ + function setAlternative( value ) { + alternativeDescriptor.set.call( this, resolveEnum( value ) ); + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/package.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/package.json new file mode 100644 index 000000000000..ec9dc34214af --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/stats/base/ztest/two-sample/results/factory", + "version": "0.0.0", + "description": "Return a constructor for creating a two-sample Z-test results object.", + "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", + "stats", + "statistics", + "ztest", + "z-test", + "utilities", + "utility", + "utils", + "util", + "constructor", + "ctor", + "results" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/test/test.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/test/test.js new file mode 100644 index 000000000000..f3bed3cbf857 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/factory/test/test.js @@ -0,0 +1,686 @@ +/** +* @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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var isDataView = require( '@stdlib/assert/is-dataview' ); +var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var resultsFactory = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof resultsFactory, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not a supported data type', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + 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() { + resultsFactory( value ); + }; + } +}); + +tape( 'the function returns a constructor which throws an error if provided a first argument which is not an ArrayBuffer or data object', function test( t ) { + var results; + var values; + var i; + + results = resultsFactory( 'float64' ); + + values = [ + '5', + 5, + NaN, + 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() { + results( value ); + }; + } +}); + +tape( 'the function returns a constructor which throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { + var results; + var values; + var i; + + results = resultsFactory( 'float64' ); + + values = [ + '5', + -5, + 3.14, + NaN, + 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() { + results( new ArrayBuffer( 1024 ), value ); + }; + } +}); + +tape( 'the function returns a constructor which throws an error if provided a third argument which is not a nonnegative integer', function test( t ) { + var results; + var values; + var i; + + results = resultsFactory( 'float64' ); + + values = [ + '5', + -5, + 3.14, + NaN, + 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() { + results( new ArrayBuffer( 1024 ), 0, value ); + }; + } +}); + +tape( 'the function returns a constructor which throws an error if provided an invalid `alternative` property value', function test( t ) { + var results; + var values; + var i; + + results = resultsFactory( 'float64' ); + + values = [ + '5', + -5, + 3.14, + NaN, + 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() { + results({ + 'alternative': value + }); + }; + } +}); + +tape( 'the function returns a constructor which does not require the `new` operator', function test( t ) { + var results; + var res; + + results = resultsFactory( 'float64' ); + + res = results(); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + res = results( {} ); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + res = results( new ArrayBuffer( 1024 ) ); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + res = results( new ArrayBuffer( 1024 ), 0 ); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + res = results( new ArrayBuffer( 1024 ), 0, 1024 ); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (dtype=float64)', function test( t ) { + var expected; + var Results; + var actual; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + actual = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }); + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (dtype=float32)', function test( t ) { + var expected; + var Results; + var actual; + + Results = resultsFactory( 'float32' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + actual = new Results({ + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.0132 ), + 'statistic': f32( 2.4773 ), + 'nullValue': f32( 0.0 ), + 'xmean': f32( 3.7561 ), + 'ymean': f32( 3.0129 ), + 'ci': new Float32Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }); + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.0132 ), + 'statistic': f32( 2.4773 ), + 'nullValue': f32( 0.0 ), + 'xmean': f32( 3.7561 ), + 'ymean': f32( 3.0129 ), + 'ci': new Float32Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (no arguments)', function test( t ) { + var expected; + var Results; + var actual; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + actual = new Results(); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.0132; + actual.statistic = 2.4773; + actual.nullValue = 0.0; + actual.xmean = 3.7561; + actual.ymean = 3.0129; + actual.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (empty object)', function test( t ) { + var expected; + var Results; + var actual; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + actual = new Results( {} ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.0132; + actual.statistic = 2.4773; + actual.nullValue = 0.0; + actual.xmean = 3.7561; + actual.ymean = 3.0129; + actual.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (ArrayBuffer)', function test( t ) { + var expected; + var Results; + var actual; + var buf; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + buf = new ArrayBuffer( 1024 ); + actual = new Results( buf ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.0132; + actual.statistic = 2.4773; + actual.nullValue = 0.0; + actual.xmean = 3.7561; + actual.ymean = 3.0129; + actual.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 0, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (ArrayBuffer, byteOffset)', function test( t ) { + var expected; + var Results; + var actual; + var buf; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + buf = new ArrayBuffer( 1024 ); + actual = new Results( buf, 16 ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.0132; + actual.statistic = 2.4773; + actual.nullValue = 0.0; + actual.xmean = 3.7561; + actual.ymean = 3.0129; + actual.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor for creating a fixed-width results object (ArrayBuffer, byteOffset, byteLength)', function test( t ) { + var expected; + var Results; + var actual; + var buf; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + buf = new ArrayBuffer( 1024 ); + actual = new Results( buf, 16, 160 ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.0132; + actual.statistic = 2.4773; + actual.nullValue = 0.0; + actual.xmean = 3.7561; + actual.ymean = 3.0129; + actual.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor which returns an instance having a method property', function test( t ) { + var Results; + var results; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + results = new Results(); + + t.strictEqual( results.method, 'Two-sample Z-test', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor which returns an instance having a `toString` method', function test( t ) { + var Results; + var results; + var actual; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + results = new Results(); + + actual = results.toString(); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + + actual = results.toString({ + 'decision': false + }); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor which returns an instance having a `toJSON` method', function test( t ) { + var Results; + var results; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + results = new Results(); + t.strictEqual( typeof results.toJSON, 'function', 'returns expected value' ); + t.strictEqual( typeof results.toJSON(), 'object', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a constructor which returns an instance having a `toDataView` method', function test( t ) { + var Results; + var results; + + Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + + results = new Results(); + t.strictEqual( typeof results.toDataView, 'function', 'returns expected value' ); + t.strictEqual( isDataView( results.toDataView() ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a constructor having a `name` property', function test( t ) { + var Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + t.strictEqual( typeof Results.name, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having an `alignment` property', function test( t ) { + var Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + t.strictEqual( typeof Results.alignment, 'number', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `byteLength` property', function test( t ) { + var Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + t.strictEqual( typeof Results.byteLength, 'number', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `fields` property', function test( t ) { + var Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + t.strictEqual( isStringArray( Results.fields ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `layout` property', function test( t ) { + var Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + t.strictEqual( typeof Results.layout, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `bufferOf` method', function test( t ) { + var Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + t.strictEqual( typeof Results.bufferOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `byteLengthOf` method', function test( t ) { + var Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + t.strictEqual( typeof Results.byteLengthOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `byteOffsetOf` method', function test( t ) { + var Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + t.strictEqual( typeof Results.byteOffsetOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `descriptionOf` method', function test( t ) { + var Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + t.strictEqual( typeof Results.descriptionOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having an `isStruct` method', function test( t ) { + var Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + t.strictEqual( typeof Results.isStruct, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a constructor having a `viewOf` method', function test( t ) { + var Results = resultsFactory( 'float64' ); + t.strictEqual( typeof Results, 'function', 'returns expected value' ); + t.strictEqual( typeof Results.viewOf, 'function', 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/README.md b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/README.md new file mode 100644 index 000000000000..24d36e1fc600 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/README.md @@ -0,0 +1,429 @@ + + +# Float32Results + +> Create a two-sample Z-test single-precision floating-point results object. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var Float32Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +``` + +#### Float32Results( \[arg\[, byteOffset\[, byteLength]]] ) + +Returns a two-sample Z-test single-precision floating-point results object. + +```javascript +var results = new Float32Results(); +// returns {...} +``` + +The function supports the following parameters: + +- **arg**: an [`ArrayBuffer`][@stdlib/array/buffer] or a data object (_optional_). +- **byteOffset**: byte offset (_optional_). +- **byteLength**: maximum byte length (_optional_). + +A data object argument is an object having one or more of the following properties: + +- **rejected**: boolean indicating whether the null hypothesis was rejected. +- **alternative**: the alternative hypothesis (e.g., `'two-sided'`, `'less'`, or `'greater'`). +- **alpha**: significance level. +- **pValue**: p-value. +- **statistic**: test statistic. +- **ci**: confidence interval as a [`Float32Array`][@stdlib/array/float32]. +- **nullValue**: difference in means under the null hypothesis. +- **xmean**: sample mean of `x`. +- **ymean**: sample mean of `y`. + +#### Float32Results.prototype.rejected + +Boolean indicating whether the null hypothesis was rejected. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.rejected; +// returns +``` + +#### Float32Results.prototype.alternative + +The alternative hypothesis. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.alternative; +// returns +``` + +#### Float32Results.prototype.alpha + +Significance level. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.alpha; +// returns +``` + +#### Float32Results.prototype.pValue + +The test p-value. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.pValue; +// returns +``` + +#### Float32Results.prototype.statistic + +The test statistic. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.statistic; +// returns +``` + +#### Float32Results.prototype.ci + +Confidence interval. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.ci; +// returns +``` + +#### Float32Results.prototype.nullValue + +Difference in means under the null hypothesis. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.nullValue; +// returns +``` + +#### Float32Results.prototype.xmean + +Sample mean of `x`. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.xmean; +// returns +``` + +#### Float32Results.prototype.ymean + +Sample mean of `y`. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.ymean; +// returns +``` + +#### Float32Results.prototype.toString( \[options] ) + +Serializes a results object to a formatted string. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.toString(); +// returns +``` + +The method supports the following options: + +- **digits**: number of digits to display after decimal points. Default: `4`. +- **decision**: boolean indicating whether to show the test decision. Default: `true`. + +Example output: + +```text + +Two-sample Z-test + +Alternative hypothesis: True difference in means is less than 1.0 + + pValue: 0.0406 + statistic: 9.9901 + 95% confidence interval: [9.7821, 10.4451] + +Test Decision: Reject null in favor of alternative at 5% significance level + +``` + +#### Float32Results.prototype.toJSON( \[options] ) + +Serializes a results object as a JSON object. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.toJSON(); +// returns {...} +``` + +`JSON.stringify()` implicitly calls this method when stringifying a results instance. + +#### Float32Results.prototype.toDataView() + +Returns a [`DataView`][@stdlib/array/dataview] of a results object. + +```javascript +var results = new Float32Results(); +// returns {...} + +// ... + +var v = results.toDataView(); +// returns +``` + +
+ + + + + +
+ +## Notes + +- A results object is a [`struct`][@stdlib/dstructs/struct] providing a fixed-width composite data structure for storing two-sample Z-test results and providing an ABI-stable data layout for JavaScript-C interoperation. + +
+ + + + + +
+ +## Examples + + + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); + +var results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float32Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/ztest/two-sample/results/float32.h" +``` + +#### stdlib_stats_ztest_two_sample_float32_results + +Structure for holding single-precision floating-point test results. + +```c +#include +#include + +struct stdlib_stats_ztest_two_sample_float32_results { + // Boolean indicating whether the null hypothesis was rejected: + bool rejected; + + // Alternative hypothesis: + int8_t alternative; + + // Significance level: + float alpha; + + // p-value: + float pValue; + + // Test statistic: + float statistic; + + // Confidence interval: + float ci[ 2 ]; + + // Difference in means under the null hypothesis: + float nullValue; + + // Sample mean of `x`: + float xmean; + + // Sample mean of `y`: + float ymean; +}; +``` + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/benchmark/benchmark.js new file mode 100644 index 000000000000..c9e290699a2c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/benchmark/benchmark.js @@ -0,0 +1,70 @@ +/** +* @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 isObject = require( '@stdlib/assert/is-object' ); +var pkg = require( './../package.json' ).name; +var Float32Results = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::constructor,new', function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new Float32Results(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::constructor,no_new', function benchmark( b ) { + var results; + var v; + var i; + + results = Float32Results; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = results(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/repl.txt new file mode 100644 index 000000000000..e30724623d96 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( [arg[, byteOffset[, byteLength]]] ) + Returns a two-sample Z-test single-precision floating-point results object. + + Parameters + ---------- + arg: Object|ArrayBuffer (optional) + ArrayBuffer or data object. + + byteOffset: integer (optional) + Byte offset. + + byteLength: integer (optional) + Maximum byte length. + + Returns + ------- + out: Object + Results object. + + Examples + -------- + > var r = new {{alias}}(); + > r.toString( { 'format': 'linear' } ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/index.d.ts new file mode 100644 index 000000000000..fa908e6a84ad --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/index.d.ts @@ -0,0 +1,198 @@ +/* +* @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 + +/** +* Alternative hypothesis. +*/ +type Alternative = 'two-sided' | 'greater' | 'less'; + +/** +* Interface describing test results. +*/ +interface Results { + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected?: boolean; + + /** + * Alternative hypothesis. + */ + alternative?: Alternative; + + /** + * Significance level. + */ + alpha?: number; + + /** + * p-value. + */ + pValue?: number; + + /** + * Test statistic. + */ + statistic?: number; + + /** + * Confidence interval. + */ + ci?: Float32Array; + + /** + * Difference in means under the null hypothesis. + */ + nullValue?: number; + + /** + * Sample mean of `x`. + */ + xmean?: number; + + /** + * Sample mean of `y`. + */ + ymean?: number; +} + +/** +* Interface describing a results data structure. +*/ +declare class ResultsStruct { + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns results + */ + constructor( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ); + + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected: boolean; + + /** + * Alternative hypothesis. + */ + alternative: Alternative; + + /** + * Significance level. + */ + alpha: number; + + /** + * p-value. + */ + pValue: number; + + /** + * Test statistic. + */ + statistic: number; + + /** + * Confidence interval. + */ + ci: Float32Array; + + /** + * Difference in means under the null hypothesis. + */ + nullValue: number; + + /** + * Sample mean of `x`. + */ + xmean?: number; + + /** + * Sample mean of `y`. + */ + ymean?: number; + + /** + * Test method. + */ + method: string; +} + +/** +* Interface defining a results constructor which is both "newable" and "callable". +*/ +interface ResultsConstructor { + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns results object + */ + new( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ): ResultsStruct; + + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns results object + */ + ( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ): ResultsStruct; +} + +/** +* Returns a two-sample Z-test single-precision floating-point results object. +* +* @param arg - buffer or data object +* @param byteOffset - byte offset +* @param byteLength - maximum byte length +* @returns results object +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.0132; +* results.statistic = 2.4773; +* results.xmean = 3.7561; +* results.ymean = 3.0129; +* results.ci = new Float32Array( [ 0.1552, 1.3311 ] ); +* results.rejected = true; +* +* var str = results.toString(); +* // returns +*/ +declare var Results: ResultsConstructor; + + +// EXPORTS // + +export = Results; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/test.ts new file mode 100644 index 000000000000..d770dcca67d1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/docs/types/test.ts @@ -0,0 +1,39 @@ +/* +* @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 Results = require( './index' ); + + +// TESTS // + +// The function returns a results object... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r0 = new Results( {} ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r1 = new Results( new ArrayBuffer( 80 ) ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r2 = new Results( new ArrayBuffer( 80 ), 8 ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r3 = new Results( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType ResultsStruct +} + +// TODO: add individual parameter tests diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/examples/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/examples/index.js new file mode 100644 index 000000000000..547fe87ad3fa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/examples/index.js @@ -0,0 +1,39 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var Results = require( './../lib' ); + +var results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float32Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/include/stdlib/stats/base/ztest/two-sample/results/float32.h b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/include/stdlib/stats/base/ztest/two-sample/results/float32.h new file mode 100644 index 000000000000..79b5ffcef8d7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/include/stdlib/stats/base/ztest/two-sample/results/float32.h @@ -0,0 +1,57 @@ +/** +* @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. +*/ + +#ifndef STDLIB_STATS_BASE_ZTEST_TWO_SAMPLE_RESULTS_FLOAT32_H +#define STDLIB_STATS_BASE_ZTEST_TWO_SAMPLE_RESULTS_FLOAT32_H + +#include +#include + +/** +* Struct for storing test results. +*/ +struct stdlib_stats_ztest_two_sample_float32_results { + // Boolean indicating whether the null hypothesis was rejected: + bool rejected; + + // Alternative hypothesis: + int8_t alternative; + + // Significance level: + float alpha; + + // p-value: + float pValue; + + // Test statistic: + float statistic; + + // Confidence interval: + float ci[ 2 ]; + + // Difference in means under the null hypothesis: + float nullValue; + + // Sample mean of `x`: + float xmean; + + // Sample mean of `y`: + float ymean; +}; + +#endif // !STDLIB_STATS_BASE_ZTEST_TWO_SAMPLE_RESULTS_FLOAT32_H diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/index.js new file mode 100644 index 000000000000..e5fc2ecd2689 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/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'; + +/** +* Create a two-sample Z-test single-precision floating-point results object. +* +* @module @stdlib/stats/base/ztest/two-sample/results/float32 +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.0132; +* results.statistic = 2.4773; +* results.xmean = 3.7561; +* results.ymean = 3.0129; +* results.ci = new Float32Array( [ 0.1552, 1.3311 ] ); +* results.rejected = true; +* +* var str = results.toString(); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/main.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/main.js new file mode 100644 index 000000000000..227b59562a64 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/lib/main.js @@ -0,0 +1,63 @@ +/** +* @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 factory = require( '@stdlib/stats/base/ztest/two-sample/results/factory' ); + + +// MAIN // + +/** +* Returns a two-sample Z-test single-precision floating-point results object. +* +* @name Results +* @constructor +* @type {Function} +* @param {ArrayBuffer} [buffer] - underlying byte buffer +* @param {NonNegativeInteger} [byteOffset] - byte offset +* @param {NonNegativeInteger} [byteLength] - maximum byte length +* @returns {Results} results object +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.0132; +* results.statistic = 2.4773; +* results.xmean = 3.7561; +* results.ymean = 3.0129; +* results.ci = new Float32Array( [ 0.1552, 1.3311 ] ); +* results.rejected = true; +* +* var str = results.toString(); +* // returns +*/ +var Results = factory( 'float32' ); + + +// EXPORTS // + +module.exports = Results; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/manifest.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/manifest.json new file mode 100644 index 000000000000..844d692f6439 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/package.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/package.json new file mode 100644 index 000000000000..dfbcaea97373 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/base/ztest/two-sample/results/float32", + "version": "0.0.0", + "description": "Create a two-sample Z-test single-precision floating-point results object.", + "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", + "include": "./include", + "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", + "stats", + "statistics", + "ztest", + "z-test", + "utilities", + "utility", + "utils", + "util", + "constructor", + "ctor", + "results" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/test/test.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/test/test.js new file mode 100644 index 000000000000..7ce673b23c09 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float32/test/test.js @@ -0,0 +1,507 @@ +/** +* @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 isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var isDataView = require( '@stdlib/assert/is-dataview' ); +var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var Float32Array = require( '@stdlib/array/float32' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Results = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float32Results, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ArrayBuffer or data object', function test( t ) { + var results; + var values; + var i; + + results = Float32Results; + + values = [ + '5', + 5, + NaN, + 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() { + results( value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { + var results; + var values; + var i; + + results = Float32Results; + + values = [ + '5', + -5, + 3.14, + NaN, + 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() { + results( new ArrayBuffer( 1024 ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not a nonnegative integer', function test( t ) { + var results; + var values; + var i; + + results = Float32Results; + + values = [ + '5', + -5, + 3.14, + NaN, + 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() { + results( new ArrayBuffer( 1024 ), 0, value ); + }; + } +}); + +tape( 'the function is a constructor which does not require the `new` operator', function test( t ) { + var results; + var res; + + results = Float32Results; + + res = results(); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + res = results( {} ); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + res = results( new ArrayBuffer( 1024 ) ); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + res = results( new ArrayBuffer( 1024 ), 0 ); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + res = results( new ArrayBuffer( 1024 ), 0, 1024 ); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object ', function test( t ) { + var expected; + var actual; + + actual = new Float32Results({ + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.0132 ), + 'statistic': f32( 2.4773 ), + 'nullValue': f32( 0.0 ), + 'xmean': f32( 3.7561 ), + 'ymean': f32( 3.0129 ), + 'ci': new Float32Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }); + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.0132 ), + 'statistic': f32( 2.4773 ), + 'nullValue': f32( 0.0 ), + 'xmean': f32( 3.7561 ), + 'ymean': f32( 3.0129 ), + 'ci': new Float32Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float32Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (no arguments)', function test( t ) { + var expected; + var actual; + + actual = new Float32Results(); + + actual.rejected = true; + actual.alpha = f32( 0.05 ); + actual.pValue = f32( 0.0132 ); + actual.statistic = f32( 2.4773 ); + actual.nullValue = f32( 0.0 ); + actual.xmean = f32( 3.7561 ); + actual.ymean = f32( 3.0129 ); + actual.ci = new Float32Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.0132 ), + 'statistic': f32( 2.4773 ), + 'nullValue': f32( 0.0 ), + 'xmean': f32( 3.7561 ), + 'ymean': f32( 3.0129 ), + 'ci': new Float32Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float32Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (empty object)', function test( t ) { + var expected; + var actual; + + actual = new Float32Results( {} ); + + actual.rejected = true; + actual.alpha = f32( 0.05 ); + actual.pValue = f32( 0.0132 ); + actual.statistic = f32( 2.4773 ); + actual.nullValue = f32( 0.0 ); + actual.xmean = f32( 3.7561 ); + actual.ymean = f32( 3.0129 ); + actual.ci = new Float32Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.0132 ), + 'statistic': f32( 2.4773 ), + 'nullValue': f32( 0.0 ), + 'xmean': f32( 3.7561 ), + 'ymean': f32( 3.0129 ), + 'ci': new Float32Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float32Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (ArrayBuffer)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float32Results( buf ); + + actual.rejected = true; + actual.alpha = f32( 0.05 ); + actual.pValue = f32( 0.0132 ); + actual.statistic = f32( 2.4773 ); + actual.nullValue = f32( 0.0 ); + actual.xmean = f32( 3.7561 ); + actual.ymean = f32( 3.0129 ); + actual.ci = new Float32Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.0132 ), + 'statistic': f32( 2.4773 ), + 'nullValue': f32( 0.0 ), + 'xmean': f32( 3.7561 ), + 'ymean': f32( 3.0129 ), + 'ci': new Float32Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float32Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 0, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (ArrayBuffer, byteOffset)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float32Results( buf, 16 ); + + actual.rejected = true; + actual.alpha = f32( 0.05 ); + actual.pValue = f32( 0.0132 ); + actual.statistic = f32( 2.4773 ); + actual.nullValue = f32( 0.0 ); + actual.xmean = f32( 3.7561 ); + actual.ymean = f32( 3.0129 ); + actual.ci = new Float32Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.0132 ), + 'statistic': f32( 2.4773 ), + 'nullValue': f32( 0.0 ), + 'xmean': f32( 3.7561 ), + 'ymean': f32( 3.0129 ), + 'ci': new Float32Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float32Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (ArrayBuffer, byteOffset, byteLength)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float32Results( buf, 16, 160 ); + + actual.rejected = true; + actual.alpha = f32( 0.05 ); + actual.pValue = f32( 0.0132 ); + actual.statistic = f32( 2.4773 ); + actual.nullValue = f32( 0.0 ); + actual.xmean = f32( 3.7561 ); + actual.ymean = f32( 3.0129 ); + actual.ci = new Float32Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': f32( 0.05 ), + 'pValue': f32( 0.0132 ), + 'statistic': f32( 2.4773 ), + 'nullValue': f32( 0.0 ), + 'xmean': f32( 3.7561 ), + 'ymean': f32( 3.0129 ), + 'ci': new Float32Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float32Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a method property', function test( t ) { + var results = new Float32Results(); + + t.strictEqual( results.method, 'Two-sample Z-test', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toString` method', function test( t ) { + var results; + var actual; + + results = new Float32Results(); + + actual = results.toString(); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + + actual = results.toString({ + 'decision': false + }); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toJSON` method', function test( t ) { + var results = new Float32Results(); + t.strictEqual( typeof results.toJSON, 'function', 'returns expected value' ); + t.strictEqual( typeof results.toJSON(), 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toDataView` method', function test( t ) { + var results = new Float32Results(); + t.strictEqual( typeof results.toDataView, 'function', 'returns expected value' ); + t.strictEqual( isDataView( results.toDataView() ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `name` property', function test( t ) { + t.strictEqual( typeof Float32Results.name, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has an `alignment` property', function test( t ) { + t.strictEqual( typeof Float32Results.alignment, 'number', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `byteLength` property', function test( t ) { + t.strictEqual( typeof Float32Results.byteLength, 'number', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `fields` property', function test( t ) { + t.strictEqual( isStringArray( Float32Results.fields ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `layout` property', function test( t ) { + t.strictEqual( typeof Float32Results.layout, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `bufferOf` method', function test( t ) { + t.strictEqual( typeof Float32Results.bufferOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `byteLengthOf` method', function test( t ) { + t.strictEqual( typeof Float32Results.byteLengthOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `byteOffsetOf` method', function test( t ) { + t.strictEqual( typeof Float32Results.byteOffsetOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `descriptionOf` method', function test( t ) { + t.strictEqual( typeof Float32Results.descriptionOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has an `isStruct` method', function test( t ) { + t.strictEqual( typeof Float32Results.isStruct, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `viewOf` method', function test( t ) { + t.strictEqual( typeof Float32Results.viewOf, 'function', 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/README.md b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/README.md new file mode 100644 index 000000000000..eff667632c85 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/README.md @@ -0,0 +1,429 @@ + + +# Float64Results + +> Create a two-sample Z-test double-precision floating-point results object. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +``` + +#### Float64Results( \[arg\[, byteOffset\[, byteLength]]] ) + +Returns a two-sample Z-test double-precision floating-point results object. + +```javascript +var results = new Float64Results(); +// returns {...} +``` + +The function supports the following parameters: + +- **arg**: an [`ArrayBuffer`][@stdlib/array/buffer] or a data object (_optional_). +- **byteOffset**: byte offset (_optional_). +- **byteLength**: maximum byte length (_optional_). + +A data object argument is an object having one or more of the following properties: + +- **rejected**: boolean indicating whether the null hypothesis was rejected. +- **alternative**: the alternative hypothesis (e.g., `'two-sided'`, `'less'`, or `'greater'`). +- **alpha**: significance level. +- **pValue**: p-value. +- **statistic**: test statistic. +- **ci**: confidence interval as a [`Float64Array`][@stdlib/array/float64]. +- **nullValue**: difference in means under the null hypothesis. +- **xmean**: sample mean of `x`. +- **ymean**: sample mean of `y`. + +#### Float64Results.prototype.rejected + +Boolean indicating whether the null hypothesis was rejected. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.rejected; +// returns +``` + +#### Float64Results.prototype.alternative + +The alternative hypothesis. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.alternative; +// returns +``` + +#### Float64Results.prototype.alpha + +Significance level. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.alpha; +// returns +``` + +#### Float64Results.prototype.pValue + +The test p-value. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.pValue; +// returns +``` + +#### Float64Results.prototype.statistic + +The test statistic. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.statistic; +// returns +``` + +#### Float64Results.prototype.ci + +Confidence interval. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.ci; +// returns +``` + +#### Float64Results.prototype.nullValue + +Difference in means under the null hypothesis. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.nullValue; +// returns +``` + +#### Float64Results.prototype.xmean + +Sample mean of `x`. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.xmean; +// returns +``` + +#### Float64Results.prototype.ymean + +Sample mean of `y`. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.ymean; +// returns +``` + +#### Float64Results.prototype.toString( \[options] ) + +Serializes a results object to a formatted string. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.toString(); +// returns +``` + +The method supports the following options: + +- **digits**: number of digits to display after decimal points. Default: `4`. +- **decision**: boolean indicating whether to show the test decision. Default: `true`. + +Example output: + +```text + +Two-sample Z-test + +Alternative hypothesis: True difference in means is less than 1.0 + + pValue: 0.0406 + statistic: 9.9901 + 95% confidence interval: [9.7821, 10.4451] + +Test Decision: Reject null in favor of alternative at 5% significance level + +``` + +#### Float64Results.prototype.toJSON( \[options] ) + +Serializes a results object as a JSON object. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.toJSON(); +// returns {...} +``` + +`JSON.stringify()` implicitly calls this method when stringifying a results instance. + +#### Float64Results.prototype.toDataView() + +Returns a [`DataView`][@stdlib/array/dataview] of a results object. + +```javascript +var results = new Float64Results(); +// returns {...} + +// ... + +var v = results.toDataView(); +// returns +``` + +
+ + + + + +
+ +## Notes + +- A results object is a [`struct`][@stdlib/dstructs/struct] providing a fixed-width composite data structure for storing two-sample Z-test results and providing an ABI-stable data layout for JavaScript-C interoperation. + +
+ + + + + +
+ +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); + +var results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/ztest/two-sample/results/float64.h" +``` + +#### stdlib_stats_ztest_two_sample_float64_results + +Structure for holding double-precision floating-point test results. + +```c +#include +#include + +struct stdlib_stats_ztest_two_sample_float64_results { + // Boolean indicating whether the null hypothesis was rejected: + bool rejected; + + // Alternative hypothesis: + int8_t alternative; + + // Significance level: + double alpha; + + // p-value: + double pValue; + + // Test statistic: + double statistic; + + // Confidence interval: + double ci[ 2 ]; + + // Difference in means under the null hypothesis: + double nullValue; + + // Sample mean of `x`: + double xmean; + + // Sample mean of `y`: + double ymean; +}; +``` + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/benchmark/benchmark.js new file mode 100644 index 000000000000..328377e909f0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/benchmark/benchmark.js @@ -0,0 +1,70 @@ +/** +* @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 isObject = require( '@stdlib/assert/is-object' ); +var pkg = require( './../package.json' ).name; +var Float64Results = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::constructor,new', function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new Float64Results(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::constructor,no_new', function benchmark( b ) { + var results; + var v; + var i; + + results = Float64Results; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = results(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/repl.txt new file mode 100644 index 000000000000..dad9ed58e824 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( [arg[, byteOffset[, byteLength]]] ) + Returns a two-sample Z-test double-precision floating-point results object. + + Parameters + ---------- + arg: Object|ArrayBuffer (optional) + ArrayBuffer or data object. + + byteOffset: integer (optional) + Byte offset. + + byteLength: integer (optional) + Maximum byte length. + + Returns + ------- + out: Object + Results object. + + Examples + -------- + > var r = new {{alias}}(); + > r.toString( { 'format': 'linear' } ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/index.d.ts new file mode 100644 index 000000000000..206100774968 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/index.d.ts @@ -0,0 +1,198 @@ +/* +* @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 + +/** +* Alternative hypothesis. +*/ +type Alternative = 'two-sided' | 'greater' | 'less'; + +/** +* Interface describing test results. +*/ +interface Results { + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected?: boolean; + + /** + * Alternative hypothesis. + */ + alternative?: Alternative; + + /** + * Significance level. + */ + alpha?: number; + + /** + * p-value. + */ + pValue?: number; + + /** + * Test statistic. + */ + statistic?: number; + + /** + * Confidence interval. + */ + ci?: Float64Array; + + /** + * Difference in means under the null hypothesis. + */ + nullValue?: number; + + /** + * Sample mean of `x`. + */ + xmean?: number; + + /** + * Sample mean of `y`. + */ + ymean?: number; +} + +/** +* Interface describing a results data structure. +*/ +declare class ResultsStruct { + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns results + */ + constructor( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ); + + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected: boolean; + + /** + * Alternative hypothesis. + */ + alternative: Alternative; + + /** + * Significance level. + */ + alpha: number; + + /** + * p-value. + */ + pValue: number; + + /** + * Test statistic. + */ + statistic: number; + + /** + * Confidence interval. + */ + ci: Float64Array; + + /** + * Difference in means under the null hypothesis. + */ + nullValue: number; + + /** + * Sample mean of `x`. + */ + xmean: number; + + /** + * Sample mean of `y`. + */ + ymean: number; + + /** + * Test method. + */ + method: string; +} + +/** +* Interface defining a results constructor which is both "newable" and "callable". +*/ +interface ResultsConstructor { + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns results object + */ + new( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ): ResultsStruct; + + /** + * Results constructor. + * + * @param arg - buffer or data object + * @param byteOffset - byte offset + * @param byteLength - maximum byte length + * @returns results object + */ + ( arg?: ArrayBuffer | Results, byteOffset?: number, byteLength?: number ): ResultsStruct; +} + +/** +* Returns a two-sample Z-test double-precision floating-point results object. +* +* @param arg - buffer or data object +* @param byteOffset - byte offset +* @param byteLength - maximum byte length +* @returns results object +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.0132; +* results.statistic = 2.4773; +* results.xmean = 3.7561; +* results.ymean = 3.0129; +* results.ci = new Float64Array( [ 0.1552, 1.3311 ] ); +* results.rejected = true; +* +* var str = results.toString(); +* // returns +*/ +declare var Results: ResultsConstructor; + + +// EXPORTS // + +export = Results; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/test.ts new file mode 100644 index 000000000000..d770dcca67d1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/docs/types/test.ts @@ -0,0 +1,39 @@ +/* +* @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 Results = require( './index' ); + + +// TESTS // + +// The function returns a results object... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r0 = new Results( {} ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r1 = new Results( new ArrayBuffer( 80 ) ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r2 = new Results( new ArrayBuffer( 80 ), 8 ); // $ExpectType ResultsStruct + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const r3 = new Results( new ArrayBuffer( 80 ), 8, 16 ); // $ExpectType ResultsStruct +} + +// TODO: add individual parameter tests diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/examples/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/examples/index.js new file mode 100644 index 000000000000..f7e8019a9e53 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/examples/index.js @@ -0,0 +1,39 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var Results = require( './../lib' ); + +var results = new Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 9.9983, 11.4123 ] ), + 'alternative': 'two-sided' +}); + +var str = results.toString({ + 'format': 'linear' +}); +console.log( str ); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/include/stdlib/stats/base/ztest/two-sample/results/float64.h b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/include/stdlib/stats/base/ztest/two-sample/results/float64.h new file mode 100644 index 000000000000..a5f147dee1fa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/include/stdlib/stats/base/ztest/two-sample/results/float64.h @@ -0,0 +1,57 @@ +/** +* @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. +*/ + +#ifndef STDLIB_STATS_BASE_ZTEST_TWO_SAMPLE_RESULTS_FLOAT64_H +#define STDLIB_STATS_BASE_ZTEST_TWO_SAMPLE_RESULTS_FLOAT64_H + +#include +#include + +/** +* Struct for storing test results. +*/ +struct stdlib_stats_ztest_two_sample_float64_results { + // Boolean indicating whether the null hypothesis was rejected: + bool rejected; + + // Alternative hypothesis: + int8_t alternative; + + // Significance level: + double alpha; + + // p-value: + double pValue; + + // Test statistic: + double statistic; + + // Confidence interval: + double ci[ 2 ]; + + // Difference in means under the null hypothesis: + double nullValue; + + // Sample mean of `x`: + double xmean; + + // Sample mean of `y`: + double ymean; +}; + +#endif // !STDLIB_STATS_BASE_ZTEST_TWO_SAMPLE_RESULTS_FLOAT64_H diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/index.js new file mode 100644 index 000000000000..df0e602f35ef --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/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'; + +/** +* Create a two-sample Z-test double-precision floating-point results object. +* +* @module @stdlib/stats/base/ztest/two-sample/results/float64 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.0132; +* results.statistic = 2.4773; +* results.xmean = 3.7561; +* results.ymean = 3.0129; +* results.ci = new Float64Array( [ 0.1552, 1.3311 ] ); +* results.rejected = true; +* +* var str = results.toString(); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/main.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/main.js new file mode 100644 index 000000000000..2ad08cf62b21 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/lib/main.js @@ -0,0 +1,63 @@ +/** +* @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 factory = require( '@stdlib/stats/base/ztest/two-sample/results/factory' ); + + +// MAIN // + +/** +* Returns a two-sample Z-test double-precision floating-point results object. +* +* @name Results +* @constructor +* @type {Function} +* @param {ArrayBuffer} [buffer] - underlying byte buffer +* @param {NonNegativeInteger} [byteOffset] - byte offset +* @param {NonNegativeInteger} [byteLength] - maximum byte length +* @returns {Results} results object +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var results = new Results(); +* // returns +* +* results.alternative = 'two-sided'; +* results.alpha = 0.05; +* results.nullValue = 0.0; +* results.pValue = 0.0132; +* results.statistic = 2.4773; +* results.xmean = 3.7561; +* results.ymean = 3.0129; +* results.ci = new Float64Array( [ 0.1552, 1.3311 ] ); +* results.rejected = true; +* +* var str = results.toString(); +* // returns +*/ +var Results = factory( 'float64' ); + + +// EXPORTS // + +module.exports = Results; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/manifest.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/manifest.json new file mode 100644 index 000000000000..844d692f6439 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/package.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/package.json new file mode 100644 index 000000000000..782c8f05e448 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/base/ztest/two-sample/results/float64", + "version": "0.0.0", + "description": "Create a two-sample Z-test double-precision floating-point results object.", + "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", + "include": "./include", + "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", + "stats", + "statistics", + "ztest", + "z-test", + "utilities", + "utility", + "utils", + "util", + "constructor", + "ctor", + "results" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/test/test.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/test/test.js new file mode 100644 index 000000000000..00f1e78bfc01 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/float64/test/test.js @@ -0,0 +1,506 @@ +/** +* @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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isDataView = require( '@stdlib/assert/is-dataview' ); +var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var Float64Array = require( '@stdlib/array/float64' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var Float64Results = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Float64Results, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ArrayBuffer or data object', function test( t ) { + var results; + var values; + var i; + + results = Float64Results; + + values = [ + '5', + 5, + NaN, + 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() { + results( value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not a nonnegative integer', function test( t ) { + var results; + var values; + var i; + + results = Float64Results; + + values = [ + '5', + -5, + 3.14, + NaN, + 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() { + results( new ArrayBuffer( 1024 ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not a nonnegative integer', function test( t ) { + var results; + var values; + var i; + + results = Float64Results; + + values = [ + '5', + -5, + 3.14, + NaN, + 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() { + results( new ArrayBuffer( 1024 ), 0, value ); + }; + } +}); + +tape( 'the function is a constructor which does not require the `new` operator', function test( t ) { + var results; + var res; + + results = Float64Results; + + res = results(); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + res = results( {} ); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + res = results( new ArrayBuffer( 1024 ) ); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + res = results( new ArrayBuffer( 1024 ), 0 ); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + res = results( new ArrayBuffer( 1024 ), 0, 1024 ); + t.strictEqual( res instanceof results, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object ', function test( t ) { + var expected; + var actual; + + actual = new Float64Results({ + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }); + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float64Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (no arguments)', function test( t ) { + var expected; + var actual; + + actual = new Float64Results(); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.0132; + actual.statistic = 2.4773; + actual.nullValue = 0.0; + actual.xmean = 3.7561; + actual.ymean = 3.0129; + actual.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float64Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (empty object)', function test( t ) { + var expected; + var actual; + + actual = new Float64Results( {} ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.0132; + actual.statistic = 2.4773; + actual.nullValue = 0.0; + actual.xmean = 3.7561; + actual.ymean = 3.0129; + actual.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float64Results, true, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (ArrayBuffer)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float64Results( buf ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.0132; + actual.statistic = 2.4773; + actual.nullValue = 0.0; + actual.xmean = 3.7561; + actual.ymean = 3.0129; + actual.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float64Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 0, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (ArrayBuffer, byteOffset)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float64Results( buf, 16 ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.0132; + actual.statistic = 2.4773; + actual.nullValue = 0.0; + actual.xmean = 3.7561; + actual.ymean = 3.0129; + actual.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float64Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor for a fixed-width results object (ArrayBuffer, byteOffset, byteLength)', function test( t ) { + var expected; + var actual; + var buf; + + buf = new ArrayBuffer( 1024 ); + actual = new Float64Results( buf, 16, 160 ); + + actual.rejected = true; + actual.alpha = 0.05; + actual.pValue = 0.0132; + actual.statistic = 2.4773; + actual.nullValue = 0.0; + actual.xmean = 3.7561; + actual.ymean = 3.0129; + actual.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + actual.alternative = 'two-sided'; + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided' + }; + + t.strictEqual( actual instanceof Float64Results, true, 'returns expected value' ); + t.strictEqual( actual.toDataView().buffer, buf, 'returns expected value' ); + t.strictEqual( actual.toDataView().byteOffset, 16, 'returns expected value' ); + t.strictEqual( actual.rejected, expected.rejected, 'returns expected value' ); + t.strictEqual( actual.alpha, expected.alpha, 'returns expected value' ); + t.strictEqual( actual.pValue, expected.pValue, 'returns expected value' ); + t.strictEqual( actual.statistic, expected.statistic, 'returns expected value' ); + t.strictEqual( actual.nullValue, expected.nullValue, 'returns expected value' ); + t.strictEqual( actual.xmean, expected.xmean, 'returns expected value' ); + t.strictEqual( actual.ymean, expected.ymean, 'returns expected value' ); + t.strictEqual( actual.alternative, expected.alternative, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( actual.ci, expected.ci ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a method property', function test( t ) { + var results = new Float64Results(); + + t.strictEqual( results.method, 'Two-sample Z-test', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toString` method', function test( t ) { + var results; + var actual; + + results = new Float64Results(); + + actual = results.toString(); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + + actual = results.toString({ + 'decision': false + }); + t.strictEqual( typeof actual, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toJSON` method', function test( t ) { + var results = new Float64Results(); + t.strictEqual( typeof results.toJSON, 'function', 'returns expected value' ); + t.strictEqual( typeof results.toJSON(), 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toDataView` method', function test( t ) { + var results = new Float64Results(); + t.strictEqual( typeof results.toDataView, 'function', 'returns expected value' ); + t.strictEqual( isDataView( results.toDataView() ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `name` property', function test( t ) { + t.strictEqual( typeof Float64Results.name, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has an `alignment` property', function test( t ) { + t.strictEqual( typeof Float64Results.alignment, 'number', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `byteLength` property', function test( t ) { + t.strictEqual( typeof Float64Results.byteLength, 'number', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `fields` property', function test( t ) { + t.strictEqual( isStringArray( Float64Results.fields ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `layout` property', function test( t ) { + t.strictEqual( typeof Float64Results.layout, 'string', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `bufferOf` method', function test( t ) { + t.strictEqual( typeof Float64Results.bufferOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `byteLengthOf` method', function test( t ) { + t.strictEqual( typeof Float64Results.byteLengthOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `byteOffsetOf` method', function test( t ) { + t.strictEqual( typeof Float64Results.byteOffsetOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `descriptionOf` method', function test( t ) { + t.strictEqual( typeof Float64Results.descriptionOf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has an `isStruct` method', function test( t ) { + t.strictEqual( typeof Float64Results.isStruct, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor has a `viewOf` method', function test( t ) { + t.strictEqual( typeof Float64Results.viewOf, 'function', 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/types/index.d.ts index 2bfa92386959..791772e360ad 100644 --- a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/struct-factory/docs/types/index.d.ts @@ -53,7 +53,7 @@ interface Results { ci?: T; /** - * Value of the mean under the null hypothesis. + * Difference in means under the null hypothesis. */ nullValue?: number; @@ -113,7 +113,7 @@ declare class Struct { ci: T; /** - * Value of the mean under the null hypothesis + * Difference in means under the null hypothesis. */ nullValue: number; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/README.md b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/README.md new file mode 100644 index 000000000000..319a18b97994 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/README.md @@ -0,0 +1,129 @@ + + +# res2json + +> Serialize a two-sample Z-test results object as a JSON object. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var res2json = require( '@stdlib/stats/base/ztest/two-sample/results/to-json' ); +``` + +#### res2json( results ) + +Serializes a two-sample Z-test results object as a JSON object. + +```javascript +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); + +var results = new Float64Results(); + +// ... + +var o = res2json( results ); +// returns {...} +``` + +The function supports the following parameters: + +- **results**: two-sample Z-test results object. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var Float64Array = require( '@stdlib/array/float64' ); +var res2json = require( '@stdlib/stats/base/ztest/two-sample/results/to-json' ); + +var results = new Float64Results(); +results.rejected = true; +results.alpha = 0.05; +results.pValue = 0.0132; +results.statistic = 2.4773; +results.nullValue = 0.0; +results.xmean = 3.7561; +results.ymean = 3.0129; +results.ci = new Float64Array( [ 0.1552, 1.3311 ] ); +results.alternative = resolveEnum( 'two-sided' ); + +var o = res2json( results ); +console.log( o ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/benchmark/benchmark.js new file mode 100644 index 000000000000..ea0c5fe26db8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/benchmark/benchmark.js @@ -0,0 +1,55 @@ +/** +* @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 Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var pkg = require( './../package.json' ).name; +var res2json = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var v; + var i; + + values = [ + new Float64Results(), + new Float64Results() + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = res2json( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isPlainObject( v ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/repl.txt new file mode 100644 index 000000000000..5391ee181405 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/repl.txt @@ -0,0 +1,34 @@ + +{{alias}}( results ) + Serializes a two-sample Z-test results object as a JSON object. + + Parameters + ---------- + results: Object + Two-sample Z-test results object. + + Returns + ------- + out: Object + Serialized object. + + Examples + -------- + > var res = { + ... 'rejected': true, + ... 'alpha': 0.05, + ... 'pValue': 0.0132, + ... 'statistic': 2.4773, + ... 'nullValue': 0.0, + ... 'xmean': 3.7561, + ... 'ymean': 3.0129, + ... 'ci': new {{alias:@stdlib/array/float64}}( [ 0.1552, 1.3311 ] ), + ... 'alternative': 'two-sided', + ... 'method': 'Two-sample Z-test' + ... }; + > var o = {{alias}}( res ) + {...} + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/index.d.ts new file mode 100644 index 000000000000..a71a6a0b7234 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/index.d.ts @@ -0,0 +1,106 @@ +/* +* @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 + +/** +* Interface describing a results object. +*/ +interface Results { + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected: boolean; + + /** + * Alternative hypothesis. + */ + alternative: string; + + /** + * Significance level. + */ + alpha: number; + + /** + * p-value. + */ + pValue: number; + + /** + * Test statistic. + */ + statistic: number; + + /** + * Confidence interval. + */ + ci: Float64Array | Float32Array; + + /** + * Difference in means under the null hypothesis. + */ + nullValue: number; + + /** + * Sample mean of `x`. + */ + xmean: number; + + /** + * Sample mean of `y`. + */ + ymean: number; + + /** + * Test method. + */ + method: string; +} + +/** +* Serializes a two-sample Z-test results object as a JSON object. +* +* @param results - two-sample Z-test results object +* @returns serialized object +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var results = { +* 'rejected': true, +* 'alpha': 0.05, +* 'pValue': 0.0132, +* 'statistic': 2.4773, +* 'nullValue': 0.0, +* 'xmean': 3.7561, +* 'ymean': 3.0129, +* 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), +* 'alternative': 'two-sided', +* 'method': 'Two-sample Z-test' +* }; +* +* var obj = res2json( results ); +* // returns {...} +*/ +declare function res2json( results: Results ): Results; + + +// EXPORTS // + +export = res2json; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/test.ts new file mode 100644 index 000000000000..e7b93c0a8e16 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/docs/types/test.ts @@ -0,0 +1,51 @@ +/* +* @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 res2json = require( './index' ); + + +// TESTS // + +// The function returns an object... +{ + var res = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided', + 'method': 'Two-sample Z-test' + }; + res2json( res ); // $ExpectType Results +} + +// The compiler throws an error if not provided a results object... +{ + res2json( 10 ); // $ExpectError + res2json( true ); // $ExpectError + res2json( false ); // $ExpectError + res2json( null ); // $ExpectError + res2json( undefined ); // $ExpectError + res2json( [] ); // $ExpectError + res2json( {} ); // $ExpectError + res2json( ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/examples/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/examples/index.js new file mode 100644 index 000000000000..21d78ee398b6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/examples/index.js @@ -0,0 +1,38 @@ +/** +* @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 Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var Float64Array = require( '@stdlib/array/float64' ); +var res2json = require( './../lib' ); + +var results = new Float64Results(); +results.rejected = true; +results.alpha = 0.05; +results.pValue = 0.0132; +results.statistic = 2.4773; +results.nullValue = 0.0; +results.xmean = 3.7561; +results.ymean = 3.0129; +results.ci = new Float64Array( [ 0.1552, 1.3311 ] ); +results.alternative = resolveEnum( 'two-sided' ); + +var o = res2json( results ); +console.log( o ); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/index.js new file mode 100644 index 000000000000..bab086b5fe5d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/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'; + +/** +* Serialize a two-sample Z-test results object as a JSON object. +* +* @module @stdlib/stats/base/ztest/two-sample/results/to-json +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var res2json = require( '@stdlib/stats/base/ztest/two-sample/results/to-json' ); +* +* var results = { +* 'rejected': true, +* 'alpha': 0.05, +* 'pValue': 0.0132, +* 'statistic': 2.4773, +* 'nullValue': 0.0, +* 'xmean': 3.7561, +* 'ymean': 3.0129, +* 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), +* 'alternative': 'two-sided', +* 'method': 'Two-sample Z-test' +* }; +* +* var obj = res2json( results ); +* // returns {...} +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/main.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/main.js new file mode 100644 index 000000000000..9f7e61b8c354 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/lib/main.js @@ -0,0 +1,71 @@ +/** +* @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 typedarray2json = require( '@stdlib/array/to-json' ); + + +// MAIN // + +/** +* Serializes a two-sample Z-test results object as a JSON object. +* +* @param {Object} results - two-sample Z-test results object +* @returns {Object} serialized object +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var results = { +* 'rejected': true, +* 'alpha': 0.05, +* 'pValue': 0.0132, +* 'statistic': 2.4773, +* 'nullValue': 0.0, +* 'xmean': 3.7561, +* 'ymean': 3.0129, +* 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), +* 'alternative': 'two-sided', +* 'method': 'Two-sample Z-test' +* }; +* +* var obj = toJSON( results ); +* // returns {...} +*/ +function toJSON( results ) { + return { + 'rejected': results.rejected, + 'alpha': results.alpha, + 'pValue': results.pValue, + 'statistic': results.statistic, + 'nullValue': results.nullValue, + 'xmean': results.xmean, + 'ymean': results.ymean, + 'ci': typedarray2json( results.ci ), + 'alternative': results.alternative, + 'method': results.method + }; +} + + +// EXPORTS // + +module.exports = toJSON; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/package.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/package.json new file mode 100644 index 000000000000..ca80c296b45a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/stats/base/ztest/two-sample/results/to-json", + "version": "0.0.0", + "description": "Serialize a two-sample Z-test results object as a JSON object.", + "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", + "stats", + "statistics", + "ztest", + "z-test", + "utilities", + "utility", + "utils", + "util", + "json" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/test/test.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/test/test.js new file mode 100644 index 000000000000..5e45d693d8eb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-json/test/test.js @@ -0,0 +1,73 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var res2json = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof res2json, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function serializes a results object to JSON', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.0132; + value.statistic = 2.4773; + value.nullValue = 0.0; + value.xmean = 3.7561; + value.ymean = 3.0129; + value.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + value.alternative = resolveEnum( 'two-sided' ); + + expected = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': { + 'type': 'Float64Array', + 'data': [ 0.1552, 1.3311 ] + }, + 'alternative': 'two-sided', + 'method': 'Two-sample Z-test' + }; + + actual = res2json( value ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/README.md b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/README.md new file mode 100644 index 000000000000..7abc2b2b45e3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/README.md @@ -0,0 +1,153 @@ + + +# res2str + +> Serialize a two-sample Z-test results object as a formatted string. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var res2str = require( '@stdlib/stats/base/ztest/two-sample/results/to-string' ); +``` + +#### res2str( results\[, options] ) + +Serializes a two-sample Z-test results object as a formatted string. + +```javascript +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); + +var results = new Float64Results(); + +// ... + +var s = res2str( results ); +// returns +``` + +The function supports the following parameters: + +- **results**: two-sample Z-test results object. +- **options**: function options. + +The function supports the following options: + +- **digits**: number of digits to display after decimal points. Default: `4`. +- **decision**: boolean indicating whether to show the test decision. Default: `true`. + +
+ + + + + +
+ +## Notes + +- Example output: + + ```text + + Two-sample Z-test + + Alternative hypothesis: True difference in means is less than 1.0 + + pValue: 0.0406 + statistic: 9.9901 + 95% confidence interval: [9.7821, 10.4451] + + Test Decision: Reject null in favor of alternative at 5% significance level + + ``` + +
+ + + + + +
+ +## Examples + + + +```javascript +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var Float64Array = require( '@stdlib/array/float64' ); +var res2str = require( '@stdlib/stats/base/ztest/two-sample/results/to-string' ); + +var results = new Float64Results(); +results.rejected = true; +results.alpha = 0.05; +results.pValue = 0.0132; +results.statistic = 2.4773; +results.nullValue = 0.0; +results.xmean = 3.7561; +results.ymean = 3.0129; +results.ci = new Float64Array( [ 0.1552, 1.3311 ] ); +results.alternative = resolveEnum( 'two-sided' ); + +var s = res2str( results ); +console.log( s ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/benchmark/benchmark.js new file mode 100644 index 000000000000..2ae07f20f27b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/benchmark/benchmark.js @@ -0,0 +1,55 @@ +/** +* @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 Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var res2str = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var v; + var i; + + values = [ + new Float64Results(), + new Float64Results() + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = res2str( values[ i%values.length ] ); + if ( typeof v !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/repl.txt new file mode 100644 index 000000000000..64442e8004a3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/repl.txt @@ -0,0 +1,43 @@ + +{{alias}}( results[, options] ) + Serializes a two-sample Z-test results object as a formatted string. + + Parameters + ---------- + results: Object + Two-sample Z-test results object. + + options: Object (optional) + Function options. + + options.digits: number (optional) + Number of digits to display after decimal points. Default: 4. + + options.decision: boolean (optional) + Boolean indicating whether to show the test decision. Default: true. + + Returns + ------- + out: string + Serialized results. + + Examples + -------- + > var res = { + ... 'rejected': true, + ... 'alpha': 0.05, + ... 'pValue': 0.0132, + ... 'statistic': 2.4773, + ... 'nullValue': 0.0, + ... 'xmean': 3.7561, + ... 'ymean': 3.0129, + ... 'ci': new {{alias:@stdlib/array/float64}}( [ 0.1552, 1.3311 ] ), + ... 'alternative': 'two-sided', + ... 'method': 'Two-sample Z-test' + ... }; + > var s = {{alias}}( res ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/index.d.ts new file mode 100644 index 000000000000..e88545d3d774 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/index.d.ts @@ -0,0 +1,142 @@ +/* +* @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 + +/** +* Interface describing a results object. +*/ +interface Results { + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected: boolean; + + /** + * Alternative hypothesis. + */ + alternative: string; + + /** + * Significance level. + */ + alpha: number; + + /** + * p-value. + */ + pValue: number; + + /** + * Test statistic. + */ + statistic: number; + + /** + * Confidence interval. + */ + ci: Float64Array | Float32Array; + + /** + * Difference in means under the null hypothesis. + */ + nullValue: number; + + /** + * Sample mean of `x`. + */ + xmean: number; + + /** + * Sample mean of `y`. + */ + ymean: number; + + /** + * Test method. + */ + method: string; +} + +/** +* Interface describing function options. +*/ +interface Options { + /** + * Number of digits to display after decimal points. Default: 4. + */ + digits?: number; + + /** + * Boolean indicating whether to show the test decision. + */ + decision?: boolean; +} + +/** +* Serializes a two-sample Z-test results object as a formatted string. +* +* ## Notes +* +* - Example output: +* +* ```text +* +* Two-sample Z-test +* +* Alternative hypothesis: True difference in means is less than 1.0 +* +* pValue: 0.0406 +* statistic: 9.9901 +* 95% confidence interval: [9.7821, 10.4451] +* +* Test Decision: Reject null in favor of alternative at 5% significance level +* +* ``` +* +* @param results - two-sample Z-test results object +* @param options - options object +* @param options.digits - number of digits to display after decimal points +* @param options.decision - boolean indicating whether to show the test decision +* @returns serialized results +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var results = { +* 'rejected': true, +* 'alpha': 0.05, +* 'pValue': 0.0132, +* 'statistic': 2.4773, +* 'nullValue': 0.0, +* 'xmean': 3.7561, +* 'ymean': 3.0129, +* 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), +* 'alternative': 'two-sided', +* 'method': 'Two-sample Z-test' +* }; +* +* var str = res2str( results ); +* // returns +*/ +declare function res2str( results: Results, options?: Options ): string; + + +// EXPORTS // + +export = res2str; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/test.ts new file mode 100644 index 000000000000..6b854e121eed --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/docs/types/test.ts @@ -0,0 +1,134 @@ +/* +* @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 res2str = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + var res = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided', + 'method': 'Two-sample Z-test' + }; + res2str( res ); // $ExpectType string + res2str( res, {} ); // $ExpectType string +} + +// The compiler throws an error if provided first argument which is not a results object... +{ + res2str( '10' ); // $ExpectError + res2str( 10 ); // $ExpectError + res2str( true ); // $ExpectError + res2str( false ); // $ExpectError + res2str( null ); // $ExpectError + res2str( undefined ); // $ExpectError + res2str( [] ); // $ExpectError + res2str( {} ); // $ExpectError + res2str( ( x: number ): number => x ); // $ExpectError + + res2str( '10', {} ); // $ExpectError + res2str( 10, {} ); // $ExpectError + res2str( true, {} ); // $ExpectError + res2str( false, {} ); // $ExpectError + res2str( null, {} ); // $ExpectError + res2str( undefined, {} ); // $ExpectError + res2str( [], {} ); // $ExpectError + res2str( {}, {} ); // $ExpectError + res2str( ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if provided a second argument which is not an object... +{ + var res = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided', + 'method': 'Two-sample Z-test' + }; + + res2str( res, '10' ); // $ExpectError + res2str( res, 10 ); // $ExpectError + res2str( res, true ); // $ExpectError + res2str( res, false ); // $ExpectError + res2str( res, null ); // $ExpectError + res2str( res, [] ); // $ExpectError + res2str( res, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if provided a `digits` option which is not a number... +{ + var res = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided', + 'method': 'Two-sample Z-test' + }; + + res2str( res, { 'digits': '10' } ); // $ExpectError + res2str( res, { 'digits': true } ); // $ExpectError + res2str( res, { 'digits': false } ); // $ExpectError + res2str( res, { 'digits': null } ); // $ExpectError + res2str( res, { 'digits': [] } ); // $ExpectError + res2str( res, { 'digits': {} } ); // $ExpectError + res2str( res, { 'digits': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if provided a `decision` option which is not a boolean... +{ + var res = { + 'rejected': true, + 'alpha': 0.05, + 'pValue': 0.0132, + 'statistic': 2.4773, + 'nullValue': 0.0, + 'xmean': 3.7561, + 'ymean': 3.0129, + 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), + 'alternative': 'two-sided', + 'method': 'Two-sample Z-test' + }; + + res2str( res, { 'decision': '10' } ); // $ExpectError + res2str( res, { 'decision': 10 } ); // $ExpectError + res2str( res, { 'decision': null } ); // $ExpectError + res2str( res, { 'decision': [] } ); // $ExpectError + res2str( res, { 'decision': {} } ); // $ExpectError + res2str( res, { 'decision': ( x: number ): number => x } ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/examples/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/examples/index.js new file mode 100644 index 000000000000..90fab048b145 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/examples/index.js @@ -0,0 +1,38 @@ +/** +* @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 Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var Float64Array = require( '@stdlib/array/float64' ); +var res2str = require( './../lib' ); + +var results = new Float64Results(); +results.rejected = true; +results.alpha = 0.05; +results.pValue = 0.0132; +results.statistic = 2.4773; +results.nullValue = 0.0; +results.xmean = 3.7561; +results.ymean = 3.0129; +results.ci = new Float64Array( [ 0.1552, 1.3311 ] ); +results.alternative = resolveEnum( 'two-sided' ); + +var s = res2str( results ); +console.log( s ); diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/index.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/index.js new file mode 100644 index 000000000000..b373105a7e17 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/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'; + +/** +* Serialize a two-sample Z-test results object as a formatted string. +* +* @module @stdlib/stats/base/ztest/two-sample/results/to-string +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var res2str = require( '@stdlib/stats/base/ztest/two-sample/results/to-string' ); +* +* var results = { +* 'rejected': true, +* 'alpha': 0.05, +* 'pValue': 0.0132, +* 'statistic': 2.4773, +* 'nullValue': 0.0, +* 'xmean': 3.7561, +* 'ymean': 3.0129, +* 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), +* 'alternative': 'two-sided', +* 'method': 'Two-sample Z-test' +* }; +* +* var str = res2str( results ); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/main.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/main.js new file mode 100644 index 000000000000..f8060a592ffd --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/lib/main.js @@ -0,0 +1,144 @@ +/** +* @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 isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ); +var isObject = require( '@stdlib/assert/is-plain-object' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Serializes a two-sample Z-test results object as a formatted string. +* +* ## Notes +* +* - Example output: +* +* ```text +* +* Two-sample Z-test +* +* Alternative hypothesis: True differences in means is less than 1.0 +* +* pValue: 0.0406 +* statistic: 9.9901 +* 95% confidence interval: [9.7821, 10.4451] +* +* Test Decision: Reject null in favor of alternative at 5% significance level +* +* ``` +* +* @param {Object} results - two-sample Z-test results object +* @param {Options} [opts] - options object +* @param {PositiveInteger} [opts.digits=4] - number of digits to display after decimal points +* @param {boolean} [opts.decision=true] - boolean indicating whether to show the test decision +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @returns {string} serialized results +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var results = { +* 'rejected': true, +* 'alpha': 0.05, +* 'pValue': 0.0132, +* 'statistic': 2.4773, +* 'nullValue': 0.0, +* 'xmean': 3.7561, +* 'ymean': 3.0129, +* 'ci': new Float64Array( [ 0.1552, 1.3311 ] ), +* 'alternative': 'two-sided', +* 'method': 'Two-sample Z-test' +* }; +* +* var str = toString( results ); +* // returns +*/ +function toString( results, opts ) { // eslint-disable-line stdlib/no-redeclare + var decision; + var level; + var dgts; + var out; + var alt; + var ci; + + dgts = 4; + decision = true; + if ( arguments.length > 1 ) { + if ( !isObject( opts ) ) { + throw new TypeError( format( 'invalid argument. Must provide an object. Value: `%s`.', opts ) ); + } + if ( hasOwnProp( opts, 'digits' ) ) { + if ( !isPositiveInteger( opts.digits ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'digits', opts.digits ) ); + } + dgts = opts.digits; + } + if ( hasOwnProp( opts, 'decision' ) ) { + if ( !isBoolean( opts.decision ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'decision', opts.decision ) ); + } + decision = opts.decision; + } + } + switch ( results.alternative ) { + case 'less': + alt = 'less than'; + break; + case 'greater': + alt = 'greater than'; + break; + case 'two-sided': + default: + alt = 'not equal to'; + break; + } + + level = ( 1.0 - results.alpha ) * 100; + ci = results.ci; + + out = [ + '', + results.method, + '', + format( 'Alternative hypothesis: True difference in means is %s %0.'+dgts+'f', alt, results.nullValue ), + '', + format( ' pValue: %0.'+dgts+'f', results.pValue ), + format( ' statistic: %0.'+dgts+'f', results.statistic ), + format( ' %.'+dgts+'f%% confidence interval: [%0.'+dgts+'f, %0.'+dgts+'f]', level, ci[ 0 ], ci[ 1 ] ), + '' + ]; + if ( decision ) { + out.push( format( 'Test Decision: %s null in favor of alternative at %.'+dgts+'f%% significance level', ( results.rejected ) ? 'Reject' : 'Fail to reject', 100-level ) ); + out.push( '' ); + } + return out.join( '\n' ); +} + + +// EXPORTS // + +module.exports = toString; diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/package.json b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/package.json new file mode 100644 index 000000000000..42969fadb073 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/stats/base/ztest/two-sample/results/to-string", + "version": "0.0.0", + "description": "Serialize a two-sample Z-test results object as a formatted string.", + "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", + "stats", + "statistics", + "ztest", + "z-test", + "utilities", + "utility", + "utils", + "util", + "string" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/test/test.js b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/test/test.js new file mode 100644 index 000000000000..520260bc68ce --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ztest/two-sample/results/to-string/test/test.js @@ -0,0 +1,431 @@ +/** +* @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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var Float64Array = require( '@stdlib/array/float64' ); +var Float64Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var res2str = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof res2str, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { + var results; + var values; + var i; + + results = new Float64Results(); + + values = [ + '5', + 5, + NaN, + 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() { + res2str( results, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `digits` option which is not a positive integer', function test( t ) { + var results; + var values; + var i; + + results = new Float64Results(); + + values = [ + '5', + -5, + NaN, + 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() { + res2str( results, { + 'digits': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `decision` option which is not a boolean', function test( t ) { + var results; + var values; + var i; + + results = new Float64Results(); + + values = [ + '5', + -5, + NaN, + 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() { + res2str( results, { + 'decision': value + }); + }; + } +}); + +tape( 'the function serializes a results object to a string (rejected)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.0132; + value.statistic = 2.4773; + value.nullValue = 0.0; + value.xmean = 3.7561; + value.ymean = 3.0129; + value.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + value.alternative = resolveEnum( 'two-sided' ); + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True difference in means is not equal to 0.0000', + '', + ' pValue: 0.0132', + ' statistic: 2.4773', + ' 95.0000% confidence interval: [0.1552, 1.3311]', + '', + 'Test Decision: Reject null in favor of alternative at 5.0000% significance level', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a results object to a string (not rejected)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = false; + value.alpha = 0.05; + value.pValue = 0.0132; + value.statistic = 2.4773; + value.nullValue = 0.0; + value.xmean = 3.7561; + value.ymean = 3.0129; + value.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + value.alternative = resolveEnum( 'two-sided' ); + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True difference in means is not equal to 0.0000', + '', + ' pValue: 0.0132', + ' statistic: 2.4773', + ' 95.0000% confidence interval: [0.1552, 1.3311]', + '', + 'Test Decision: Fail to reject null in favor of alternative at 5.0000% significance level', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a results object to a string (two-sided)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.0132; + value.statistic = 2.4773; + value.nullValue = 0.0; + value.xmean = 3.7561; + value.ymean = 3.0129; + value.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + value.alternative = resolveEnum( 'two-sided' ); + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True difference in means is not equal to 0.0000', + '', + ' pValue: 0.0132', + ' statistic: 2.4773', + ' 95.0000% confidence interval: [0.1552, 1.3311]', + '', + 'Test Decision: Reject null in favor of alternative at 5.0000% significance level', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a results object to a string (less)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.0132; + value.statistic = 2.4773; + value.nullValue = 0.0; + value.xmean = 3.7561; + value.ymean = 3.0129; + value.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + value.alternative = resolveEnum( 'less' ); + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True difference in means is less than 0.0000', + '', + ' pValue: 0.0132', + ' statistic: 2.4773', + ' 95.0000% confidence interval: [0.1552, 1.3311]', + '', + 'Test Decision: Reject null in favor of alternative at 5.0000% significance level', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes a results object to a string (greater)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.0132; + value.statistic = 2.4773; + value.nullValue = 0.0; + value.xmean = 3.7561; + value.ymean = 3.0129; + value.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + value.alternative = resolveEnum( 'greater' ); + + actual = res2str( value ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True difference in means is greater than 0.0000', + '', + ' pValue: 0.0132', + ' statistic: 2.4773', + ' 95.0000% confidence interval: [0.1552, 1.3311]', + '', + 'Test Decision: Reject null in favor of alternative at 5.0000% significance level', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports displaying the test decision (decision=true)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.0132; + value.statistic = 2.4773; + value.nullValue = 0.0; + value.xmean = 3.7561; + value.ymean = 3.0129; + value.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + value.alternative = resolveEnum( 'two-sided' ); + + actual = res2str( value, { + 'decision': true + }); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True difference in means is not equal to 0.0000', + '', + ' pValue: 0.0132', + ' statistic: 2.4773', + ' 95.0000% confidence interval: [0.1552, 1.3311]', + '', + 'Test Decision: Reject null in favor of alternative at 5.0000% significance level', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports not displaying the test decision (decision=false)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.0132; + value.statistic = 2.4773; + value.nullValue = 0.0; + value.xmean = 3.7561; + value.ymean = 3.0129; + value.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + value.alternative = resolveEnum( 'less' ); + + actual = res2str( value, { + 'decision': false + }); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True difference in means is less than 0.0000', + '', + ' pValue: 0.0132', + ' statistic: 2.4773', + ' 95.0000% confidence interval: [0.1552, 1.3311]', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the number of displayed digits (digits=2)', function test( t ) { + var expected; + var actual; + var value; + + value = new Float64Results(); + value.rejected = true; + value.alpha = 0.05; + value.pValue = 0.0132; + value.statistic = 2.4773; + value.nullValue = 0.0; + value.xmean = 3.7561; + value.ymean = 3.0129; + value.ci = new Float64Array( [ 0.1552, 1.3311 ] ); + value.alternative = resolveEnum( 'two-sided' ); + + actual = res2str( value, { + 'digits': 2 + }); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + + expected = [ + '', + 'Two-sample Z-test', + '', + 'Alternative hypothesis: True difference in means is not equal to 0.00', + '', + ' pValue: 0.01', + ' statistic: 2.48', + ' 95.00% confidence interval: [0.16, 1.33]', + '', + 'Test Decision: Reject null in favor of alternative at 5.00% significance level', + '' + ].join( '\n' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); From 628566c624637bfc908595ab492f3398634c5544 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 13:43:56 +0000 Subject: [PATCH 06/32] feat: add `stats/strided/varianceyc` Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../stats/strided/varianceyc/README.md | 265 +++++++++++++ .../strided/varianceyc/benchmark/benchmark.js | 96 +++++ .../varianceyc/benchmark/benchmark.ndarray.js | 96 +++++ .../docs/img/equation_population_mean.svg | 42 ++ .../docs/img/equation_population_variance.svg | 54 +++ .../docs/img/equation_sample_mean.svg | 43 ++ .../img/equation_unbiased_sample_variance.svg | 61 +++ .../stats/strided/varianceyc/docs/repl.txt | 114 ++++++ .../strided/varianceyc/docs/types/index.d.ts | 96 +++++ .../strided/varianceyc/docs/types/test.ts | 190 +++++++++ .../strided/varianceyc/examples/index.js | 30 ++ .../stats/strided/varianceyc/lib/accessors.js | 88 +++++ .../stats/strided/varianceyc/lib/index.js | 59 +++ .../stats/strided/varianceyc/lib/main.js | 59 +++ .../stats/strided/varianceyc/lib/ndarray.js | 92 +++++ .../stats/strided/varianceyc/package.json | 75 ++++ .../stats/strided/varianceyc/test/test.js | 38 ++ .../strided/varianceyc/test/test.main.js | 371 ++++++++++++++++++ .../strided/varianceyc/test/test.ndarray.js | 359 +++++++++++++++++ 19 files changed, 2228 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_population_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_population_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_sample_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_unbiased_sample_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/test/test.main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/varianceyc/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/README.md b/lib/node_modules/@stdlib/stats/strided/varianceyc/README.md new file mode 100644 index 000000000000..d19a26b562d7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/README.md @@ -0,0 +1,265 @@ + + +# varianceyc + +> Calculate the [variance][variance] of a strided array using a one-pass algorithm proposed by Youngs and Cramer. + +
+ +The population [variance][variance] of a finite size population of size `N` is given by + + + +```math +\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 +``` + + + + + +where the population mean is given by + + + +```math +\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i +``` + + + + + +Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, + + + +```math +s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 +``` + + + + + +where the sample mean is given by + + + +```math +\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + + + +The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. + +
+ + + +
+ +## Usage + +```javascript +var varianceyc = require( '@stdlib/stats/strided/varianceyc' ); +``` + +#### varianceyc( N, correction, x, strideX ) + +Computes the [variance][variance] of a strided array using a one-pass algorithm proposed by Youngs and Cramer. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; + +var v = varianceyc( x.length, 1.0, x, 1 ); +// returns ~4.3333 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, + +```javascript +var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; + +var v = varianceyc( 4, 1.0, x, 2 ); +// returns 6.25 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var v = varianceyc( 4, 1.0, x1, 2 ); +// returns 6.25 +``` + +#### varianceyc.ndarray( N, correction, x, strideX, offsetX ) + +Computes the [variance][variance] of a strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; + +var v = varianceyc.ndarray( x.length, 1.0, x, 1, 0 ); +// returns ~4.33333 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element + +```javascript +var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; + +var v = varianceyc.ndarray( 4, 1.0, x, 2, 1 ); +// returns 6.25 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `NaN`. +- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. +- Depending on the environment, the typed versions ([`dvarianceyc`][@stdlib/stats/strided/dvarianceyc], [`svarianceyc`][@stdlib/stats/strided/svarianceyc], etc.) are likely to be significantly more performant. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var varianceyc = require( '@stdlib/stats/strided/varianceyc' ); + +var x = uniform( 10, -50.0, 50.0, { + 'dtype': 'generic' +}); +console.log( x ); + +var v = varianceyc( x.length, 1.0, x, 1 ); +console.log( v ); +``` + +
+ + + +* * * + +
+ +## References + +- Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826][@youngs:1971a]. + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/varianceyc/benchmark/benchmark.js new file mode 100644 index 000000000000..4cf64da5f3d4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/benchmark/benchmark.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var varianceyc = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = varianceyc( x.length, 1.0, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/varianceyc/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..c760ff42df7f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/benchmark/benchmark.ndarray.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var varianceyc = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = varianceyc( x.length, 1.0, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_population_mean.svg new file mode 100644 index 000000000000..4bbdf0d2a56f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_population_mean.svg @@ -0,0 +1,42 @@ + +mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_population_variance.svg new file mode 100644 index 000000000000..4130ba0750d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_population_variance.svg @@ -0,0 +1,54 @@ + +sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_sample_mean.svg new file mode 100644 index 000000000000..aea7a5f6687a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_sample_mean.svg @@ -0,0 +1,43 @@ + +x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_unbiased_sample_variance.svg new file mode 100644 index 000000000000..1ae1283e7fb1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/img/equation_unbiased_sample_variance.svg @@ -0,0 +1,61 @@ + +s squared equals 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 + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/repl.txt new file mode 100644 index 000000000000..2511d4ec7df5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/repl.txt @@ -0,0 +1,114 @@ + +{{alias}}( N, correction, x, strideX ) + Computes the variance of a strided array using a one-pass algorithm proposed + by Youngs and Cramer. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns `NaN`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length for `x`. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > {{alias}}( x.length, 1.0, x, 1 ) + ~4.3333 + + // Using `N` and stride parameters: + > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; + > {{alias}}( 3, 1.0, x, 2 ) + ~4.3333 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, 1.0, x1, 2 ) + ~4.3333 + + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) + Computes the variance of a strided array using a one-pass algorithm proposed + by Youngs and Cramer and alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > {{alias}}.ndarray( x.length, 1.0, x, 1, 0 ) + ~4.3333 + + // Using offset parameter: + > var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; + > {{alias}}.ndarray( 3, 1.0, x, 2, 1 ) + ~4.3333 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/types/index.d.ts new file mode 100644 index 000000000000..de3b1949ee4b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/types/index.d.ts @@ -0,0 +1,96 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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 + +/// + +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `varianceyc`. +*/ +interface Routine { + /** + * Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length for `x` + * @returns variance + * + * @example + * var x = [ 1.0, -2.0, 2.0 ]; + * + * var v = varianceyc( x.length, 1.0, x, 1 ); + * // returns ~4.3333 + */ + ( N: number, correction: number, x: InputArray, strideX: number ): number; + + /** + * Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @returns variance + * + * @example + * var x = [ 1.0, -2.0, 2.0 ]; + * + * var v = varianceyc.ndarray( x.length, 1.0, x, 1, 0 ); + * // returns ~4.3333 + */ + ndarray( N: number, correction: number, x: InputArray, strideX: number, offsetX: number ): number; +} + +/** +* Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. +* +* @param N - number of indexed elements +* @param correction - degrees of freedom adjustment +* @param x - input array +* @param strideX - stride length for `x` +* @returns variance +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = varianceyc( x.length, 1.0, x, 1 ); +* // returns ~4.3333 +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = varianceyc.ndarray( x.length, 1.0, x, 1, 0 ); +* // returns ~4.3333 +*/ +declare var varianceyc: Routine; + + +// EXPORTS // + +export = varianceyc; diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/types/test.ts new file mode 100644 index 000000000000..cae7d268af9d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/docs/types/test.ts @@ -0,0 +1,190 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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 AccessorArray = require( '@stdlib/array/base/accessor' ); +import varianceyc = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Float64Array( 10 ); + + varianceyc( x.length, 1.0, x, 1 ); // $ExpectType number + varianceyc( x.length, 1.0, new AccessorArray( x ), 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + varianceyc( '10', 1.0, x, 1 ); // $ExpectError + varianceyc( true, 1.0, x, 1 ); // $ExpectError + varianceyc( false, 1.0, x, 1 ); // $ExpectError + varianceyc( null, 1.0, x, 1 ); // $ExpectError + varianceyc( undefined, 1.0, x, 1 ); // $ExpectError + varianceyc( [], 1.0, x, 1 ); // $ExpectError + varianceyc( {}, 1.0, x, 1 ); // $ExpectError + varianceyc( ( x: number ): number => x, 1.0, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + varianceyc( x.length, '10', x, 1 ); // $ExpectError + varianceyc( x.length, true, x, 1 ); // $ExpectError + varianceyc( x.length, false, x, 1 ); // $ExpectError + varianceyc( x.length, null, x, 1 ); // $ExpectError + varianceyc( x.length, undefined, x, 1 ); // $ExpectError + varianceyc( x.length, [], x, 1 ); // $ExpectError + varianceyc( x.length, {}, x, 1 ); // $ExpectError + varianceyc( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + varianceyc( x.length, 1.0, 10, 1 ); // $ExpectError + varianceyc( x.length, 1.0, '10', 1 ); // $ExpectError + varianceyc( x.length, 1.0, true, 1 ); // $ExpectError + varianceyc( x.length, 1.0, false, 1 ); // $ExpectError + varianceyc( x.length, 1.0, null, 1 ); // $ExpectError + varianceyc( x.length, 1.0, undefined, 1 ); // $ExpectError + varianceyc( x.length, 1.0, [ '1' ], 1 ); // $ExpectError + varianceyc( x.length, 1.0, {}, 1 ); // $ExpectError + varianceyc( x.length, 1.0, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + varianceyc( x.length, 1.0, x, '10' ); // $ExpectError + varianceyc( x.length, 1.0, x, true ); // $ExpectError + varianceyc( x.length, 1.0, x, false ); // $ExpectError + varianceyc( x.length, 1.0, x, null ); // $ExpectError + varianceyc( x.length, 1.0, x, undefined ); // $ExpectError + varianceyc( x.length, 1.0, x, [] ); // $ExpectError + varianceyc( x.length, 1.0, x, {} ); // $ExpectError + varianceyc( x.length, 1.0, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + varianceyc(); // $ExpectError + varianceyc( x.length ); // $ExpectError + varianceyc( x.length, 1.0 ); // $ExpectError + varianceyc( x.length, 1.0, x ); // $ExpectError + varianceyc( x.length, 1.0, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + + varianceyc.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number + varianceyc.ndarray( x.length, 1, new AccessorArray( x ), 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + varianceyc.ndarray( '10', 1.0, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( true, 1.0, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( false, 1.0, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( null, 1.0, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( undefined, 1.0, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( [], 1.0, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( {}, 1.0, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( ( x: number ): number => x, 1.0, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + varianceyc.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, [], x, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + varianceyc.ndarray( x.length, 1.0, 10, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, '10', 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, true, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, false, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, null, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, undefined, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, [ '1' ], 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, {}, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + varianceyc.ndarray( x.length, 1.0, x, '10', 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, true, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, false, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, null, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, undefined, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, [], 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, {}, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + varianceyc.ndarray( x.length, 1.0, x, 1, '10' ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, true ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, false ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, null ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, undefined ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, [] ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, {} ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + varianceyc.ndarray(); // $ExpectError + varianceyc.ndarray( x.length ); // $ExpectError + varianceyc.ndarray( x.length, 1.0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/examples/index.js b/lib/node_modules/@stdlib/stats/strided/varianceyc/examples/index.js new file mode 100644 index 000000000000..d659f7f2aa7f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/examples/index.js @@ -0,0 +1,30 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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/array/uniform' ); +var varianceyc = require( './../lib' ); + +var x = uniform( 10, -50.0, 50.0, { + 'dtype': 'generic' +}); +console.log( x ); + +var v = varianceyc( x.length, 1.0, x, 1 ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/lib/accessors.js b/lib/node_modules/@stdlib/stats/strided/varianceyc/lib/accessors.js new file mode 100644 index 000000000000..0406525482d6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/lib/accessors.js @@ -0,0 +1,88 @@ +/** +* @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'; + +// MAIN // + +/** +* Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. +* +* ## Method +* +* - This implementation uses a one-pass algorithm, as proposed by Youngs and Cramer (1971). +* +* ## References +* +* - Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826](https://doi.org/10.1080/00401706.1971.10488826). +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} variance +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); +* +* var v = varianceyc( x.length, 1.0, arraylike2object( x ), 1, 0 ); +* // returns 10.7 +*/ +function varianceyc( N, correction, x, strideX, offsetX ) { + var xbuf; + var xget; + var sum; + var ix; + var S; + var v; + var d; + var n; + var i; + + n = N - correction; + + // Cache a reference to array data: + xbuf = x.data; + + // Cache a reference to an element accessor: + xget = x.accessors[ 0 ]; + + sum = xget( xbuf, offsetX ); + ix = offsetX + strideX; + S = 0.0; + for ( i = 2; i <= N; i++ ) { + v = xget( xbuf, ix ); + sum += v; + d = (i*v) - sum; + S += (1.0/(i*(i-1))) * d * d; + ix += strideX; + } + return S / n; +} + + +// EXPORTS // + +module.exports = varianceyc; diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/lib/index.js b/lib/node_modules/@stdlib/stats/strided/varianceyc/lib/index.js new file mode 100644 index 000000000000..2475a86948f4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/lib/index.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. +* +* @module @stdlib/stats/strided/varianceyc +* +* @example +* var varianceyc = require( '@stdlib/stats/strided/varianceyc' ); +* +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = varianceyc( 3, 1.0, x, 1 ); +* // returns ~4.3333 +* +* @example +* var varianceyc = require( '@stdlib/stats/strided/varianceyc' ); +* +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = varianceyc.ndarray( 4, 1.0, x, 2, 1 ); +* // returns 6.25 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/lib/main.js b/lib/node_modules/@stdlib/stats/strided/varianceyc/lib/main.js new file mode 100644 index 000000000000..4dfe7440899e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/lib/main.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. +* +* ## Method +* +* - This implementation uses a one-pass algorithm, as proposed by Youngs and Cramer (1971). +* +* ## References +* +* - Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826](https://doi.org/10.1080/00401706.1971.10488826). +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @returns {number} variance +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = varianceyc( x.length, 1.0, x, 1 ); +* // returns ~4.3333 +*/ +function varianceyc( N, correction, x, strideX ) { + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = varianceyc; diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/varianceyc/lib/ndarray.js new file mode 100644 index 000000000000..11c3f0cfa0e5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/lib/ndarray.js @@ -0,0 +1,92 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. +* +* ## Method +* +* - This implementation uses a one-pass algorithm, as proposed by Youngs and Cramer (1971). +* +* ## References +* +* - Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826](https://doi.org/10.1080/00401706.1971.10488826). +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} variance +* +* @example +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = varianceyc( 4, 1.0, x, 2, 1 ); +* // returns 6.25 +*/ +function varianceyc( N, correction, x, strideX, offsetX ) { + var sum; + var ix; + var S; + var v; + var d; + var n; + var i; + var o; + + n = N - correction; + if ( N <= 0 || n <= 0.0 ) { + return NaN; + } + if ( N === 1 || strideX === 0 ) { + return 0.0; + } + + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, correction, o, strideX, offsetX ); + } + + sum = x[ offsetX ]; + ix = offsetX + strideX; + S = 0.0; + for ( i = 2; i <= N; i++ ) { + v = x[ ix ]; + sum += v; + d = (i*v) - sum; + S += (1.0/(i*(i-1))) * d * d; + ix += strideX; + } + return S / n; +} + + +// EXPORTS // + +module.exports = varianceyc; diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/package.json b/lib/node_modules/@stdlib/stats/strided/varianceyc/package.json new file mode 100644 index 000000000000..fb9c39e4f2ee --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/package.json @@ -0,0 +1,75 @@ +{ + "name": "@stdlib/stats/strided/varianceyc", + "version": "0.0.0", + "description": "Calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer.", + "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", + "var", + "deviation", + "dispersion", + "sample variance", + "unbiased", + "stdev", + "std", + "standard deviation", + "youngs", + "cramer", + "strided", + "strided array", + "typed", + "array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/test/test.js b/lib/node_modules/@stdlib/stats/strided/varianceyc/test/test.js new file mode 100644 index 000000000000..861c6bfa65bc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 varianceyc = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof varianceyc, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof varianceyc.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/test/test.main.js b/lib/node_modules/@stdlib/stats/strided/varianceyc/test/test.main.js new file mode 100644 index 000000000000..f3335f77fef8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/test/test.main.js @@ -0,0 +1,371 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var varianceyc = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof varianceyc, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( varianceyc.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = varianceyc( x.length, 0.0, x, 1 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = varianceyc( x.length, 0.0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = varianceyc( x.length, 0.0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = varianceyc( x.length, 1.0, x, 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = varianceyc( x.length, 1.0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = varianceyc( x.length, 1.0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = varianceyc( 0, 1.0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = varianceyc( -1, 1.0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN (accessor)`', function test( t ) { + var x; + var v; + + x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = varianceyc( 0, 1.0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = varianceyc( -1, 1.0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = toAccessorArray( [ 10.0 ] ); + v = varianceyc( 0, 0.0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = varianceyc( 1, 0.0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessor)', function test( t ) { + var x; + var v; + + x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = varianceyc( 1, 0.0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = toAccessorArray( [ 5.0 ] ); + v = varianceyc( 1, 0.0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = varianceyc( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = varianceyc( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) { + var x; + var v; + + x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = varianceyc( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected' ); + + v = varianceyc( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected' ); + + x = toAccessorArray( [ 7.0, 8.0, 9.0 ] ); + v = varianceyc( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = varianceyc( 4, 1.0, x, 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessor)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = varianceyc( 4, 1.0, toAccessorArray( x ), 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = varianceyc( 4, 1.0, x, -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessor)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = varianceyc( 4, 1.0, toAccessorArray( x ), -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = varianceyc( x.length, 1.0, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = varianceyc( 4, 1.0, x1, 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets (accessor)', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = varianceyc( 4, 1.0, toAccessorArray( x1 ), 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/varianceyc/test/test.ndarray.js new file mode 100644 index 000000000000..65440b321483 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/test/test.ndarray.js @@ -0,0 +1,359 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var varianceyc = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof varianceyc, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( varianceyc.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = varianceyc( x.length, 0.0, x, 1, 0 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = varianceyc( x.length, 0.0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = varianceyc( x.length, 0.0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = varianceyc( x.length, 1.0, x, 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = varianceyc( x.length, 1.0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = varianceyc( x.length, 1.0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = varianceyc( 0, 1.0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = varianceyc( -1, 1.0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) { + var x; + var v; + + x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = varianceyc( 0, 1.0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = varianceyc( -1, 1.0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = toAccessorArray( [ 10.0 ] ); + v = varianceyc( 0, 0.0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = varianceyc( 1, 0.0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessor)', function test( t ) { + var x; + var v; + + x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = varianceyc( 1, 0.0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = toAccessorArray( [ 5.0 ] ); + v = varianceyc( 1, 0.0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = varianceyc( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = varianceyc( x.length, x.length+1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN (accessor)`', function test( t ) { + var x; + var v; + + x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = varianceyc( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = varianceyc( x.length, x.length+1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = toAccessorArray( [ 7.0, 8.0, 9.0 ] ); + v = varianceyc( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = varianceyc( 4, 1.0, x, 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessor)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = varianceyc( 4, 1.0, toAccessorArray( x ), 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = varianceyc( 4, 1.0, x, -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessor)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = varianceyc( 4, 1.0, toAccessorArray( x ), -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = varianceyc( x.length, 1.0, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + + v = varianceyc( 4, 1.0, x, 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter (accessor)', function test( t ) { + var x; + var v; + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + v = varianceyc( 4, 1.0, toAccessorArray( x ), 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); From 3eb90f3b6844f5a4fb3946075efd26aa73d19eaa Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 13:46:19 +0000 Subject: [PATCH 07/32] remove: remove `varianceyc` from namespace This commit removes the `varianceyc` symbol from the `@stdlib/stats/base` namespace due to a package migration. BREAKING CHANGE: remove `varianceyc` To migrate, users should access the same symbol via the `@stdlib/stats/strided` namespace. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/docs/types/index.d.ts | 24 ------------------- .../@stdlib/stats/base/lib/index.js | 9 ------- 2 files changed, 33 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts index d4d5aa6f8924..5a01d919f521 100644 --- a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts @@ -71,7 +71,6 @@ import variancech = require( '@stdlib/stats/base/variancech' ); import variancepn = require( '@stdlib/stats/base/variancepn' ); import variancetk = require( '@stdlib/stats/base/variancetk' ); import variancewd = require( '@stdlib/stats/base/variancewd' ); -import varianceyc = require( '@stdlib/stats/base/varianceyc' ); import dmeankbn2 = require( '@stdlib/stats/strided/dmeankbn2' ); import dmeanli = require( '@stdlib/stats/strided/dmeanli' ); import dmeanlipw = require( '@stdlib/stats/strided/dmeanlipw' ); @@ -1369,29 +1368,6 @@ interface Namespace { */ variancewd: typeof variancewd; - /** - * Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param stride - stride length - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = ns.varianceyc( x.length, 1, x, 1 ); - * // returns ~4.3333 - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = ns.varianceyc.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - varianceyc: typeof varianceyc; - /** * Computes the arithmetic mean of a double-precision floating-point strided array using a second-order iterative Kahan–Babuška algorithm. * diff --git a/lib/node_modules/@stdlib/stats/base/lib/index.js b/lib/node_modules/@stdlib/stats/base/lib/index.js index 99cd8dd0b7d8..f817ca72d9fd 100644 --- a/lib/node_modules/@stdlib/stats/base/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/lib/index.js @@ -504,15 +504,6 @@ setReadOnly( ns, 'variancetk', require( '@stdlib/stats/base/variancetk' ) ); */ setReadOnly( ns, 'variancewd', require( '@stdlib/stats/base/variancewd' ) ); -/** -* @name varianceyc -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/stats/base/varianceyc} -*/ -setReadOnly( ns, 'varianceyc', require( '@stdlib/stats/base/varianceyc' ) ); - /** * @name dmeankbn2 * @memberof ns From 33b006da9166c233b4e423e1da318aa99f56db00 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 13:47:26 +0000 Subject: [PATCH 08/32] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/namespace/lib/namespace/base/strided/d.js | 2 +- .../@stdlib/namespace/lib/namespace/base/strided/n.js | 2 +- .../@stdlib/namespace/lib/namespace/base/strided/s.js | 4 ++-- .../@stdlib/namespace/lib/namespace/base/strided/v.js | 4 ++-- lib/node_modules/@stdlib/stats/array/varianceyc/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/base/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/nanvarianceyc/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/stdevyc/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/stdevyc/lib/ndarray.js | 2 +- lib/node_modules/@stdlib/stats/base/stdevyc/lib/stdevyc.js | 2 +- lib/node_modules/@stdlib/stats/strided/dvarianceyc/README.md | 4 ++-- lib/node_modules/@stdlib/stats/strided/svarianceyc/README.md | 4 ++-- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js index aad9f073b37b..6730b5d4b4e5 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js @@ -2323,7 +2323,7 @@ ns.push({ '@stdlib/stats/strided/dstdevyc', '@stdlib/stats/strided/dvariance', '@stdlib/stats/strided/svarianceyc', - '@stdlib/stats/base/varianceyc' + '@stdlib/stats/strided/varianceyc' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js index ee659caf0857..fc15cf1b8325 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js @@ -396,7 +396,7 @@ ns.push({ '@stdlib/stats/base/nanstdevyc', '@stdlib/stats/base/nanvariance', '@stdlib/stats/base/snanvarianceyc', - '@stdlib/stats/base/varianceyc' + '@stdlib/stats/strided/varianceyc' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js index 8658fb32ca2f..b9a21704ff4f 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js @@ -1868,7 +1868,7 @@ ns.push({ '@stdlib/stats/base/nanstdevyc', '@stdlib/stats/strided/sstdevyc', '@stdlib/stats/base/stdev', - '@stdlib/stats/base/varianceyc' + '@stdlib/stats/strided/varianceyc' ] }); @@ -1971,7 +1971,7 @@ ns.push({ '@stdlib/stats/base/snanvarianceyc', '@stdlib/stats/strided/sstdevyc', '@stdlib/stats/strided/svariance', - '@stdlib/stats/base/varianceyc' + '@stdlib/stats/strided/varianceyc' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js index 1e6cc3a90ccd..ba21e9ad7618 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js @@ -95,8 +95,8 @@ ns.push({ ns.push({ 'alias': 'base.strided.varianceyc', - 'path': '@stdlib/stats/base/varianceyc', - 'value': require( '@stdlib/stats/base/varianceyc' ), + 'path': '@stdlib/stats/strided/varianceyc', + 'value': require( '@stdlib/stats/strided/varianceyc' ), 'type': 'Function', 'related': [ '@stdlib/stats/strided/dvarianceyc', diff --git a/lib/node_modules/@stdlib/stats/array/varianceyc/lib/main.js b/lib/node_modules/@stdlib/stats/array/varianceyc/lib/main.js index ad6d187474de..38197a670257 100644 --- a/lib/node_modules/@stdlib/stats/array/varianceyc/lib/main.js +++ b/lib/node_modules/@stdlib/stats/array/varianceyc/lib/main.js @@ -26,7 +26,7 @@ var dtypes = require( '@stdlib/array/dtypes' ); var dtype = require( '@stdlib/array/dtype' ); var contains = require( '@stdlib/array/base/assert/contains' ); var join = require( '@stdlib/array/base/join' ); -var strided = require( '@stdlib/stats/base/varianceyc' ).ndarray; +var strided = require( '@stdlib/stats/strided/varianceyc' ).ndarray; var format = require( '@stdlib/string/format' ); diff --git a/lib/node_modules/@stdlib/stats/base/README.md b/lib/node_modules/@stdlib/stats/base/README.md index b9843e79017d..eb3c619fcbc7 100644 --- a/lib/node_modules/@stdlib/stats/base/README.md +++ b/lib/node_modules/@stdlib/stats/base/README.md @@ -112,7 +112,7 @@ The namespace contains the following statistical functions: - [`variancepn( N, correction, x, strideX )`][@stdlib/stats/base/variancepn]: calculate the variance of a strided array using a two-pass algorithm. - [`variancetk( N, correction, x, strideX )`][@stdlib/stats/base/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. - [`variancewd( N, correction, x, stride )`][@stdlib/stats/base/variancewd]: calculate the variance of a strided array using Welford's algorithm. -- [`varianceyc( N, correction, x, strideX )`][@stdlib/stats/base/varianceyc]: calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. +- [`varianceyc( N, correction, x, strideX )`][@stdlib/stats/strided/varianceyc]: calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. @@ -273,7 +273,7 @@ console.log( objectKeys( ns ) ); [@stdlib/stats/base/variancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancewd -[@stdlib/stats/base/varianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/varianceyc +[@stdlib/stats/strided/varianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/varianceyc [@stdlib/stats/base/dists]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists diff --git a/lib/node_modules/@stdlib/stats/base/nanvarianceyc/README.md b/lib/node_modules/@stdlib/stats/base/nanvarianceyc/README.md index c6002675c464..5db363f6579c 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvarianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanvarianceyc/README.md @@ -234,7 +234,7 @@ console.log( v ); - [`@stdlib/stats/base/nanstdevyc`][@stdlib/stats/base/nanstdevyc]: calculate the standard deviation of a strided array ignoring NaN values and using a one-pass algorithm proposed by Youngs and Cramer. - [`@stdlib/stats/base/nanvariance`][@stdlib/stats/base/nanvariance]: calculate the variance of a strided array ignoring NaN values. - [`@stdlib/stats/base/snanvarianceyc`][@stdlib/stats/base/snanvarianceyc]: calculate the variance of a single-precision floating-point strided array ignoring NaN values and using a one-pass algorithm proposed by Youngs and Cramer. -- [`@stdlib/stats/base/varianceyc`][@stdlib/stats/base/varianceyc]: calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. +- [`@stdlib/stats/strided/varianceyc`][@stdlib/stats/strided/varianceyc]: calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. @@ -264,7 +264,7 @@ console.log( v ); [@stdlib/stats/base/snanvarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/snanvarianceyc -[@stdlib/stats/base/varianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/varianceyc +[@stdlib/stats/strided/varianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/varianceyc diff --git a/lib/node_modules/@stdlib/stats/base/stdevyc/README.md b/lib/node_modules/@stdlib/stats/base/stdevyc/README.md index aac0db01b1df..d09a06b42621 100644 --- a/lib/node_modules/@stdlib/stats/base/stdevyc/README.md +++ b/lib/node_modules/@stdlib/stats/base/stdevyc/README.md @@ -241,7 +241,7 @@ console.log( v ); - [`@stdlib/stats/base/nanstdevyc`][@stdlib/stats/base/nanstdevyc]: calculate the standard deviation of a strided array ignoring NaN values and using a one-pass algorithm proposed by Youngs and Cramer. - [`@stdlib/stats/strided/sstdevyc`][@stdlib/stats/strided/sstdevyc]: calculate the standard deviation of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. - [`@stdlib/stats/base/stdev`][@stdlib/stats/base/stdev]: calculate the standard deviation of a strided array. -- [`@stdlib/stats/base/varianceyc`][@stdlib/stats/base/varianceyc]: calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. +- [`@stdlib/stats/strided/varianceyc`][@stdlib/stats/strided/varianceyc]: calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. @@ -269,7 +269,7 @@ console.log( v ); [@stdlib/stats/base/stdev]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/stdev -[@stdlib/stats/base/varianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/varianceyc +[@stdlib/stats/strided/varianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/varianceyc diff --git a/lib/node_modules/@stdlib/stats/base/stdevyc/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/stdevyc/lib/ndarray.js index f69a3652a931..5a24712bd22b 100644 --- a/lib/node_modules/@stdlib/stats/base/stdevyc/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/stdevyc/lib/ndarray.js @@ -20,7 +20,7 @@ // MODULES // -var varianceyc = require( '@stdlib/stats/base/varianceyc' ).ndarray; +var varianceyc = require( '@stdlib/stats/strided/varianceyc' ).ndarray; var sqrt = require( '@stdlib/math/base/special/sqrt' ); diff --git a/lib/node_modules/@stdlib/stats/base/stdevyc/lib/stdevyc.js b/lib/node_modules/@stdlib/stats/base/stdevyc/lib/stdevyc.js index 3030bafe696a..59f9d7e0b831 100644 --- a/lib/node_modules/@stdlib/stats/base/stdevyc/lib/stdevyc.js +++ b/lib/node_modules/@stdlib/stats/base/stdevyc/lib/stdevyc.js @@ -20,7 +20,7 @@ // MODULES // -var varianceyc = require( '@stdlib/stats/base/varianceyc' ); +var varianceyc = require( '@stdlib/stats/strided/varianceyc' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); diff --git a/lib/node_modules/@stdlib/stats/strided/dvarianceyc/README.md b/lib/node_modules/@stdlib/stats/strided/dvarianceyc/README.md index b38d69957124..1169759dcce4 100644 --- a/lib/node_modules/@stdlib/stats/strided/dvarianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/strided/dvarianceyc/README.md @@ -352,7 +352,7 @@ int main( void ) { - [`@stdlib/stats/strided/dstdevyc`][@stdlib/stats/strided/dstdevyc]: calculate the standard deviation of a double-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. - [`@stdlib/stats/strided/dvariance`][@stdlib/stats/strided/dvariance]: calculate the variance of a double-precision floating-point strided array. - [`@stdlib/stats/strided/svarianceyc`][@stdlib/stats/strided/svarianceyc]: calculate the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. -- [`@stdlib/stats/base/varianceyc`][@stdlib/stats/base/varianceyc]: calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. +- [`@stdlib/stats/strided/varianceyc`][@stdlib/stats/strided/varianceyc]: calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. @@ -380,7 +380,7 @@ int main( void ) { [@stdlib/stats/strided/svarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svarianceyc -[@stdlib/stats/base/varianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/varianceyc +[@stdlib/stats/strided/varianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/varianceyc diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/README.md b/lib/node_modules/@stdlib/stats/strided/svarianceyc/README.md index e83a03dc4730..d46115a72872 100644 --- a/lib/node_modules/@stdlib/stats/strided/svarianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/README.md @@ -352,7 +352,7 @@ int main( void ) { - [`@stdlib/stats/base/snanvarianceyc`][@stdlib/stats/base/snanvarianceyc]: calculate the variance of a single-precision floating-point strided array ignoring NaN values and using a one-pass algorithm proposed by Youngs and Cramer. - [`@stdlib/stats/strided/sstdevyc`][@stdlib/stats/strided/sstdevyc]: calculate the standard deviation of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. - [`@stdlib/stats/strided/svariance`][@stdlib/stats/strided/svariance]: calculate the variance of a single-precision floating-point strided array. -- [`@stdlib/stats/base/varianceyc`][@stdlib/stats/base/varianceyc]: calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. +- [`@stdlib/stats/strided/varianceyc`][@stdlib/stats/strided/varianceyc]: calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. @@ -380,7 +380,7 @@ int main( void ) { [@stdlib/stats/strided/svariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariance -[@stdlib/stats/base/varianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/varianceyc +[@stdlib/stats/strided/varianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/varianceyc From ca61d4dabf27640e9420e9d03424e8db90c24816 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 13:49:17 +0000 Subject: [PATCH 09/32] remove: remove `stats/base/varianceyc` This commit removes `@stdlib/stats/base/varianceyc` in favor of `@stdlib/stats/strided/varianceyc`. BREAKING CHANGE: remove `stats/base/varianceyc` To migrate, users should update their require/import paths to use `@stdlib/stats/strided/varianceyc`, which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/varianceyc/README.md | 265 ------------- .../base/varianceyc/benchmark/benchmark.js | 96 ----- .../varianceyc/benchmark/benchmark.ndarray.js | 96 ----- .../docs/img/equation_population_mean.svg | 42 -- .../docs/img/equation_population_variance.svg | 54 --- .../docs/img/equation_sample_mean.svg | 43 -- .../img/equation_unbiased_sample_variance.svg | 61 --- .../stats/base/varianceyc/docs/repl.txt | 114 ------ .../base/varianceyc/docs/types/index.d.ts | 96 ----- .../stats/base/varianceyc/docs/types/test.ts | 190 --------- .../stats/base/varianceyc/examples/index.js | 30 -- .../stats/base/varianceyc/lib/accessors.js | 88 ----- .../stats/base/varianceyc/lib/index.js | 59 --- .../@stdlib/stats/base/varianceyc/lib/main.js | 59 --- .../stats/base/varianceyc/lib/ndarray.js | 92 ----- .../stats/base/varianceyc/package.json | 75 ---- .../stats/base/varianceyc/test/test.js | 38 -- .../stats/base/varianceyc/test/test.main.js | 371 ------------------ .../base/varianceyc/test/test.ndarray.js | 359 ----------------- 19 files changed, 2228 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/README.md delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_population_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_population_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_sample_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_unbiased_sample_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/lib/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/lib/main.js delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/package.json delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/test/test.js delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/test/test.main.js delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md deleted file mode 100644 index a05b606f4f10..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md +++ /dev/null @@ -1,265 +0,0 @@ - - -# varianceyc - -> Calculate the [variance][variance] of a strided array using a one-pass algorithm proposed by Youngs and Cramer. - -
- -The population [variance][variance] of a finite size population of size `N` is given by - - - -```math -\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 -``` - - - - - -where the population mean is given by - - - -```math -\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i -``` - - - - - -Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, - - - -```math -s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 -``` - - - - - -where the sample mean is given by - - - -```math -\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i -``` - - - - - -The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. - -
- - - -
- -## Usage - -```javascript -var varianceyc = require( '@stdlib/stats/base/varianceyc' ); -``` - -#### varianceyc( N, correction, x, strideX ) - -Computes the [variance][variance] of a strided array using a one-pass algorithm proposed by Youngs and Cramer. - -```javascript -var x = [ 1.0, -2.0, 2.0 ]; - -var v = varianceyc( x.length, 1.0, x, 1 ); -// returns ~4.3333 -``` - -The function has the following parameters: - -- **N**: number of indexed elements. -- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. -- **strideX**: stride length for `x`. - -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, - -```javascript -var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; - -var v = varianceyc( 4, 1.0, x, 2 ); -// returns 6.25 -``` - -Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); - -var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - -var v = varianceyc( 4, 1.0, x1, 2 ); -// returns 6.25 -``` - -#### varianceyc.ndarray( N, correction, x, strideX, offsetX ) - -Computes the [variance][variance] of a strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. - -```javascript -var x = [ 1.0, -2.0, 2.0 ]; - -var v = varianceyc.ndarray( x.length, 1.0, x, 1, 0 ); -// returns ~4.33333 -``` - -The function has the following additional parameters: - -- **offsetX**: starting index for `x`. - -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element - -```javascript -var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; - -var v = varianceyc.ndarray( 4, 1.0, x, 2, 1 ); -// returns 6.25 -``` - -
- - - -
- -## Notes - -- If `N <= 0`, both functions return `NaN`. -- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. -- Depending on the environment, the typed versions ([`dvarianceyc`][@stdlib/stats/strided/dvarianceyc], [`svarianceyc`][@stdlib/stats/strided/svarianceyc], etc.) are likely to be significantly more performant. -- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). - -
- - - -
- -## Examples - - - -```javascript -var uniform = require( '@stdlib/random/array/uniform' ); -var varianceyc = require( '@stdlib/stats/base/varianceyc' ); - -var x = uniform( 10, -50.0, 50.0, { - 'dtype': 'generic' -}); -console.log( x ); - -var v = varianceyc( x.length, 1.0, x, 1 ); -console.log( v ); -``` - -
- - - -* * * - -
- -## References - -- Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826][@youngs:1971a]. - -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.js deleted file mode 100644 index 4cf64da5f3d4..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var uniform = require( '@stdlib/random/array/uniform' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var varianceyc = require( './../lib' ); - - -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10.0, 10.0, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = varianceyc( x.length, 1.0, x, 1 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.ndarray.js deleted file mode 100644 index c760ff42df7f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var varianceyc = require( './../lib/ndarray.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10.0, 10.0, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = varianceyc( x.length, 1.0, x, 1, 0 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':ndarray:len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_population_mean.svg deleted file mode 100644 index 4bbdf0d2a56f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_population_mean.svg +++ /dev/null @@ -1,42 +0,0 @@ - -mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_population_variance.svg deleted file mode 100644 index 4130ba0750d2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_population_variance.svg +++ /dev/null @@ -1,54 +0,0 @@ - -sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_sample_mean.svg deleted file mode 100644 index aea7a5f6687a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_sample_mean.svg +++ /dev/null @@ -1,43 +0,0 @@ - -x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_unbiased_sample_variance.svg deleted file mode 100644 index 1ae1283e7fb1..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/img/equation_unbiased_sample_variance.svg +++ /dev/null @@ -1,61 +0,0 @@ - -s squared equals 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 - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt deleted file mode 100644 index 2511d4ec7df5..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt +++ /dev/null @@ -1,114 +0,0 @@ - -{{alias}}( N, correction, x, strideX ) - Computes the variance of a strided array using a one-pass algorithm proposed - by Youngs and Cramer. - - The `N` and stride parameters determine which elements in the strided array - are accessed at runtime. - - Indexing is relative to the first index. To introduce an offset, use a typed - array view. - - If `N <= 0`, the function returns `NaN`. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Array|TypedArray - Input array. - - strideX: integer - Stride length for `x`. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = [ 1.0, -2.0, 2.0 ]; - > {{alias}}( x.length, 1.0, x, 1 ) - ~4.3333 - - // Using `N` and stride parameters: - > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; - > {{alias}}( 3, 1.0, x, 2 ) - ~4.3333 - - // Using view offsets: - > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 1.0, x1, 2 ) - ~4.3333 - - -{{alias}}.ndarray( N, correction, x, strideX, offsetX ) - Computes the variance of a strided array using a one-pass algorithm proposed - by Youngs and Cramer and alternative indexing semantics. - - While typed array views mandate a view offset based on the underlying - buffer, the offset parameter supports indexing semantics based on a - starting index. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Array|TypedArray - Input array. - - strideX: integer - Stride length for `x`. - - offsetX: integer - Starting index for `x`. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = [ 1.0, -2.0, 2.0 ]; - > {{alias}}.ndarray( x.length, 1.0, x, 1, 0 ) - ~4.3333 - - // Using offset parameter: - > var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; - > {{alias}}.ndarray( 3, 1.0, x, 2, 1 ) - ~4.3333 - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts deleted file mode 100644 index de3b1949ee4b..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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 - -/// - -import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; - -/** -* Input array. -*/ -type InputArray = NumericArray | Collection | AccessorArrayLike; - -/** -* Interface describing `varianceyc`. -*/ -interface Routine { - /** - * Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length for `x` - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = varianceyc( x.length, 1.0, x, 1 ); - * // returns ~4.3333 - */ - ( N: number, correction: number, x: InputArray, strideX: number ): number; - - /** - * Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length for `x` - * @param offsetX - starting index for `x` - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = varianceyc.ndarray( x.length, 1.0, x, 1, 0 ); - * // returns ~4.3333 - */ - ndarray( N: number, correction: number, x: InputArray, strideX: number, offsetX: number ): number; -} - -/** -* Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. -* -* @param N - number of indexed elements -* @param correction - degrees of freedom adjustment -* @param x - input array -* @param strideX - stride length for `x` -* @returns variance -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = varianceyc( x.length, 1.0, x, 1 ); -* // returns ~4.3333 -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = varianceyc.ndarray( x.length, 1.0, x, 1, 0 ); -* // returns ~4.3333 -*/ -declare var varianceyc: Routine; - - -// EXPORTS // - -export = varianceyc; diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/test.ts deleted file mode 100644 index cae7d268af9d..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/test.ts +++ /dev/null @@ -1,190 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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 AccessorArray = require( '@stdlib/array/base/accessor' ); -import varianceyc = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const x = new Float64Array( 10 ); - - varianceyc( x.length, 1.0, x, 1 ); // $ExpectType number - varianceyc( x.length, 1.0, new AccessorArray( x ), 1 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a number... -{ - const x = new Float64Array( 10 ); - - varianceyc( '10', 1.0, x, 1 ); // $ExpectError - varianceyc( true, 1.0, x, 1 ); // $ExpectError - varianceyc( false, 1.0, x, 1 ); // $ExpectError - varianceyc( null, 1.0, x, 1 ); // $ExpectError - varianceyc( undefined, 1.0, x, 1 ); // $ExpectError - varianceyc( [], 1.0, x, 1 ); // $ExpectError - varianceyc( {}, 1.0, x, 1 ); // $ExpectError - varianceyc( ( x: number ): number => x, 1.0, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = new Float64Array( 10 ); - - varianceyc( x.length, '10', x, 1 ); // $ExpectError - varianceyc( x.length, true, x, 1 ); // $ExpectError - varianceyc( x.length, false, x, 1 ); // $ExpectError - varianceyc( x.length, null, x, 1 ); // $ExpectError - varianceyc( x.length, undefined, x, 1 ); // $ExpectError - varianceyc( x.length, [], x, 1 ); // $ExpectError - varianceyc( x.length, {}, x, 1 ); // $ExpectError - varianceyc( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a numeric array... -{ - const x = new Float64Array( 10 ); - - varianceyc( x.length, 1.0, 10, 1 ); // $ExpectError - varianceyc( x.length, 1.0, '10', 1 ); // $ExpectError - varianceyc( x.length, 1.0, true, 1 ); // $ExpectError - varianceyc( x.length, 1.0, false, 1 ); // $ExpectError - varianceyc( x.length, 1.0, null, 1 ); // $ExpectError - varianceyc( x.length, 1.0, undefined, 1 ); // $ExpectError - varianceyc( x.length, 1.0, [ '1' ], 1 ); // $ExpectError - varianceyc( x.length, 1.0, {}, 1 ); // $ExpectError - varianceyc( x.length, 1.0, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - varianceyc( x.length, 1.0, x, '10' ); // $ExpectError - varianceyc( x.length, 1.0, x, true ); // $ExpectError - varianceyc( x.length, 1.0, x, false ); // $ExpectError - varianceyc( x.length, 1.0, x, null ); // $ExpectError - varianceyc( x.length, 1.0, x, undefined ); // $ExpectError - varianceyc( x.length, 1.0, x, [] ); // $ExpectError - varianceyc( x.length, 1.0, x, {} ); // $ExpectError - varianceyc( x.length, 1.0, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - - varianceyc(); // $ExpectError - varianceyc( x.length ); // $ExpectError - varianceyc( x.length, 1.0 ); // $ExpectError - varianceyc( x.length, 1.0, x ); // $ExpectError - varianceyc( x.length, 1.0, x, 1, 10 ); // $ExpectError -} - -// Attached to main export is an `ndarray` method which returns a number... -{ - const x = new Float64Array( 10 ); - - varianceyc.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number - varianceyc.ndarray( x.length, 1, new AccessorArray( x ), 1, 0 ); // $ExpectType number -} - -// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... -{ - const x = new Float64Array( 10 ); - - varianceyc.ndarray( '10', 1.0, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( true, 1.0, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( false, 1.0, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( null, 1.0, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( undefined, 1.0, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( [], 1.0, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( {}, 1.0, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( ( x: number ): number => x, 1.0, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... -{ - const x = new Float64Array( 10 ); - - varianceyc.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, true, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, false, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, null, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, [], x, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... -{ - const x = new Float64Array( 10 ); - - varianceyc.ndarray( x.length, 1.0, 10, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, '10', 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, true, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, false, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, null, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, undefined, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, [ '1' ], 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, {}, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - varianceyc.ndarray( x.length, 1.0, x, '10', 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, true, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, false, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, null, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, undefined, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, [], 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, {}, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, ( x: number ): number => x, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - varianceyc.ndarray( x.length, 1.0, x, 1, '10' ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, 1, true ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, 1, false ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, 1, null ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, 1, undefined ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, 1, [] ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, 1, {} ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - - varianceyc.ndarray(); // $ExpectError - varianceyc.ndarray( x.length ); // $ExpectError - varianceyc.ndarray( x.length, 1.0 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, 1 ); // $ExpectError - varianceyc.ndarray( x.length, 1.0, x, 1, 0, 10 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js b/lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js deleted file mode 100644 index d659f7f2aa7f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js +++ /dev/null @@ -1,30 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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/array/uniform' ); -var varianceyc = require( './../lib' ); - -var x = uniform( 10, -50.0, 50.0, { - 'dtype': 'generic' -}); -console.log( x ); - -var v = varianceyc( x.length, 1.0, x, 1 ); -console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js deleted file mode 100644 index 0406525482d6..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @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'; - -// MAIN // - -/** -* Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. -* -* ## Method -* -* - This implementation uses a one-pass algorithm, as proposed by Youngs and Cramer (1971). -* -* ## References -* -* - Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826](https://doi.org/10.1080/00401706.1971.10488826). -* -* @private -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {Object} x - input array object -* @param {Collection} x.data - input array data -* @param {Array} x.accessors - array element accessors -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index -* @returns {number} variance -* -* @example -* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -* -* var x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); -* -* var v = varianceyc( x.length, 1.0, arraylike2object( x ), 1, 0 ); -* // returns 10.7 -*/ -function varianceyc( N, correction, x, strideX, offsetX ) { - var xbuf; - var xget; - var sum; - var ix; - var S; - var v; - var d; - var n; - var i; - - n = N - correction; - - // Cache a reference to array data: - xbuf = x.data; - - // Cache a reference to an element accessor: - xget = x.accessors[ 0 ]; - - sum = xget( xbuf, offsetX ); - ix = offsetX + strideX; - S = 0.0; - for ( i = 2; i <= N; i++ ) { - v = xget( xbuf, ix ); - sum += v; - d = (i*v) - sum; - S += (1.0/(i*(i-1))) * d * d; - ix += strideX; - } - return S / n; -} - - -// EXPORTS // - -module.exports = varianceyc; diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/index.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/index.js deleted file mode 100644 index 51c01687fbb2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. -* -* @module @stdlib/stats/base/varianceyc -* -* @example -* var varianceyc = require( '@stdlib/stats/base/varianceyc' ); -* -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = varianceyc( 3, 1.0, x, 1 ); -* // returns ~4.3333 -* -* @example -* var varianceyc = require( '@stdlib/stats/base/varianceyc' ); -* -* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* -* var v = varianceyc.ndarray( 4, 1.0, x, 2, 1 ); -* // returns 6.25 -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var ndarray = require( './ndarray.js' ); - - -// MAIN // - -setReadOnly( main, 'ndarray', ndarray ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/main.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/main.js deleted file mode 100644 index 4dfe7440899e..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/main.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); -var ndarray = require( './ndarray.js' ); - - -// MAIN // - -/** -* Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. -* -* ## Method -* -* - This implementation uses a one-pass algorithm, as proposed by Youngs and Cramer (1971). -* -* ## References -* -* - Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826](https://doi.org/10.1080/00401706.1971.10488826). -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array -* @param {integer} strideX - stride length -* @returns {number} variance -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = varianceyc( x.length, 1.0, x, 1 ); -* // returns ~4.3333 -*/ -function varianceyc( N, correction, x, strideX ) { - return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); -} - - -// EXPORTS // - -module.exports = varianceyc; diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js deleted file mode 100644 index 11c3f0cfa0e5..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -var accessors = require( './accessors.js' ); - - -// MAIN // - -/** -* Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. -* -* ## Method -* -* - This implementation uses a one-pass algorithm, as proposed by Youngs and Cramer (1971). -* -* ## References -* -* - Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826](https://doi.org/10.1080/00401706.1971.10488826). -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index -* @returns {number} variance -* -* @example -* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* -* var v = varianceyc( 4, 1.0, x, 2, 1 ); -* // returns 6.25 -*/ -function varianceyc( N, correction, x, strideX, offsetX ) { - var sum; - var ix; - var S; - var v; - var d; - var n; - var i; - var o; - - n = N - correction; - if ( N <= 0 || n <= 0.0 ) { - return NaN; - } - if ( N === 1 || strideX === 0 ) { - return 0.0; - } - - o = arraylike2object( x ); - if ( o.accessorProtocol ) { - return accessors( N, correction, o, strideX, offsetX ); - } - - sum = x[ offsetX ]; - ix = offsetX + strideX; - S = 0.0; - for ( i = 2; i <= N; i++ ) { - v = x[ ix ]; - sum += v; - d = (i*v) - sum; - S += (1.0/(i*(i-1))) * d * d; - ix += strideX; - } - return S / n; -} - - -// EXPORTS // - -module.exports = varianceyc; diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/package.json b/lib/node_modules/@stdlib/stats/base/varianceyc/package.json deleted file mode 100644 index ef20d7a8a8e2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/package.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "name": "@stdlib/stats/base/varianceyc", - "version": "0.0.0", - "description": "Calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer.", - "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", - "var", - "deviation", - "dispersion", - "sample variance", - "unbiased", - "stdev", - "std", - "standard deviation", - "youngs", - "cramer", - "strided", - "strided array", - "typed", - "array" - ], - "__stdlib__": {} -} diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.js deleted file mode 100644 index 861c6bfa65bc..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 varianceyc = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof varianceyc, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { - t.strictEqual( typeof varianceyc.ndarray, 'function', 'method is a function' ); - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.main.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.main.js deleted file mode 100644 index f3335f77fef8..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.main.js +++ /dev/null @@ -1,371 +0,0 @@ -/** -* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var Float64Array = require( '@stdlib/array/float64' ); -var varianceyc = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof varianceyc, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( varianceyc.length, 4, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 0.0, x, 1 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 0.0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 0.0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 1.0, x, 1 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 1.0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 1.0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = varianceyc( 0, 1.0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = varianceyc( -1, 1.0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN (accessor)`', function test( t ) { - var x; - var v; - - x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = varianceyc( 0, 1.0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = varianceyc( -1, 1.0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - x = toAccessorArray( [ 10.0 ] ); - v = varianceyc( 0, 0.0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = varianceyc( 1, 0.0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessor)', function test( t ) { - var x; - var v; - - x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = varianceyc( 1, 0.0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = toAccessorArray( [ 5.0 ] ); - v = varianceyc( 1, 0.0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = varianceyc( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = varianceyc( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) { - var x; - var v; - - x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = varianceyc( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected' ); - - v = varianceyc( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected' ); - - x = toAccessorArray( [ 7.0, 8.0, 9.0 ] ); - v = varianceyc( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = varianceyc( 4, 1.0, x, 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a `stride` parameter (accessor)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = varianceyc( 4, 1.0, toAccessorArray( x ), 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = varianceyc( 4, 1.0, x, -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter (accessor)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = varianceyc( 4, 1.0, toAccessorArray( x ), -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = varianceyc( x.length, 1.0, x, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = varianceyc( x.length, 1.0, toAccessorArray( x ), 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float64Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = varianceyc( 4, 1.0, x1, 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets (accessor)', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float64Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = varianceyc( 4, 1.0, toAccessorArray( x1 ), 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js deleted file mode 100644 index 65440b321483..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js +++ /dev/null @@ -1,359 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var varianceyc = require( './../lib/ndarray.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof varianceyc, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( varianceyc.length, 5, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 0.0, x, 1, 0 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 0.0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 0.0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 1.0, x, 1, 0 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 1.0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 1.0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = varianceyc( 0, 1.0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = varianceyc( -1, 1.0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) { - var x; - var v; - - x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = varianceyc( 0, 1.0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = varianceyc( -1, 1.0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - x = toAccessorArray( [ 10.0 ] ); - v = varianceyc( 0, 0.0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = varianceyc( 1, 0.0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessor)', function test( t ) { - var x; - var v; - - x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = varianceyc( 1, 0.0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = toAccessorArray( [ 5.0 ] ); - v = varianceyc( 1, 0.0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = varianceyc( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = varianceyc( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN (accessor)`', function test( t ) { - var x; - var v; - - x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = varianceyc( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = varianceyc( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - x = toAccessorArray( [ 7.0, 8.0, 9.0 ] ); - v = varianceyc( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = varianceyc( 4, 1.0, x, 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a `stride` parameter (accessor)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = varianceyc( 4, 1.0, toAccessorArray( x ), 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = varianceyc( 4, 1.0, x, -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter (accessor)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = varianceyc( 4, 1.0, toAccessorArray( x ), -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = varianceyc( x.length, 1.0, x, 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = varianceyc( x.length, 1.0, toAccessorArray( x ), 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter', function test( t ) { - var x; - var v; - - x = [ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]; - - v = varianceyc( 4, 1.0, x, 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter (accessor)', function test( t ) { - var x; - var v; - x = [ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]; - v = varianceyc( 4, 1.0, toAccessorArray( x ), 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); From 8bb07686be49817eb0d52733767c7c2791dc49a8 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 13:54:14 +0000 Subject: [PATCH 10/32] feat: add `stats/strided/variancewd` Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../stats/strided/variancewd/README.md | 268 +++++++++++++ .../strided/variancewd/benchmark/benchmark.js | 96 +++++ .../variancewd/benchmark/benchmark.ndarray.js | 96 +++++ .../docs/img/equation_population_mean.svg | 42 ++ .../docs/img/equation_population_variance.svg | 54 +++ .../docs/img/equation_sample_mean.svg | 43 +++ .../img/equation_unbiased_sample_variance.svg | 61 +++ .../stats/strided/variancewd/docs/repl.txt | 113 ++++++ .../strided/variancewd/docs/types/index.d.ts | 96 +++++ .../strided/variancewd/docs/types/test.ts | 190 +++++++++ .../strided/variancewd/examples/index.js | 30 ++ .../stats/strided/variancewd/lib/accessors.js | 118 ++++++ .../stats/strided/variancewd/lib/index.js | 59 +++ .../stats/strided/variancewd/lib/main.js | 90 +++++ .../stats/strided/variancewd/lib/ndarray.js | 121 ++++++ .../stats/strided/variancewd/package.json | 74 ++++ .../stats/strided/variancewd/test/test.js | 38 ++ .../strided/variancewd/test/test.ndarray.js | 350 +++++++++++++++++ .../variancewd/test/test.variancewd.js | 359 ++++++++++++++++++ 19 files changed, 2298 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_population_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_population_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_sample_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_unbiased_sample_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancewd/test/test.variancewd.js diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/README.md b/lib/node_modules/@stdlib/stats/strided/variancewd/README.md new file mode 100644 index 000000000000..4e4b750f5d2b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/README.md @@ -0,0 +1,268 @@ + + +# variancewd + +> Calculate the [variance][variance] of a strided array using Welford's algorithm. + +
+ +The population [variance][variance] of a finite size population of size `N` is given by + + + +```math +\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 +``` + + + + + +where the population mean is given by + + + +```math +\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i +``` + + + + + +Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, + + + +```math +s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 +``` + + + + + +where the sample mean is given by + + + +```math +\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + + + +The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. + +
+ + + +
+ +## Usage + +```javascript +var variancewd = require( '@stdlib/stats/strided/variancewd' ); +``` + +#### variancewd( N, correction, x, strideX ) + +Computes the [variance][variance] of a strided array using Welford's algorithm. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; + +var v = variancewd( x.length, 1, x, 1 ); +// returns ~4.3333 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, + +```javascript +var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; + +var v = variancewd( 4, 1, x, 2 ); +// returns 6.25 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var v = variancewd( 4, 1, x1, 2 ); +// returns 6.25 +``` + +#### variancewd.ndarray( N, correction, x, strideX, offsetX ) + +Computes the [variance][variance] of a strided array using Welford's algorithm and alternative indexing semantics. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; + +var v = variancewd.ndarray( x.length, 1, x, 1, 0 ); +// returns ~4.33333 +``` + +The function has the following additional parameters: + +- **offset**: starting index for `x`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element + +```javascript +var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; + +var v = variancewd.ndarray( 4, 1, x, 2, 1 ); +// returns 6.25 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `NaN`. +- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). +- Depending on the environment, the typed versions ([`dvariancewd`][@stdlib/stats/strided/dvariancewd], [`svariancewd`][@stdlib/stats/strided/svariancewd], etc.) are likely to be significantly more performant. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var variancewd = require( '@stdlib/stats/strided/variancewd' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +console.log( x ); + +var v = variancewd( x.length, 1, x, 1 ); +console.log( v ); +``` + +
+ + + +* * * + +
+ +## References + +- Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022][@welford:1962a]. +- van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961][@vanreeken:1968a]. + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/variancewd/benchmark/benchmark.js new file mode 100644 index 000000000000..653a13db7e47 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/benchmark/benchmark.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var variancewd = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = variancewd( x.length, 1, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/variancewd/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..bf5fd4fa45d7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/benchmark/benchmark.ndarray.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var variancewd = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = variancewd( x.length, 1, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_population_mean.svg new file mode 100644 index 000000000000..4bbdf0d2a56f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_population_mean.svg @@ -0,0 +1,42 @@ + +mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_population_variance.svg new file mode 100644 index 000000000000..4130ba0750d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_population_variance.svg @@ -0,0 +1,54 @@ + +sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_sample_mean.svg new file mode 100644 index 000000000000..aea7a5f6687a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_sample_mean.svg @@ -0,0 +1,43 @@ + +x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_unbiased_sample_variance.svg new file mode 100644 index 000000000000..1ae1283e7fb1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/docs/img/equation_unbiased_sample_variance.svg @@ -0,0 +1,61 @@ + +s squared equals 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 + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/variancewd/docs/repl.txt new file mode 100644 index 000000000000..6ccd6f6054f8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/docs/repl.txt @@ -0,0 +1,113 @@ + +{{alias}}( N, correction, x, strideX ) + Computes the variance of a strided array using Welford's algorithm. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns `NaN`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > {{alias}}( x.length, 1, x, 1 ) + ~4.3333 + + // Using `N` and stride parameters: + > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; + > {{alias}}( 3, 1, x, 2 ) + ~4.3333 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, 1, x1, 2 ) + ~4.3333 + + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) + Computes the variance of a strided array using Welford's algorithm and + alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the `offset` parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) + ~4.3333 + + // Using offset parameter: + > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; + > {{alias}}.ndarray( 3, 1, x, 2, 1 ) + ~4.3333 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/variancewd/docs/types/index.d.ts new file mode 100644 index 000000000000..3671308bf4c5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/docs/types/index.d.ts @@ -0,0 +1,96 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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 + +/// + +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `variancewd`. +*/ +interface Routine { + /** + * Computes the variance of a strided array using Welford's algorithm. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @returns variance + * + * @example + * var x = [ 1.0, -2.0, 2.0 ]; + * + * var v = variancewd( x.length, 1, x, 1 ); + * // returns ~4.3333 + */ + ( N: number, correction: number, x: InputArray, strideX: number ): number; + + /** + * Computes the variance of a strided array using Welford's algorithm and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns variance + * + * @example + * var x = [ 1.0, -2.0, 2.0 ]; + * + * var v = variancewd.ndarray( x.length, 1, x, 1, 0 ); + * // returns ~4.3333 + */ + ndarray( N: number, correction: number, x: InputArray, strideX: number, offsetX: number ): number; +} + +/** +* Computes the variance of a strided array using Welford's algorithm. +* +* @param N - number of indexed elements +* @param correction - degrees of freedom adjustment +* @param x - input array +* @param strideX - stride length +* @returns variance +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancewd( x.length, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancewd.ndarray( x.length, 1, x, 1, 0 ); +* // returns ~4.3333 +*/ +declare var variancewd: Routine; + + +// EXPORTS // + +export = variancewd; diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/variancewd/docs/types/test.ts new file mode 100644 index 000000000000..0a4d061c50ec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/docs/types/test.ts @@ -0,0 +1,190 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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 AccessorArray = require( '@stdlib/array/base/accessor' ); +import variancewd = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Float64Array( 10 ); + + variancewd( x.length, 1, x, 1 ); // $ExpectType number + variancewd( x.length, 1, new AccessorArray( x ), 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancewd( '10', 1, x, 1 ); // $ExpectError + variancewd( true, 1, x, 1 ); // $ExpectError + variancewd( false, 1, x, 1 ); // $ExpectError + variancewd( null, 1, x, 1 ); // $ExpectError + variancewd( undefined, 1, x, 1 ); // $ExpectError + variancewd( [], 1, x, 1 ); // $ExpectError + variancewd( {}, 1, x, 1 ); // $ExpectError + variancewd( ( x: number ): number => x, 1, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancewd( x.length, '10', x, 1 ); // $ExpectError + variancewd( x.length, true, x, 1 ); // $ExpectError + variancewd( x.length, false, x, 1 ); // $ExpectError + variancewd( x.length, null, x, 1 ); // $ExpectError + variancewd( x.length, undefined, x, 1 ); // $ExpectError + variancewd( x.length, [], x, 1 ); // $ExpectError + variancewd( x.length, {}, x, 1 ); // $ExpectError + variancewd( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + variancewd( x.length, 1, 10, 1 ); // $ExpectError + variancewd( x.length, 1, '10', 1 ); // $ExpectError + variancewd( x.length, 1, true, 1 ); // $ExpectError + variancewd( x.length, 1, false, 1 ); // $ExpectError + variancewd( x.length, 1, null, 1 ); // $ExpectError + variancewd( x.length, 1, undefined, 1 ); // $ExpectError + variancewd( x.length, 1, [ '1' ], 1 ); // $ExpectError + variancewd( x.length, 1, {}, 1 ); // $ExpectError + variancewd( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancewd( x.length, 1, x, '10' ); // $ExpectError + variancewd( x.length, 1, x, true ); // $ExpectError + variancewd( x.length, 1, x, false ); // $ExpectError + variancewd( x.length, 1, x, null ); // $ExpectError + variancewd( x.length, 1, x, undefined ); // $ExpectError + variancewd( x.length, 1, x, [] ); // $ExpectError + variancewd( x.length, 1, x, {} ); // $ExpectError + variancewd( x.length, 1, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + variancewd(); // $ExpectError + variancewd( x.length ); // $ExpectError + variancewd( x.length, 1 ); // $ExpectError + variancewd( x.length, 1, x ); // $ExpectError + variancewd( x.length, 1, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + + variancewd.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number + variancewd.ndarray( x.length, 1, new AccessorArray( x ), 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancewd.ndarray( '10', 1, x, 1, 0 ); // $ExpectError + variancewd.ndarray( true, 1, x, 1, 0 ); // $ExpectError + variancewd.ndarray( false, 1, x, 1, 0 ); // $ExpectError + variancewd.ndarray( null, 1, x, 1, 0 ); // $ExpectError + variancewd.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError + variancewd.ndarray( [], 1, x, 1, 0 ); // $ExpectError + variancewd.ndarray( {}, 1, x, 1, 0 ); // $ExpectError + variancewd.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancewd.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, [], x, 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + variancewd.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, [ '1' ], 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancewd.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, x, true, 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, x, false, 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, x, null, 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, x, [], 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError + variancewd.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancewd.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError + variancewd.ndarray( x.length, 1, x, 1, true ); // $ExpectError + variancewd.ndarray( x.length, 1, x, 1, false ); // $ExpectError + variancewd.ndarray( x.length, 1, x, 1, null ); // $ExpectError + variancewd.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError + variancewd.ndarray( x.length, 1, x, 1, [] ); // $ExpectError + variancewd.ndarray( x.length, 1, x, 1, {} ); // $ExpectError + variancewd.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + variancewd.ndarray(); // $ExpectError + variancewd.ndarray( x.length ); // $ExpectError + variancewd.ndarray( x.length, 1 ); // $ExpectError + variancewd.ndarray( x.length, 1, x ); // $ExpectError + variancewd.ndarray( x.length, 1, x, 1 ); // $ExpectError + variancewd.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/examples/index.js b/lib/node_modules/@stdlib/stats/strided/variancewd/examples/index.js new file mode 100644 index 000000000000..91ef47630e9c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/examples/index.js @@ -0,0 +1,30 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var variancewd = require( './../lib' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +console.log( x ); + +var v = variancewd( x.length, 1, x, 1 ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/lib/accessors.js b/lib/node_modules/@stdlib/stats/strided/variancewd/lib/accessors.js new file mode 100644 index 000000000000..f09fecbe3ce4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/lib/accessors.js @@ -0,0 +1,118 @@ +/** +* @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'; + +// MAIN // + +/** +* Computes the variance of a strided array using Welford's algorithm. +* +* ## Method +* +* - This implementation uses Welford's algorithm for efficient computation, which can be derived as follows. Let +* +* ```tex +* \begin{align*} +* S_n &= n \sigma_n^2 \\ +* &= \sum_{i=1}^{n} (x_i - \mu_n)^2 \\ +* &= \biggl(\sum_{i=1}^{n} x_i^2 \biggr) - n\mu_n^2 +* \end{align*} +* ``` +* +* Accordingly, +* +* ```tex +* \begin{align*} +* S_n - S_{n-1} &= \sum_{i=1}^{n} x_i^2 - n\mu_n^2 - \sum_{i=1}^{n-1} x_i^2 + (n-1)\mu_{n-1}^2 \\ +* &= x_n^2 - n\mu_n^2 + (n-1)\mu_{n-1}^2 \\ +* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1}^2 - \mu_n^2) \\ +* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1} - \mu_n)(\mu_{n-1} + \mu_n) \\ +* &= x_n^2 - \mu_{n-1}^2 + (\mu_{n-1} - x_n)(\mu_{n-1} + \mu_n) \\ +* &= x_n^2 - \mu_{n-1}^2 + \mu_{n-1}^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ +* &= x_n^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ +* &= (x_n - \mu_{n-1})(x_n - \mu_n) \\ +* &= S_{n-1} + (x_n - \mu_{n-1})(x_n - \mu_n) +* \end{align*} +* ``` +* +* where we use the identity +* +* ```tex +* x_n - \mu_{n-1} = n (\mu_n - \mu_{n-1}) +* ``` +* +* ## References +* +* - Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022](https://doi.org/10.1080/00401706.1962.10490022). +* - van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961](https://doi.org/10.1145/362929.362961). +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} variance +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +* +* var v = variancewd( 4, 1, arraylike2object( x ), 2, 1 ); +* // returns 6.25 +*/ +function variancewd( N, correction, x, strideX, offsetX ) { + var delta; + var xbuf; + var get; + var mu; + var M2; + var ix; + var v; + var n; + var i; + + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessor: + get = x.accessors[ 0 ]; + + n = N - correction; + ix = offsetX; + M2 = 0.0; + mu = 0.0; + for ( i = 0; i < N; i++ ) { + v = get( xbuf, ix ); + delta = v - mu; + mu += delta / (i+1); + M2 += delta * ( v - mu ); + ix += strideX; + } + return M2 / n; +} + + +// EXPORTS // + +module.exports = variancewd; diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/lib/index.js b/lib/node_modules/@stdlib/stats/strided/variancewd/lib/index.js new file mode 100644 index 000000000000..e5b6c515b197 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/lib/index.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 the variance of a strided array using Welford's algorithm. +* +* @module @stdlib/stats/strided/variancewd +* +* @example +* var variancewd = require( '@stdlib/stats/strided/variancewd' ); +* +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancewd( x.length, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var variancewd = require( '@stdlib/stats/strided/variancewd' ); +* +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = variancewd.ndarray( 4, 1, x, 2, 1 ); +* // returns 6.25 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/lib/main.js b/lib/node_modules/@stdlib/stats/strided/variancewd/lib/main.js new file mode 100644 index 000000000000..ff478a018620 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/lib/main.js @@ -0,0 +1,90 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes the variance of a strided array using Welford's algorithm. +* +* ## Method +* +* - This implementation uses Welford's algorithm for efficient computation, which can be derived as follows. Let +* +* ```tex +* \begin{align*} +* S_n &= n \sigma_n^2 \\ +* &= \sum_{i=1}^{n} (x_i - \mu_n)^2 \\ +* &= \biggl(\sum_{i=1}^{n} x_i^2 \biggr) - n\mu_n^2 +* \end{align*} +* ``` +* +* Accordingly, +* +* ```tex +* \begin{align*} +* S_n - S_{n-1} &= \sum_{i=1}^{n} x_i^2 - n\mu_n^2 - \sum_{i=1}^{n-1} x_i^2 + (n-1)\mu_{n-1}^2 \\ +* &= x_n^2 - n\mu_n^2 + (n-1)\mu_{n-1}^2 \\ +* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1}^2 - \mu_n^2) \\ +* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1} - \mu_n)(\mu_{n-1} + \mu_n) \\ +* &= x_n^2 - \mu_{n-1}^2 + (\mu_{n-1} - x_n)(\mu_{n-1} + \mu_n) \\ +* &= x_n^2 - \mu_{n-1}^2 + \mu_{n-1}^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ +* &= x_n^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ +* &= (x_n - \mu_{n-1})(x_n - \mu_n) \\ +* &= S_{n-1} + (x_n - \mu_{n-1})(x_n - \mu_n) +* \end{align*} +* ``` +* +* where we use the identity +* +* ```tex +* x_n - \mu_{n-1} = n (\mu_n - \mu_{n-1}) +* ``` +* +* ## References +* +* - Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022](https://doi.org/10.1080/00401706.1962.10490022). +* - van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961](https://doi.org/10.1145/362929.362961). +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @returns {number} variance +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancewd( x.length, 1, x, 1 ); +* // returns ~4.3333 +*/ +function variancewd( N, correction, x, strideX ) { + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = variancewd; diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/variancewd/lib/ndarray.js new file mode 100644 index 000000000000..33ef0bc18b05 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/lib/ndarray.js @@ -0,0 +1,121 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Computes the variance of a strided array using Welford's algorithm. +* +* ## Method +* +* - This implementation uses Welford's algorithm for efficient computation, which can be derived as follows. Let +* +* ```tex +* \begin{align*} +* S_n &= n \sigma_n^2 \\ +* &= \sum_{i=1}^{n} (x_i - \mu_n)^2 \\ +* &= \biggl(\sum_{i=1}^{n} x_i^2 \biggr) - n\mu_n^2 +* \end{align*} +* ``` +* +* Accordingly, +* +* ```tex +* \begin{align*} +* S_n - S_{n-1} &= \sum_{i=1}^{n} x_i^2 - n\mu_n^2 - \sum_{i=1}^{n-1} x_i^2 + (n-1)\mu_{n-1}^2 \\ +* &= x_n^2 - n\mu_n^2 + (n-1)\mu_{n-1}^2 \\ +* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1}^2 - \mu_n^2) \\ +* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1} - \mu_n)(\mu_{n-1} + \mu_n) \\ +* &= x_n^2 - \mu_{n-1}^2 + (\mu_{n-1} - x_n)(\mu_{n-1} + \mu_n) \\ +* &= x_n^2 - \mu_{n-1}^2 + \mu_{n-1}^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ +* &= x_n^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ +* &= (x_n - \mu_{n-1})(x_n - \mu_n) \\ +* &= S_{n-1} + (x_n - \mu_{n-1})(x_n - \mu_n) +* \end{align*} +* ``` +* +* where we use the identity +* +* ```tex +* x_n - \mu_{n-1} = n (\mu_n - \mu_{n-1}) +* ``` +* +* ## References +* +* - Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022](https://doi.org/10.1080/00401706.1962.10490022). +* - van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961](https://doi.org/10.1145/362929.362961). +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} variance +* +* @example +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = variancewd( 4, 1, x, 2, 1 ); +* // returns 6.25 +*/ +function variancewd( N, correction, x, strideX, offsetX ) { + var delta; + var mu; + var M2; + var ix; + var o; + var v; + var n; + var i; + + n = N - correction; + if ( N <= 0 || n <= 0.0 ) { + return NaN; + } + if ( N === 1 || strideX === 0 ) { + return 0.0; + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, correction, o, strideX, offsetX ); + } + ix = offsetX; + M2 = 0.0; + mu = 0.0; + for ( i = 0; i < N; i++ ) { + v = x[ ix ]; + delta = v - mu; + mu += delta / (i+1); + M2 += delta * ( v - mu ); + ix += strideX; + } + return M2 / n; +} + + +// EXPORTS // + +module.exports = variancewd; diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/package.json b/lib/node_modules/@stdlib/stats/strided/variancewd/package.json new file mode 100644 index 000000000000..534bdecd1069 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/stats/strided/variancewd", + "version": "0.0.0", + "description": "Calculate the variance of a strided array using Welford's algorithm.", + "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", + "var", + "deviation", + "dispersion", + "sample variance", + "unbiased", + "stdev", + "std", + "standard deviation", + "welford", + "strided", + "strided array", + "typed", + "array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/test/test.js b/lib/node_modules/@stdlib/stats/strided/variancewd/test/test.js new file mode 100644 index 000000000000..600af51f7c5b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 variancewd = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variancewd, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof variancewd.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/variancewd/test/test.ndarray.js new file mode 100644 index 000000000000..7c4723cdc28b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/test/test.ndarray.js @@ -0,0 +1,350 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var variancewd = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variancewd, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( variancewd.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancewd( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancewd( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancewd( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancewd( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancewd( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancewd( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( 0, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancewd( -1, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( 0, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancewd( -1, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( 1, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( 1, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancewd( x.length, x.length+1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( x.length, x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancewd( x.length, x.length+1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancewd( 4, 1, x, 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancewd( 4, 1, toAccessorArray( x ), 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancewd( 4, 1, x, -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancewd( 4, 1, toAccessorArray( x ), -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( x.length, 1, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( x.length, 1, toAccessorArray( x ), 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + + v = variancewd( 4, 1, x, 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + + v = variancewd( 4, 1, toAccessorArray( x ), 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/test/test.variancewd.js b/lib/node_modules/@stdlib/stats/strided/variancewd/test/test.variancewd.js new file mode 100644 index 000000000000..7c8765a5717e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/test/test.variancewd.js @@ -0,0 +1,359 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var variancewd = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variancewd, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( variancewd.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancewd( x.length, 0, x, 1 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancewd( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancewd( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancewd( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancewd( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancewd( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancewd( x.length, 1, x, 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancewd( x.length, 1, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancewd( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancewd( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancewd( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancewd( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( 0, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancewd( -1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( 0, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancewd( -1, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( 1, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancewd( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( x.length, x.length, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancewd( x.length, x.length+1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancewd( 4, 1, x, 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancewd( 4, 1, toAccessorArray( x ), 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancewd( 4, 1, x, -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancewd( 4, 1, toAccessorArray( x ), -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancewd( x.length, 1, toAccessorArray( x ), 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = variancewd( 4, 1, x1, 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets (accessors)', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = variancewd( 4, 1, toAccessorArray( x1 ), 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); From 4b188ff7c846578420c778122caa4ee0c9584e09 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 13:57:31 +0000 Subject: [PATCH 11/32] remove: remove `variancewd` from namespace This commit removes the `variancewd` symbol from the `@stdlib/stats/base` namespace due to a package migration. BREAKING CHANGE: remove `variancewd` To migrate, users should access the same symbol via the `@stdlib/stats/strided` namespace. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/docs/types/index.d.ts | 24 ------------------- .../@stdlib/stats/base/lib/index.js | 9 ------- 2 files changed, 33 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts index 5a01d919f521..23e1cb85ccf0 100644 --- a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts @@ -70,7 +70,6 @@ import variance = require( '@stdlib/stats/base/variance' ); import variancech = require( '@stdlib/stats/base/variancech' ); import variancepn = require( '@stdlib/stats/base/variancepn' ); import variancetk = require( '@stdlib/stats/base/variancetk' ); -import variancewd = require( '@stdlib/stats/base/variancewd' ); import dmeankbn2 = require( '@stdlib/stats/strided/dmeankbn2' ); import dmeanli = require( '@stdlib/stats/strided/dmeanli' ); import dmeanlipw = require( '@stdlib/stats/strided/dmeanlipw' ); @@ -1345,29 +1344,6 @@ interface Namespace { */ variancetk: typeof variancetk; - /** - * Computes the variance of a strided array using Welford's algorithm. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param stride - stride length - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = ns.variancewd( x.length, 1, x, 1 ); - * // returns ~4.3333 - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = ns.variancewd.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - variancewd: typeof variancewd; - /** * Computes the arithmetic mean of a double-precision floating-point strided array using a second-order iterative Kahan–Babuška algorithm. * diff --git a/lib/node_modules/@stdlib/stats/base/lib/index.js b/lib/node_modules/@stdlib/stats/base/lib/index.js index f817ca72d9fd..8d0a5f86f428 100644 --- a/lib/node_modules/@stdlib/stats/base/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/lib/index.js @@ -495,15 +495,6 @@ setReadOnly( ns, 'variancepn', require( '@stdlib/stats/base/variancepn' ) ); */ setReadOnly( ns, 'variancetk', require( '@stdlib/stats/base/variancetk' ) ); -/** -* @name variancewd -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/stats/base/variancewd} -*/ -setReadOnly( ns, 'variancewd', require( '@stdlib/stats/base/variancewd' ) ); - /** * @name dmeankbn2 * @memberof ns From 7088dfa1cab0860d25b5a0feb649ec572cbc1e98 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 13:58:43 +0000 Subject: [PATCH 12/32] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/namespace/lib/namespace/base/strided/d.js | 2 +- .../@stdlib/namespace/lib/namespace/base/strided/n.js | 2 +- .../@stdlib/namespace/lib/namespace/base/strided/s.js | 4 ++-- .../@stdlib/namespace/lib/namespace/base/strided/v.js | 4 ++-- lib/node_modules/@stdlib/stats/array/variancewd/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/base/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/stdevwd/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/stdevwd/lib/ndarray.js | 2 +- lib/node_modules/@stdlib/stats/base/stdevwd/lib/stdevwd.js | 2 +- lib/node_modules/@stdlib/stats/strided/dvariancewd/README.md | 4 ++-- lib/node_modules/@stdlib/stats/strided/svariancewd/README.md | 4 ++-- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js index 6730b5d4b4e5..1be1e5084d1a 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js @@ -2309,7 +2309,7 @@ ns.push({ '@stdlib/stats/strided/dstdevwd', '@stdlib/stats/strided/dvariance', '@stdlib/stats/strided/svariancewd', - '@stdlib/stats/base/variancewd' + '@stdlib/stats/strided/variancewd' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js index fc15cf1b8325..bcc4d46fa58f 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js @@ -382,7 +382,7 @@ ns.push({ '@stdlib/stats/base/nanstdevwd', '@stdlib/stats/base/nanvariance', '@stdlib/stats/base/snanvariancewd', - '@stdlib/stats/base/variancewd' + '@stdlib/stats/strided/variancewd' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js index b9a21704ff4f..f907062fe591 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js @@ -1854,7 +1854,7 @@ ns.push({ '@stdlib/stats/base/nanstdevwd', '@stdlib/stats/base/sstdevwd', '@stdlib/stats/base/stdev', - '@stdlib/stats/base/variancewd' + '@stdlib/stats/strided/variancewd' ] }); @@ -1957,7 +1957,7 @@ ns.push({ '@stdlib/stats/base/snanvariancewd', '@stdlib/stats/base/sstdevwd', '@stdlib/stats/strided/svariance', - '@stdlib/stats/base/variancewd' + '@stdlib/stats/strided/variancewd' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js index ba21e9ad7618..a8a39c2dd6a7 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js @@ -82,8 +82,8 @@ ns.push({ ns.push({ 'alias': 'base.strided.variancewd', - 'path': '@stdlib/stats/base/variancewd', - 'value': require( '@stdlib/stats/base/variancewd' ), + 'path': '@stdlib/stats/strided/variancewd', + 'value': require( '@stdlib/stats/strided/variancewd' ), 'type': 'Function', 'related': [ '@stdlib/stats/strided/dvariancewd', diff --git a/lib/node_modules/@stdlib/stats/array/variancewd/lib/main.js b/lib/node_modules/@stdlib/stats/array/variancewd/lib/main.js index 55ab84b14498..8cfc135f7436 100644 --- a/lib/node_modules/@stdlib/stats/array/variancewd/lib/main.js +++ b/lib/node_modules/@stdlib/stats/array/variancewd/lib/main.js @@ -26,7 +26,7 @@ var dtypes = require( '@stdlib/array/dtypes' ); var dtype = require( '@stdlib/array/dtype' ); var contains = require( '@stdlib/array/base/assert/contains' ); var join = require( '@stdlib/array/base/join' ); -var strided = require( '@stdlib/stats/base/variancewd' ).ndarray; +var strided = require( '@stdlib/stats/strided/variancewd' ).ndarray; var format = require( '@stdlib/string/format' ); diff --git a/lib/node_modules/@stdlib/stats/base/README.md b/lib/node_modules/@stdlib/stats/base/README.md index eb3c619fcbc7..57a489d7b334 100644 --- a/lib/node_modules/@stdlib/stats/base/README.md +++ b/lib/node_modules/@stdlib/stats/base/README.md @@ -111,7 +111,7 @@ The namespace contains the following statistical functions: - [`variancech( N, correction, x, strideX )`][@stdlib/stats/base/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. - [`variancepn( N, correction, x, strideX )`][@stdlib/stats/base/variancepn]: calculate the variance of a strided array using a two-pass algorithm. - [`variancetk( N, correction, x, strideX )`][@stdlib/stats/base/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. -- [`variancewd( N, correction, x, stride )`][@stdlib/stats/base/variancewd]: calculate the variance of a strided array using Welford's algorithm. +- [`variancewd( N, correction, x, stride )`][@stdlib/stats/strided/variancewd]: calculate the variance of a strided array using Welford's algorithm. - [`varianceyc( N, correction, x, strideX )`][@stdlib/stats/strided/varianceyc]: calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. @@ -271,7 +271,7 @@ console.log( objectKeys( ns ) ); [@stdlib/stats/base/variancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancetk -[@stdlib/stats/base/variancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancewd +[@stdlib/stats/strided/variancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancewd [@stdlib/stats/strided/varianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/varianceyc diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md b/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md index af9e54593c77..9003e8c35e89 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md @@ -235,7 +235,7 @@ console.log( v ); - [`@stdlib/stats/base/nanstdevwd`][@stdlib/stats/base/nanstdevwd]: calculate the standard deviation of a strided array ignoring NaN values and using Welford's algorithm. - [`@stdlib/stats/base/nanvariance`][@stdlib/stats/base/nanvariance]: calculate the variance of a strided array ignoring NaN values. - [`@stdlib/stats/base/snanvariancewd`][@stdlib/stats/base/snanvariancewd]: calculate the variance of a single-precision floating-point strided array ignoring NaN values and using Welford's algorithm. -- [`@stdlib/stats/base/variancewd`][@stdlib/stats/base/variancewd]: calculate the variance of a strided array using Welford's algorithm. +- [`@stdlib/stats/strided/variancewd`][@stdlib/stats/strided/variancewd]: calculate the variance of a strided array using Welford's algorithm. @@ -267,7 +267,7 @@ console.log( v ); [@stdlib/stats/base/snanvariancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/snanvariancewd -[@stdlib/stats/base/variancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancewd +[@stdlib/stats/strided/variancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancewd diff --git a/lib/node_modules/@stdlib/stats/base/stdevwd/README.md b/lib/node_modules/@stdlib/stats/base/stdevwd/README.md index 1589e85c4feb..dacfdb543972 100644 --- a/lib/node_modules/@stdlib/stats/base/stdevwd/README.md +++ b/lib/node_modules/@stdlib/stats/base/stdevwd/README.md @@ -242,7 +242,7 @@ console.log( v ); - [`@stdlib/stats/base/nanstdevwd`][@stdlib/stats/base/nanstdevwd]: calculate the standard deviation of a strided array ignoring NaN values and using Welford's algorithm. - [`@stdlib/stats/base/sstdevwd`][@stdlib/stats/base/sstdevwd]: calculate the standard deviation of a single-precision floating-point strided array using Welford's algorithm. - [`@stdlib/stats/base/stdev`][@stdlib/stats/base/stdev]: calculate the standard deviation of a strided array. -- [`@stdlib/stats/base/variancewd`][@stdlib/stats/base/variancewd]: calculate the variance of a strided array using Welford's algorithm. +- [`@stdlib/stats/strided/variancewd`][@stdlib/stats/strided/variancewd]: calculate the variance of a strided array using Welford's algorithm. @@ -272,7 +272,7 @@ console.log( v ); [@stdlib/stats/base/stdev]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/stdev -[@stdlib/stats/base/variancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancewd +[@stdlib/stats/strided/variancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancewd diff --git a/lib/node_modules/@stdlib/stats/base/stdevwd/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/stdevwd/lib/ndarray.js index 0b03592656f9..f31809bdc91f 100644 --- a/lib/node_modules/@stdlib/stats/base/stdevwd/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/stdevwd/lib/ndarray.js @@ -20,7 +20,7 @@ // MODULES // -var variancewd = require( '@stdlib/stats/base/variancewd' ).ndarray; +var variancewd = require( '@stdlib/stats/strided/variancewd' ).ndarray; var sqrt = require( '@stdlib/math/base/special/sqrt' ); diff --git a/lib/node_modules/@stdlib/stats/base/stdevwd/lib/stdevwd.js b/lib/node_modules/@stdlib/stats/base/stdevwd/lib/stdevwd.js index e3aeb8783a61..326eaf7f016d 100644 --- a/lib/node_modules/@stdlib/stats/base/stdevwd/lib/stdevwd.js +++ b/lib/node_modules/@stdlib/stats/base/stdevwd/lib/stdevwd.js @@ -20,7 +20,7 @@ // MODULES // -var variancewd = require( '@stdlib/stats/base/variancewd' ); +var variancewd = require( '@stdlib/stats/strided/variancewd' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); diff --git a/lib/node_modules/@stdlib/stats/strided/dvariancewd/README.md b/lib/node_modules/@stdlib/stats/strided/dvariancewd/README.md index 5845edea1382..99b8f851d574 100644 --- a/lib/node_modules/@stdlib/stats/strided/dvariancewd/README.md +++ b/lib/node_modules/@stdlib/stats/strided/dvariancewd/README.md @@ -353,7 +353,7 @@ int main( void ) { - [`@stdlib/stats/strided/dstdevwd`][@stdlib/stats/strided/dstdevwd]: calculate the standard deviation of a double-precision floating-point strided array using Welford's algorithm. - [`@stdlib/stats/strided/dvariance`][@stdlib/stats/strided/dvariance]: calculate the variance of a double-precision floating-point strided array. - [`@stdlib/stats/strided/svariancewd`][@stdlib/stats/strided/svariancewd]: calculate the variance of a single-precision floating-point strided array using Welford's algorithm. -- [`@stdlib/stats/base/variancewd`][@stdlib/stats/base/variancewd]: calculate the variance of a strided array using Welford's algorithm. +- [`@stdlib/stats/strided/variancewd`][@stdlib/stats/strided/variancewd]: calculate the variance of a strided array using Welford's algorithm. @@ -383,7 +383,7 @@ int main( void ) { [@stdlib/stats/strided/svariancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancewd -[@stdlib/stats/base/variancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancewd +[@stdlib/stats/strided/variancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancewd diff --git a/lib/node_modules/@stdlib/stats/strided/svariancewd/README.md b/lib/node_modules/@stdlib/stats/strided/svariancewd/README.md index 8e3fa74a113f..5bad262bbe6a 100644 --- a/lib/node_modules/@stdlib/stats/strided/svariancewd/README.md +++ b/lib/node_modules/@stdlib/stats/strided/svariancewd/README.md @@ -353,7 +353,7 @@ int main( void ) { - [`@stdlib/stats/base/snanvariancewd`][@stdlib/stats/base/snanvariancewd]: calculate the variance of a single-precision floating-point strided array ignoring NaN values and using Welford's algorithm. - [`@stdlib/stats/base/sstdevwd`][@stdlib/stats/base/sstdevwd]: calculate the standard deviation of a single-precision floating-point strided array using Welford's algorithm. - [`@stdlib/stats/strided/svariance`][@stdlib/stats/strided/svariance]: calculate the variance of a single-precision floating-point strided array. -- [`@stdlib/stats/base/variancewd`][@stdlib/stats/base/variancewd]: calculate the variance of a strided array using Welford's algorithm. +- [`@stdlib/stats/strided/variancewd`][@stdlib/stats/strided/variancewd]: calculate the variance of a strided array using Welford's algorithm. @@ -383,7 +383,7 @@ int main( void ) { [@stdlib/stats/strided/svariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariance -[@stdlib/stats/base/variancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancewd +[@stdlib/stats/strided/variancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancewd From b7d4e42e1a3bf94f552ceb3d2fcf19fbf5da4449 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:00:29 +0000 Subject: [PATCH 13/32] remove: remove `stats/base/variancewd` This commit removes `@stdlib/stats/base/variancewd` in favor of `@stdlib/stats/strided/variancewd`. BREAKING CHANGE: remove `stats/base/variancewd` To migrate, users should update their require/import paths to use `@stdlib/stats/strided/variancewd`, which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/variancewd/README.md | 268 ------------- .../base/variancewd/benchmark/benchmark.js | 96 ----- .../variancewd/benchmark/benchmark.ndarray.js | 96 ----- .../docs/img/equation_population_mean.svg | 42 -- .../docs/img/equation_population_variance.svg | 54 --- .../docs/img/equation_sample_mean.svg | 43 --- .../img/equation_unbiased_sample_variance.svg | 61 --- .../stats/base/variancewd/docs/repl.txt | 113 ------ .../base/variancewd/docs/types/index.d.ts | 96 ----- .../stats/base/variancewd/docs/types/test.ts | 190 --------- .../stats/base/variancewd/examples/index.js | 30 -- .../stats/base/variancewd/lib/accessors.js | 118 ------ .../stats/base/variancewd/lib/index.js | 59 --- .../@stdlib/stats/base/variancewd/lib/main.js | 90 ----- .../stats/base/variancewd/lib/ndarray.js | 121 ------ .../stats/base/variancewd/package.json | 74 ---- .../stats/base/variancewd/test/test.js | 38 -- .../base/variancewd/test/test.ndarray.js | 350 ----------------- .../base/variancewd/test/test.variancewd.js | 359 ------------------ 19 files changed, 2298 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/README.md delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/benchmark/benchmark.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_population_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_population_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_sample_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_unbiased_sample_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/examples/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/lib/accessors.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/lib/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/lib/main.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/lib/ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/package.json delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/test/test.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/test/test.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancewd/test/test.variancewd.js diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/README.md b/lib/node_modules/@stdlib/stats/base/variancewd/README.md deleted file mode 100644 index 5d449dddd103..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/README.md +++ /dev/null @@ -1,268 +0,0 @@ - - -# variancewd - -> Calculate the [variance][variance] of a strided array using Welford's algorithm. - -
- -The population [variance][variance] of a finite size population of size `N` is given by - - - -```math -\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 -``` - - - - - -where the population mean is given by - - - -```math -\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i -``` - - - - - -Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, - - - -```math -s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 -``` - - - - - -where the sample mean is given by - - - -```math -\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i -``` - - - - - -The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. - -
- - - -
- -## Usage - -```javascript -var variancewd = require( '@stdlib/stats/base/variancewd' ); -``` - -#### variancewd( N, correction, x, strideX ) - -Computes the [variance][variance] of a strided array using Welford's algorithm. - -```javascript -var x = [ 1.0, -2.0, 2.0 ]; - -var v = variancewd( x.length, 1, x, 1 ); -// returns ~4.3333 -``` - -The function has the following parameters: - -- **N**: number of indexed elements. -- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. -- **strideX**: stride length for `x`. - -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, - -```javascript -var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; - -var v = variancewd( 4, 1, x, 2 ); -// returns 6.25 -``` - -Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); - -var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - -var v = variancewd( 4, 1, x1, 2 ); -// returns 6.25 -``` - -#### variancewd.ndarray( N, correction, x, strideX, offsetX ) - -Computes the [variance][variance] of a strided array using Welford's algorithm and alternative indexing semantics. - -```javascript -var x = [ 1.0, -2.0, 2.0 ]; - -var v = variancewd.ndarray( x.length, 1, x, 1, 0 ); -// returns ~4.33333 -``` - -The function has the following additional parameters: - -- **offset**: starting index for `x`. - -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element - -```javascript -var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; - -var v = variancewd.ndarray( 4, 1, x, 2, 1 ); -// returns 6.25 -``` - -
- - - -
- -## Notes - -- If `N <= 0`, both functions return `NaN`. -- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. -- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). -- Depending on the environment, the typed versions ([`dvariancewd`][@stdlib/stats/strided/dvariancewd], [`svariancewd`][@stdlib/stats/strided/svariancewd], etc.) are likely to be significantly more performant. - -
- - - -
- -## Examples - - - -```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var variancewd = require( '@stdlib/stats/base/variancewd' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); -console.log( x ); - -var v = variancewd( x.length, 1, x, 1 ); -console.log( v ); -``` - -
- - - -* * * - -
- -## References - -- Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022][@welford:1962a]. -- van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961][@vanreeken:1968a]. - -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/variancewd/benchmark/benchmark.js deleted file mode 100644 index 653a13db7e47..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/benchmark/benchmark.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var variancewd = require( './../lib/main.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = variancewd( x.length, 1, x, 1 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/variancewd/benchmark/benchmark.ndarray.js deleted file mode 100644 index bf5fd4fa45d7..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var variancewd = require( './../lib/ndarray.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = variancewd( x.length, 1, x, 1, 0 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':ndarray:len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_population_mean.svg deleted file mode 100644 index 4bbdf0d2a56f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_population_mean.svg +++ /dev/null @@ -1,42 +0,0 @@ - -mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_population_variance.svg deleted file mode 100644 index 4130ba0750d2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_population_variance.svg +++ /dev/null @@ -1,54 +0,0 @@ - -sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_sample_mean.svg deleted file mode 100644 index aea7a5f6687a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_sample_mean.svg +++ /dev/null @@ -1,43 +0,0 @@ - -x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_unbiased_sample_variance.svg deleted file mode 100644 index 1ae1283e7fb1..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/docs/img/equation_unbiased_sample_variance.svg +++ /dev/null @@ -1,61 +0,0 @@ - -s squared equals 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 - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/variancewd/docs/repl.txt deleted file mode 100644 index 6ccd6f6054f8..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/docs/repl.txt +++ /dev/null @@ -1,113 +0,0 @@ - -{{alias}}( N, correction, x, strideX ) - Computes the variance of a strided array using Welford's algorithm. - - The `N` and stride parameters determine which elements in the strided array - are accessed at runtime. - - Indexing is relative to the first index. To introduce an offset, use a typed - array view. - - If `N <= 0`, the function returns `NaN`. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Array|TypedArray - Input array. - - strideX: integer - Stride length. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = [ 1.0, -2.0, 2.0 ]; - > {{alias}}( x.length, 1, x, 1 ) - ~4.3333 - - // Using `N` and stride parameters: - > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; - > {{alias}}( 3, 1, x, 2 ) - ~4.3333 - - // Using view offsets: - > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 1, x1, 2 ) - ~4.3333 - - -{{alias}}.ndarray( N, correction, x, strideX, offsetX ) - Computes the variance of a strided array using Welford's algorithm and - alternative indexing semantics. - - While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a - starting index. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Array|TypedArray - Input array. - - strideX: integer - Stride length. - - offsetX: integer - Starting index. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = [ 1.0, -2.0, 2.0 ]; - > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) - ~4.3333 - - // Using offset parameter: - > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; - > {{alias}}.ndarray( 3, 1, x, 2, 1 ) - ~4.3333 - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/variancewd/docs/types/index.d.ts deleted file mode 100644 index 3671308bf4c5..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/docs/types/index.d.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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 - -/// - -import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; - -/** -* Input array. -*/ -type InputArray = NumericArray | Collection | AccessorArrayLike; - -/** -* Interface describing `variancewd`. -*/ -interface Routine { - /** - * Computes the variance of a strided array using Welford's algorithm. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = variancewd( x.length, 1, x, 1 ); - * // returns ~4.3333 - */ - ( N: number, correction: number, x: InputArray, strideX: number ): number; - - /** - * Computes the variance of a strided array using Welford's algorithm and alternative indexing semantics. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @param offsetX - starting index - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = variancewd.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - ndarray( N: number, correction: number, x: InputArray, strideX: number, offsetX: number ): number; -} - -/** -* Computes the variance of a strided array using Welford's algorithm. -* -* @param N - number of indexed elements -* @param correction - degrees of freedom adjustment -* @param x - input array -* @param strideX - stride length -* @returns variance -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancewd( x.length, 1, x, 1 ); -* // returns ~4.3333 -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancewd.ndarray( x.length, 1, x, 1, 0 ); -* // returns ~4.3333 -*/ -declare var variancewd: Routine; - - -// EXPORTS // - -export = variancewd; diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/variancewd/docs/types/test.ts deleted file mode 100644 index 0a4d061c50ec..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/docs/types/test.ts +++ /dev/null @@ -1,190 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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 AccessorArray = require( '@stdlib/array/base/accessor' ); -import variancewd = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const x = new Float64Array( 10 ); - - variancewd( x.length, 1, x, 1 ); // $ExpectType number - variancewd( x.length, 1, new AccessorArray( x ), 1 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancewd( '10', 1, x, 1 ); // $ExpectError - variancewd( true, 1, x, 1 ); // $ExpectError - variancewd( false, 1, x, 1 ); // $ExpectError - variancewd( null, 1, x, 1 ); // $ExpectError - variancewd( undefined, 1, x, 1 ); // $ExpectError - variancewd( [], 1, x, 1 ); // $ExpectError - variancewd( {}, 1, x, 1 ); // $ExpectError - variancewd( ( x: number ): number => x, 1, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancewd( x.length, '10', x, 1 ); // $ExpectError - variancewd( x.length, true, x, 1 ); // $ExpectError - variancewd( x.length, false, x, 1 ); // $ExpectError - variancewd( x.length, null, x, 1 ); // $ExpectError - variancewd( x.length, undefined, x, 1 ); // $ExpectError - variancewd( x.length, [], x, 1 ); // $ExpectError - variancewd( x.length, {}, x, 1 ); // $ExpectError - variancewd( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a numeric array... -{ - const x = new Float64Array( 10 ); - - variancewd( x.length, 1, 10, 1 ); // $ExpectError - variancewd( x.length, 1, '10', 1 ); // $ExpectError - variancewd( x.length, 1, true, 1 ); // $ExpectError - variancewd( x.length, 1, false, 1 ); // $ExpectError - variancewd( x.length, 1, null, 1 ); // $ExpectError - variancewd( x.length, 1, undefined, 1 ); // $ExpectError - variancewd( x.length, 1, [ '1' ], 1 ); // $ExpectError - variancewd( x.length, 1, {}, 1 ); // $ExpectError - variancewd( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancewd( x.length, 1, x, '10' ); // $ExpectError - variancewd( x.length, 1, x, true ); // $ExpectError - variancewd( x.length, 1, x, false ); // $ExpectError - variancewd( x.length, 1, x, null ); // $ExpectError - variancewd( x.length, 1, x, undefined ); // $ExpectError - variancewd( x.length, 1, x, [] ); // $ExpectError - variancewd( x.length, 1, x, {} ); // $ExpectError - variancewd( x.length, 1, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - - variancewd(); // $ExpectError - variancewd( x.length ); // $ExpectError - variancewd( x.length, 1 ); // $ExpectError - variancewd( x.length, 1, x ); // $ExpectError - variancewd( x.length, 1, x, 1, 10 ); // $ExpectError -} - -// Attached to main export is an `ndarray` method which returns a number... -{ - const x = new Float64Array( 10 ); - - variancewd.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number - variancewd.ndarray( x.length, 1, new AccessorArray( x ), 1, 0 ); // $ExpectType number -} - -// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancewd.ndarray( '10', 1, x, 1, 0 ); // $ExpectError - variancewd.ndarray( true, 1, x, 1, 0 ); // $ExpectError - variancewd.ndarray( false, 1, x, 1, 0 ); // $ExpectError - variancewd.ndarray( null, 1, x, 1, 0 ); // $ExpectError - variancewd.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError - variancewd.ndarray( [], 1, x, 1, 0 ); // $ExpectError - variancewd.ndarray( {}, 1, x, 1, 0 ); // $ExpectError - variancewd.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancewd.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, true, x, 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, false, x, 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, null, x, 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, [], x, 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... -{ - const x = new Float64Array( 10 ); - - variancewd.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, [ '1' ], 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancewd.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, x, true, 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, x, false, 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, x, null, 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, x, [], 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError - variancewd.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancewd.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError - variancewd.ndarray( x.length, 1, x, 1, true ); // $ExpectError - variancewd.ndarray( x.length, 1, x, 1, false ); // $ExpectError - variancewd.ndarray( x.length, 1, x, 1, null ); // $ExpectError - variancewd.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError - variancewd.ndarray( x.length, 1, x, 1, [] ); // $ExpectError - variancewd.ndarray( x.length, 1, x, 1, {} ); // $ExpectError - variancewd.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - - variancewd.ndarray(); // $ExpectError - variancewd.ndarray( x.length ); // $ExpectError - variancewd.ndarray( x.length, 1 ); // $ExpectError - variancewd.ndarray( x.length, 1, x ); // $ExpectError - variancewd.ndarray( x.length, 1, x, 1 ); // $ExpectError - variancewd.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/examples/index.js b/lib/node_modules/@stdlib/stats/base/variancewd/examples/index.js deleted file mode 100644 index 91ef47630e9c..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/examples/index.js +++ /dev/null @@ -1,30 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var variancewd = require( './../lib' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); -console.log( x ); - -var v = variancewd( x.length, 1, x, 1 ); -console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/variancewd/lib/accessors.js deleted file mode 100644 index f09fecbe3ce4..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/lib/accessors.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @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'; - -// MAIN // - -/** -* Computes the variance of a strided array using Welford's algorithm. -* -* ## Method -* -* - This implementation uses Welford's algorithm for efficient computation, which can be derived as follows. Let -* -* ```tex -* \begin{align*} -* S_n &= n \sigma_n^2 \\ -* &= \sum_{i=1}^{n} (x_i - \mu_n)^2 \\ -* &= \biggl(\sum_{i=1}^{n} x_i^2 \biggr) - n\mu_n^2 -* \end{align*} -* ``` -* -* Accordingly, -* -* ```tex -* \begin{align*} -* S_n - S_{n-1} &= \sum_{i=1}^{n} x_i^2 - n\mu_n^2 - \sum_{i=1}^{n-1} x_i^2 + (n-1)\mu_{n-1}^2 \\ -* &= x_n^2 - n\mu_n^2 + (n-1)\mu_{n-1}^2 \\ -* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1}^2 - \mu_n^2) \\ -* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1} - \mu_n)(\mu_{n-1} + \mu_n) \\ -* &= x_n^2 - \mu_{n-1}^2 + (\mu_{n-1} - x_n)(\mu_{n-1} + \mu_n) \\ -* &= x_n^2 - \mu_{n-1}^2 + \mu_{n-1}^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ -* &= x_n^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ -* &= (x_n - \mu_{n-1})(x_n - \mu_n) \\ -* &= S_{n-1} + (x_n - \mu_{n-1})(x_n - \mu_n) -* \end{align*} -* ``` -* -* where we use the identity -* -* ```tex -* x_n - \mu_{n-1} = n (\mu_n - \mu_{n-1}) -* ``` -* -* ## References -* -* - Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022](https://doi.org/10.1080/00401706.1962.10490022). -* - van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961](https://doi.org/10.1145/362929.362961). -* -* @private -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {Object} x - input array object -* @param {Collection} x.data - input array data -* @param {Array} x.accessors - array element accessors -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index -* @returns {number} variance -* -* @example -* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -* -* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* -* var v = variancewd( 4, 1, arraylike2object( x ), 2, 1 ); -* // returns 6.25 -*/ -function variancewd( N, correction, x, strideX, offsetX ) { - var delta; - var xbuf; - var get; - var mu; - var M2; - var ix; - var v; - var n; - var i; - - // Cache reference to array data: - xbuf = x.data; - - // Cache a reference to the element accessor: - get = x.accessors[ 0 ]; - - n = N - correction; - ix = offsetX; - M2 = 0.0; - mu = 0.0; - for ( i = 0; i < N; i++ ) { - v = get( xbuf, ix ); - delta = v - mu; - mu += delta / (i+1); - M2 += delta * ( v - mu ); - ix += strideX; - } - return M2 / n; -} - - -// EXPORTS // - -module.exports = variancewd; diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/lib/index.js b/lib/node_modules/@stdlib/stats/base/variancewd/lib/index.js deleted file mode 100644 index bc70d9596cdd..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/lib/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 the variance of a strided array using Welford's algorithm. -* -* @module @stdlib/stats/base/variancewd -* -* @example -* var variancewd = require( '@stdlib/stats/base/variancewd' ); -* -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancewd( x.length, 1, x, 1 ); -* // returns ~4.3333 -* -* @example -* var variancewd = require( '@stdlib/stats/base/variancewd' ); -* -* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* -* var v = variancewd.ndarray( 4, 1, x, 2, 1 ); -* // returns 6.25 -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var ndarray = require( './ndarray.js' ); - - -// MAIN // - -setReadOnly( main, 'ndarray', ndarray ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/lib/main.js b/lib/node_modules/@stdlib/stats/base/variancewd/lib/main.js deleted file mode 100644 index ff478a018620..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/lib/main.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); -var ndarray = require( './ndarray.js' ); - - -// MAIN // - -/** -* Computes the variance of a strided array using Welford's algorithm. -* -* ## Method -* -* - This implementation uses Welford's algorithm for efficient computation, which can be derived as follows. Let -* -* ```tex -* \begin{align*} -* S_n &= n \sigma_n^2 \\ -* &= \sum_{i=1}^{n} (x_i - \mu_n)^2 \\ -* &= \biggl(\sum_{i=1}^{n} x_i^2 \biggr) - n\mu_n^2 -* \end{align*} -* ``` -* -* Accordingly, -* -* ```tex -* \begin{align*} -* S_n - S_{n-1} &= \sum_{i=1}^{n} x_i^2 - n\mu_n^2 - \sum_{i=1}^{n-1} x_i^2 + (n-1)\mu_{n-1}^2 \\ -* &= x_n^2 - n\mu_n^2 + (n-1)\mu_{n-1}^2 \\ -* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1}^2 - \mu_n^2) \\ -* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1} - \mu_n)(\mu_{n-1} + \mu_n) \\ -* &= x_n^2 - \mu_{n-1}^2 + (\mu_{n-1} - x_n)(\mu_{n-1} + \mu_n) \\ -* &= x_n^2 - \mu_{n-1}^2 + \mu_{n-1}^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ -* &= x_n^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ -* &= (x_n - \mu_{n-1})(x_n - \mu_n) \\ -* &= S_{n-1} + (x_n - \mu_{n-1})(x_n - \mu_n) -* \end{align*} -* ``` -* -* where we use the identity -* -* ```tex -* x_n - \mu_{n-1} = n (\mu_n - \mu_{n-1}) -* ``` -* -* ## References -* -* - Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022](https://doi.org/10.1080/00401706.1962.10490022). -* - van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961](https://doi.org/10.1145/362929.362961). -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array -* @param {integer} strideX - stride length -* @returns {number} variance -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancewd( x.length, 1, x, 1 ); -* // returns ~4.3333 -*/ -function variancewd( N, correction, x, strideX ) { - return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); -} - - -// EXPORTS // - -module.exports = variancewd; diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/variancewd/lib/ndarray.js deleted file mode 100644 index 33ef0bc18b05..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/lib/ndarray.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -var accessors = require( './accessors.js' ); - - -// MAIN // - -/** -* Computes the variance of a strided array using Welford's algorithm. -* -* ## Method -* -* - This implementation uses Welford's algorithm for efficient computation, which can be derived as follows. Let -* -* ```tex -* \begin{align*} -* S_n &= n \sigma_n^2 \\ -* &= \sum_{i=1}^{n} (x_i - \mu_n)^2 \\ -* &= \biggl(\sum_{i=1}^{n} x_i^2 \biggr) - n\mu_n^2 -* \end{align*} -* ``` -* -* Accordingly, -* -* ```tex -* \begin{align*} -* S_n - S_{n-1} &= \sum_{i=1}^{n} x_i^2 - n\mu_n^2 - \sum_{i=1}^{n-1} x_i^2 + (n-1)\mu_{n-1}^2 \\ -* &= x_n^2 - n\mu_n^2 + (n-1)\mu_{n-1}^2 \\ -* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1}^2 - \mu_n^2) \\ -* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1} - \mu_n)(\mu_{n-1} + \mu_n) \\ -* &= x_n^2 - \mu_{n-1}^2 + (\mu_{n-1} - x_n)(\mu_{n-1} + \mu_n) \\ -* &= x_n^2 - \mu_{n-1}^2 + \mu_{n-1}^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ -* &= x_n^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ -* &= (x_n - \mu_{n-1})(x_n - \mu_n) \\ -* &= S_{n-1} + (x_n - \mu_{n-1})(x_n - \mu_n) -* \end{align*} -* ``` -* -* where we use the identity -* -* ```tex -* x_n - \mu_{n-1} = n (\mu_n - \mu_{n-1}) -* ``` -* -* ## References -* -* - Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022](https://doi.org/10.1080/00401706.1962.10490022). -* - van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961](https://doi.org/10.1145/362929.362961). -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index -* @returns {number} variance -* -* @example -* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* -* var v = variancewd( 4, 1, x, 2, 1 ); -* // returns 6.25 -*/ -function variancewd( N, correction, x, strideX, offsetX ) { - var delta; - var mu; - var M2; - var ix; - var o; - var v; - var n; - var i; - - n = N - correction; - if ( N <= 0 || n <= 0.0 ) { - return NaN; - } - if ( N === 1 || strideX === 0 ) { - return 0.0; - } - o = arraylike2object( x ); - if ( o.accessorProtocol ) { - return accessors( N, correction, o, strideX, offsetX ); - } - ix = offsetX; - M2 = 0.0; - mu = 0.0; - for ( i = 0; i < N; i++ ) { - v = x[ ix ]; - delta = v - mu; - mu += delta / (i+1); - M2 += delta * ( v - mu ); - ix += strideX; - } - return M2 / n; -} - - -// EXPORTS // - -module.exports = variancewd; diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/package.json b/lib/node_modules/@stdlib/stats/base/variancewd/package.json deleted file mode 100644 index 13ddb38e042f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/package.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "name": "@stdlib/stats/base/variancewd", - "version": "0.0.0", - "description": "Calculate the variance of a strided array using Welford's algorithm.", - "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", - "var", - "deviation", - "dispersion", - "sample variance", - "unbiased", - "stdev", - "std", - "standard deviation", - "welford", - "strided", - "strided array", - "typed", - "array" - ], - "__stdlib__": {} -} diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/test/test.js b/lib/node_modules/@stdlib/stats/base/variancewd/test/test.js deleted file mode 100644 index 600af51f7c5b..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 variancewd = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variancewd, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { - t.strictEqual( typeof variancewd.ndarray, 'function', 'method is a function' ); - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/variancewd/test/test.ndarray.js deleted file mode 100644 index 7c4723cdc28b..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/test/test.ndarray.js +++ /dev/null @@ -1,350 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -var variancewd = require( './../lib/ndarray.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variancewd, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( variancewd.length, 5, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancewd( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancewd( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancewd( x.length, 0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancewd( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancewd( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancewd( x.length, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( 0, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancewd( -1, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( 0, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancewd( -1, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( 1, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( 1, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancewd( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( x.length, x.length, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancewd( x.length, x.length+1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancewd( 4, 1, x, 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancewd( 4, 1, toAccessorArray( x ), 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancewd( 4, 1, x, -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancewd( 4, 1, toAccessorArray( x ), -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( x.length, 1, x, 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( x.length, 1, toAccessorArray( x ), 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter', function test( t ) { - var x; - var v; - - x = [ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]; - - v = variancewd( 4, 1, x, 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]; - - v = variancewd( 4, 1, toAccessorArray( x ), 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/variancewd/test/test.variancewd.js b/lib/node_modules/@stdlib/stats/base/variancewd/test/test.variancewd.js deleted file mode 100644 index 7c8765a5717e..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancewd/test/test.variancewd.js +++ /dev/null @@ -1,359 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var Float64Array = require( '@stdlib/array/float64' ); -var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -var variancewd = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variancewd, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( variancewd.length, 4, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancewd( x.length, 0, x, 1 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancewd( x.length, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancewd( x.length, 0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancewd( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancewd( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancewd( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancewd( x.length, 1, x, 1 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancewd( x.length, 1, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancewd( x.length, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancewd( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancewd( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancewd( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( 0, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancewd( -1, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( 0, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancewd( -1, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( 1, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( 1, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancewd( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( x.length, x.length, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancewd( x.length, x.length+1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancewd( 4, 1, x, 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancewd( 4, 1, toAccessorArray( x ), 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancewd( 4, 1, x, -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancewd( 4, 1, toAccessorArray( x ), -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( x.length, 1, x, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancewd( x.length, 1, toAccessorArray( x ), 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float64Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = variancewd( 4, 1, x1, 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets (accessors)', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float64Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = variancewd( 4, 1, toAccessorArray( x1 ), 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); From 7ca7b609f30e2b4d6be8fa0050cf58b218b834a9 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:04:43 +0000 Subject: [PATCH 14/32] feat: add `stats/strided/variancetk` Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../stats/strided/variancetk/README.md | 266 +++++++++++++ .../strided/variancetk/benchmark/benchmark.js | 96 +++++ .../variancetk/benchmark/benchmark.ndarray.js | 96 +++++ .../docs/img/equation_population_mean.svg | 42 ++ .../docs/img/equation_population_variance.svg | 54 +++ .../docs/img/equation_sample_mean.svg | 43 +++ .../img/equation_unbiased_sample_variance.svg | 61 +++ .../stats/strided/variancetk/docs/repl.txt | 114 ++++++ .../strided/variancetk/docs/types/index.d.ts | 96 +++++ .../strided/variancetk/docs/types/test.ts | 190 +++++++++ .../strided/variancetk/examples/index.js | 30 ++ .../stats/strided/variancetk/lib/accessors.js | 77 ++++ .../stats/strided/variancetk/lib/index.js | 59 +++ .../stats/strided/variancetk/lib/main.js | 51 +++ .../stats/strided/variancetk/lib/ndarray.js | 80 ++++ .../stats/strided/variancetk/package.json | 73 ++++ .../stats/strided/variancetk/test/test.js | 38 ++ .../strided/variancetk/test/test.main.js | 359 ++++++++++++++++++ .../strided/variancetk/test/test.ndarray.js | 350 +++++++++++++++++ 19 files changed, 2175 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_population_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_population_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_sample_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_unbiased_sample_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/test/test.main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancetk/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/README.md b/lib/node_modules/@stdlib/stats/strided/variancetk/README.md new file mode 100644 index 000000000000..4b359649e62c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/README.md @@ -0,0 +1,266 @@ + + +# variancetk + +> Calculate the [variance][variance] of a strided array using a one-pass textbook algorithm. + +
+ +The population [variance][variance] of a finite size population of size `N` is given by + + + +```math +\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 +``` + + + + + +where the population mean is given by + + + +```math +\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i +``` + + + + + +Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, + + + +```math +s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 +``` + + + + + +where the sample mean is given by + + + +```math +\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + + + +The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. + +
+ + + +
+ +## Usage + +```javascript +var variancetk = require( '@stdlib/stats/strided/variancetk' ); +``` + +#### variancetk( N, correction, x, strideX ) + +Computes the [variance][variance] of a strided array using a one-pass textbook algorithm. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; + +var v = variancetk( x.length, 1, x, 1 ); +// returns ~4.3333 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, + +```javascript +var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; + +var v = variancetk( 4, 1, x, 2 ); +// returns 6.25 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var v = variancetk( 4, 1, x1, 2 ); +// returns 6.25 +``` + +#### variancetk.ndarray( N, correction, x, strideX, offsetX ) + +Computes the [variance][variance] of a strided array using a one-pass textbook algorithm and alternative indexing semantics. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; + +var v = variancetk.ndarray( x.length, 1, x, 1, 0 ); +// returns ~4.33333 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in the strided array starting from the second element + +```javascript +var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; + +var v = variancetk.ndarray( 4, 1, x, 2, 1 ); +// returns 6.25 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `NaN`. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). +- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. +- Some caution should be exercised when using the one-pass textbook algorithm. Literature overwhelmingly discourages the algorithm's use for two reasons: 1) the lack of safeguards against underflow and overflow and 2) the risk of catastrophic cancellation when subtracting the two sums if the sums are large and the variance small. These concerns have merit; however, the one-pass textbook algorithm should not be dismissed outright. For data distributions with a moderately large standard deviation to mean ratio (i.e., **coefficient of variation**), the one-pass textbook algorithm may be acceptable, especially when performance is paramount and some precision loss is acceptable (including a risk of returning a negative variance due to floating-point rounding errors!). In short, no single "best" algorithm for computing the variance exists. The "best" algorithm depends on the underlying data distribution, your performance requirements, and your minimum precision requirements. When evaluating which algorithm to use, consider the relative pros and cons, and choose the algorithm which best serves your needs. +- Depending on the environment, the typed versions ([`dvariancetk`][@stdlib/stats/strided/dvariancetk], [`svariancetk`][@stdlib/stats/strided/svariancetk], etc.) are likely to be significantly more performant. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var variancetk = require( '@stdlib/stats/strided/variancetk' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +console.log( x ); + +var v = variancetk( x.length, 1, x, 1 ); +console.log( v ); +``` + +
+ + + +* * * + +
+ +## References + +- Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154][@ling:1974a]. + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/variancetk/benchmark/benchmark.js new file mode 100644 index 000000000000..a9d37ff8895a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/benchmark/benchmark.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var variancetk = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = variancetk( x.length, 1, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/variancetk/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..f6dcfaf8ba5f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/benchmark/benchmark.ndarray.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var variancetk = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = variancetk( x.length, 1, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_population_mean.svg new file mode 100644 index 000000000000..4bbdf0d2a56f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_population_mean.svg @@ -0,0 +1,42 @@ + +mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_population_variance.svg new file mode 100644 index 000000000000..4130ba0750d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_population_variance.svg @@ -0,0 +1,54 @@ + +sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_sample_mean.svg new file mode 100644 index 000000000000..aea7a5f6687a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_sample_mean.svg @@ -0,0 +1,43 @@ + +x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_unbiased_sample_variance.svg new file mode 100644 index 000000000000..1ae1283e7fb1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/docs/img/equation_unbiased_sample_variance.svg @@ -0,0 +1,61 @@ + +s squared equals 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 + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/variancetk/docs/repl.txt new file mode 100644 index 000000000000..0908cebb5d28 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/docs/repl.txt @@ -0,0 +1,114 @@ + +{{alias}}( N, correction, x, strideX ) + Computes the variance of a strided array using a one-pass textbook + algorithm. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns `NaN`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > {{alias}}( x.length, 1, x, 1 ) + ~4.3333 + + // Using `N` and stride parameters: + > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; + > {{alias}}( 3, 1, x, 2 ) + ~4.3333 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, 1, x1, 2 ) + ~4.3333 + + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) + Computes the variance of a strided array using a one-pass textbook algorithm + and alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the `offset` parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) + ~4.3333 + + // Using offset parameter: + > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; + > {{alias}}.ndarray( 3, 1, x, 2, 1 ) + ~4.3333 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/variancetk/docs/types/index.d.ts new file mode 100644 index 000000000000..5a08bc438850 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/docs/types/index.d.ts @@ -0,0 +1,96 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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 + +/// + +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `variancetk`. +*/ +interface Routine { + /** + * Computes the variance of a strided array using a one-pass textbook algorithm. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @returns variance + * + * @example + * var x = [ 1.0, -2.0, 2.0 ]; + * + * var v = variancetk( x.length, 1, x, 1 ); + * // returns ~4.3333 + */ + ( N: number, correction: number, x: InputArray, strideX: number ): number; + + /** + * Computes the variance of a strided array using a one-pass textbook algorithm and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns variance + * + * @example + * var x = [ 1.0, -2.0, 2.0 ]; + * + * var v = variancetk.ndarray( x.length, 1, x, 1, 0 ); + * // returns ~4.3333 + */ + ndarray( N: number, correction: number, x: InputArray, strideX: number, offsetX: number ): number; +} + +/** +* Computes the variance of a strided array using a one-pass textbook algorithm. +* +* @param N - number of indexed elements +* @param correction - degrees of freedom adjustment +* @param x - input array +* @param strideX - stride length +* @returns variance +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancetk( x.length, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancetk.ndarray( x.length, 1, x, 1, 0 ); +* // returns ~4.3333 +*/ +declare var variancetk: Routine; + + +// EXPORTS // + +export = variancetk; diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/variancetk/docs/types/test.ts new file mode 100644 index 000000000000..8a654deb2d90 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/docs/types/test.ts @@ -0,0 +1,190 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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 AccessorArray = require( '@stdlib/array/base/accessor' ); +import variancetk = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Float64Array( 10 ); + + variancetk( x.length, 1, x, 1 ); // $ExpectType number + variancetk( x.length, 1, new AccessorArray( x ), 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancetk( '10', 1, x, 1 ); // $ExpectError + variancetk( true, 1, x, 1 ); // $ExpectError + variancetk( false, 1, x, 1 ); // $ExpectError + variancetk( null, 1, x, 1 ); // $ExpectError + variancetk( undefined, 1, x, 1 ); // $ExpectError + variancetk( [], 1, x, 1 ); // $ExpectError + variancetk( {}, 1, x, 1 ); // $ExpectError + variancetk( ( x: number ): number => x, 1, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancetk( x.length, '10', x, 1 ); // $ExpectError + variancetk( x.length, true, x, 1 ); // $ExpectError + variancetk( x.length, false, x, 1 ); // $ExpectError + variancetk( x.length, null, x, 1 ); // $ExpectError + variancetk( x.length, undefined, x, 1 ); // $ExpectError + variancetk( x.length, [], x, 1 ); // $ExpectError + variancetk( x.length, {}, x, 1 ); // $ExpectError + variancetk( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + variancetk( x.length, 1, 10, 1 ); // $ExpectError + variancetk( x.length, 1, '10', 1 ); // $ExpectError + variancetk( x.length, 1, true, 1 ); // $ExpectError + variancetk( x.length, 1, false, 1 ); // $ExpectError + variancetk( x.length, 1, null, 1 ); // $ExpectError + variancetk( x.length, 1, undefined, 1 ); // $ExpectError + variancetk( x.length, 1, [ '1' ], 1 ); // $ExpectError + variancetk( x.length, 1, {}, 1 ); // $ExpectError + variancetk( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancetk( x.length, 1, x, '10' ); // $ExpectError + variancetk( x.length, 1, x, true ); // $ExpectError + variancetk( x.length, 1, x, false ); // $ExpectError + variancetk( x.length, 1, x, null ); // $ExpectError + variancetk( x.length, 1, x, undefined ); // $ExpectError + variancetk( x.length, 1, x, [] ); // $ExpectError + variancetk( x.length, 1, x, {} ); // $ExpectError + variancetk( x.length, 1, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + variancetk(); // $ExpectError + variancetk( x.length ); // $ExpectError + variancetk( x.length, 1 ); // $ExpectError + variancetk( x.length, 1, x ); // $ExpectError + variancetk( x.length, 1, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + + variancetk.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number + variancetk.ndarray( x.length, 1, new AccessorArray( x ), 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancetk.ndarray( '10', 1, x, 1, 0 ); // $ExpectError + variancetk.ndarray( true, 1, x, 1, 0 ); // $ExpectError + variancetk.ndarray( false, 1, x, 1, 0 ); // $ExpectError + variancetk.ndarray( null, 1, x, 1, 0 ); // $ExpectError + variancetk.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError + variancetk.ndarray( [], 1, x, 1, 0 ); // $ExpectError + variancetk.ndarray( {}, 1, x, 1, 0 ); // $ExpectError + variancetk.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancetk.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, [], x, 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + variancetk.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, [ '1' ], 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancetk.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, x, true, 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, x, false, 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, x, null, 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, x, [], 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError + variancetk.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancetk.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError + variancetk.ndarray( x.length, 1, x, 1, true ); // $ExpectError + variancetk.ndarray( x.length, 1, x, 1, false ); // $ExpectError + variancetk.ndarray( x.length, 1, x, 1, null ); // $ExpectError + variancetk.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError + variancetk.ndarray( x.length, 1, x, 1, [] ); // $ExpectError + variancetk.ndarray( x.length, 1, x, 1, {} ); // $ExpectError + variancetk.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + variancetk.ndarray(); // $ExpectError + variancetk.ndarray( x.length ); // $ExpectError + variancetk.ndarray( x.length, 1 ); // $ExpectError + variancetk.ndarray( x.length, 1, x ); // $ExpectError + variancetk.ndarray( x.length, 1, x, 1 ); // $ExpectError + variancetk.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/examples/index.js b/lib/node_modules/@stdlib/stats/strided/variancetk/examples/index.js new file mode 100644 index 000000000000..50517c278915 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/examples/index.js @@ -0,0 +1,30 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var variancetk = require( './../lib' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +console.log( x ); + +var v = variancetk( x.length, 1, x, 1 ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/lib/accessors.js b/lib/node_modules/@stdlib/stats/strided/variancetk/lib/accessors.js new file mode 100644 index 000000000000..05afdc9ca84c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/lib/accessors.js @@ -0,0 +1,77 @@ +/** +* @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'; + +// MAIN // + +/** +* Computes the variance of a strided array using a one-pass textbook algorithm. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} variance +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +* +* var v = variancetk( 4, 1, arraylike2object( x ), 2, 1 ); +* // returns 6.25 +*/ +function variancetk( N, correction, x, strideX, offsetX ) { + var xbuf; + var get; + var S2; + var ix; + var S; + var v; + var n; + var i; + + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessor: + get = x.accessors[ 0 ]; + + n = N - correction; + ix = offsetX; + S2 = 0.0; + S = 0.0; + for ( i = 0; i < N; i++ ) { + v = get( xbuf, ix ); + S2 += v * v; + S += v; + ix += strideX; + } + return (S2 - ((S/N)*S)) / n; +} + + +// EXPORTS // + +module.exports = variancetk; diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/lib/index.js b/lib/node_modules/@stdlib/stats/strided/variancetk/lib/index.js new file mode 100644 index 000000000000..c09fef7ca7aa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/lib/index.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 the variance of a strided array using a one-pass textbook algorithm. +* +* @module @stdlib/stats/strided/variancetk +* +* @example +* var variancetk = require( '@stdlib/stats/strided/variancetk' ); +* +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancetk( x.length, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var variancetk = require( '@stdlib/stats/strided/variancetk' ); +* +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = variancetk.ndarray( 4, 1, x, 2, 1 ); +* // returns 6.25 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/lib/main.js b/lib/node_modules/@stdlib/stats/strided/variancetk/lib/main.js new file mode 100644 index 000000000000..3e845eec090e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/lib/main.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes the variance of a strided array using a one-pass textbook algorithm. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @returns {number} variance +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancetk( x.length, 1, x, 1 ); +* // returns ~4.3333 +*/ +function variancetk( N, correction, x, strideX ) { + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = variancetk; diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/variancetk/lib/ndarray.js new file mode 100644 index 000000000000..d534a0f403c8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/lib/ndarray.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Computes the variance of a strided array using a one-pass textbook algorithm. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} variance +* +* @example +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = variancetk( 4, 1, x, 2, 1 ); +* // returns 6.25 +*/ +function variancetk( N, correction, x, strideX, offsetX ) { + var S2; + var ix; + var o; + var S; + var v; + var n; + var i; + + n = N - correction; + if ( N <= 0 || n <= 0.0 ) { + return NaN; + } + if ( N === 1 || strideX === 0 ) { + return 0.0; + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, correction, o, strideX, offsetX ); + } + ix = offsetX; + S2 = 0.0; + S = 0.0; + for ( i = 0; i < N; i++ ) { + v = x[ ix ]; + S2 += v * v; + S += v; + ix += strideX; + } + return (S2 - ((S/N)*S)) / n; +} + + +// EXPORTS // + +module.exports = variancetk; diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/package.json b/lib/node_modules/@stdlib/stats/strided/variancetk/package.json new file mode 100644 index 000000000000..b8bfc5e86e7f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/stats/strided/variancetk", + "version": "0.0.0", + "description": "Calculate the variance of a strided array using a one-pass textbook algorithm.", + "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", + "var", + "deviation", + "dispersion", + "sample variance", + "unbiased", + "stdev", + "std", + "standard deviation", + "strided", + "strided array", + "typed", + "array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/test/test.js b/lib/node_modules/@stdlib/stats/strided/variancetk/test/test.js new file mode 100644 index 000000000000..83c744d39274 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 variancetk = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variancetk, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof variancetk.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/test/test.main.js b/lib/node_modules/@stdlib/stats/strided/variancetk/test/test.main.js new file mode 100644 index 000000000000..ba84f5cb26e5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/test/test.main.js @@ -0,0 +1,359 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var variancetk = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variancetk, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( variancetk.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancetk( x.length, 0, x, 1 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancetk( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancetk( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancetk( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancetk( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancetk( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancetk( x.length, 1, x, 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancetk( x.length, 1, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancetk( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancetk( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancetk( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancetk( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( 0, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancetk( -1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( 0, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancetk( -1, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( 1, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancetk( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( x.length, x.length, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancetk( x.length, x.length+1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancetk( 4, 1, x, 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancetk( 4, 1, toAccessorArray( x ), 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancetk( 4, 1, x, -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancetk( 4, 1, toAccessorArray( x ), -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( x.length, 1, toAccessorArray( x ), 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = variancetk( 4, 1, x1, 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets (accessors)', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = variancetk( 4, 1, toAccessorArray( x1 ), 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/variancetk/test/test.ndarray.js new file mode 100644 index 000000000000..423d140d3821 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/test/test.ndarray.js @@ -0,0 +1,350 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var variancetk = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variancetk, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( variancetk.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancetk( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancetk( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancetk( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancetk( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancetk( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancetk( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancetk( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancetk( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancetk( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancetk( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancetk( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancetk( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( 0, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancetk( -1, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( 0, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancetk( -1, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( 1, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( 1, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancetk( x.length, x.length+1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( x.length, x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancetk( x.length, x.length+1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancetk( 4, 1, x, 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancetk( 4, 1, toAccessorArray( x ), 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancetk( 4, 1, x, -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancetk( 4, 1, toAccessorArray( x ), -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( x.length, 1, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancetk( x.length, 1, toAccessorArray( x ), 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + + v = variancetk( 4, 1, x, 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + + v = variancetk( 4, 1, toAccessorArray( x ), 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); From f647afcd87e95c6444ad3f5d3652a13582901e3f Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:06:50 +0000 Subject: [PATCH 15/32] remove: remove `variancetk` from namespace This commit removes the `variancetk` symbol from the `@stdlib/stats/base` namespace due to a package migration. BREAKING CHANGE: remove `variancetk` To migrate, users should access the same symbol via the `@stdlib/stats/strided` namespace. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/docs/types/index.d.ts | 24 ------------------- .../@stdlib/stats/base/lib/index.js | 9 ------- 2 files changed, 33 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts index 23e1cb85ccf0..9553a9e60c26 100644 --- a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts @@ -69,7 +69,6 @@ import stdevyc = require( '@stdlib/stats/base/stdevyc' ); import variance = require( '@stdlib/stats/base/variance' ); import variancech = require( '@stdlib/stats/base/variancech' ); import variancepn = require( '@stdlib/stats/base/variancepn' ); -import variancetk = require( '@stdlib/stats/base/variancetk' ); import dmeankbn2 = require( '@stdlib/stats/strided/dmeankbn2' ); import dmeanli = require( '@stdlib/stats/strided/dmeanli' ); import dmeanlipw = require( '@stdlib/stats/strided/dmeanlipw' ); @@ -1321,29 +1320,6 @@ interface Namespace { */ variancepn: typeof variancepn; - /** - * Computes the variance of a strided array using a one-pass textbook algorithm. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param stride - stride length - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = ns.variancetk( x.length, 1, x, 1 ); - * // returns ~4.3333 - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = ns.variancetk.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - variancetk: typeof variancetk; - /** * Computes the arithmetic mean of a double-precision floating-point strided array using a second-order iterative Kahan–Babuška algorithm. * diff --git a/lib/node_modules/@stdlib/stats/base/lib/index.js b/lib/node_modules/@stdlib/stats/base/lib/index.js index 8d0a5f86f428..07b0a0075fac 100644 --- a/lib/node_modules/@stdlib/stats/base/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/lib/index.js @@ -486,15 +486,6 @@ setReadOnly( ns, 'variancech', require( '@stdlib/stats/base/variancech' ) ); */ setReadOnly( ns, 'variancepn', require( '@stdlib/stats/base/variancepn' ) ); -/** -* @name variancetk -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/stats/base/variancetk} -*/ -setReadOnly( ns, 'variancetk', require( '@stdlib/stats/base/variancetk' ) ); - /** * @name dmeankbn2 * @memberof ns From f51215e31f91fa5843f641deb8bf875ffa313596 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:07:46 +0000 Subject: [PATCH 16/32] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/namespace/lib/namespace/base/strided/d.js | 2 +- .../@stdlib/namespace/lib/namespace/base/strided/n.js | 2 +- .../@stdlib/namespace/lib/namespace/base/strided/s.js | 4 ++-- .../@stdlib/namespace/lib/namespace/base/strided/v.js | 4 ++-- lib/node_modules/@stdlib/stats/array/variancetk/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/base/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/nanvariancetk/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/stdevtk/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/stdevtk/lib/ndarray.js | 2 +- lib/node_modules/@stdlib/stats/base/stdevtk/lib/stdevtk.js | 2 +- lib/node_modules/@stdlib/stats/strided/dvariancetk/README.md | 4 ++-- lib/node_modules/@stdlib/stats/strided/svariancetk/README.md | 4 ++-- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js index 1be1e5084d1a..84ace489c5ed 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js @@ -2295,7 +2295,7 @@ ns.push({ '@stdlib/stats/strided/dstdevtk', '@stdlib/stats/strided/dvariance', '@stdlib/stats/strided/svariancetk', - '@stdlib/stats/base/variancetk' + '@stdlib/stats/strided/variancetk' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js index bcc4d46fa58f..796c53c8ea0f 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js @@ -368,7 +368,7 @@ ns.push({ '@stdlib/stats/base/nanstdevtk', '@stdlib/stats/base/nanvariance', '@stdlib/stats/base/snanvariancetk', - '@stdlib/stats/base/variancetk' + '@stdlib/stats/strided/variancetk' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js index f907062fe591..4f0e35a81fac 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js @@ -1840,7 +1840,7 @@ ns.push({ '@stdlib/stats/base/nanstdevtk', '@stdlib/stats/strided/sstdevtk', '@stdlib/stats/base/stdev', - '@stdlib/stats/base/variancetk' + '@stdlib/stats/strided/variancetk' ] }); @@ -1943,7 +1943,7 @@ ns.push({ '@stdlib/stats/base/snanvariancetk', '@stdlib/stats/strided/sstdevtk', '@stdlib/stats/strided/svariance', - '@stdlib/stats/base/variancetk' + '@stdlib/stats/strided/variancetk' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js index a8a39c2dd6a7..d71863c07e3c 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js @@ -69,8 +69,8 @@ ns.push({ ns.push({ 'alias': 'base.strided.variancetk', - 'path': '@stdlib/stats/base/variancetk', - 'value': require( '@stdlib/stats/base/variancetk' ), + 'path': '@stdlib/stats/strided/variancetk', + 'value': require( '@stdlib/stats/strided/variancetk' ), 'type': 'Function', 'related': [ '@stdlib/stats/strided/dvariancetk', diff --git a/lib/node_modules/@stdlib/stats/array/variancetk/lib/main.js b/lib/node_modules/@stdlib/stats/array/variancetk/lib/main.js index 0ca545604e0f..ee1942eb055b 100644 --- a/lib/node_modules/@stdlib/stats/array/variancetk/lib/main.js +++ b/lib/node_modules/@stdlib/stats/array/variancetk/lib/main.js @@ -26,7 +26,7 @@ var dtypes = require( '@stdlib/array/dtypes' ); var dtype = require( '@stdlib/array/dtype' ); var contains = require( '@stdlib/array/base/assert/contains' ); var join = require( '@stdlib/array/base/join' ); -var strided = require( '@stdlib/stats/base/variancetk' ).ndarray; +var strided = require( '@stdlib/stats/strided/variancetk' ).ndarray; var format = require( '@stdlib/string/format' ); diff --git a/lib/node_modules/@stdlib/stats/base/README.md b/lib/node_modules/@stdlib/stats/base/README.md index 57a489d7b334..8a0a53325b18 100644 --- a/lib/node_modules/@stdlib/stats/base/README.md +++ b/lib/node_modules/@stdlib/stats/base/README.md @@ -110,7 +110,7 @@ The namespace contains the following statistical functions: - [`variance( N, correction, x, strideX )`][@stdlib/stats/base/variance]: calculate the variance of a strided array. - [`variancech( N, correction, x, strideX )`][@stdlib/stats/base/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. - [`variancepn( N, correction, x, strideX )`][@stdlib/stats/base/variancepn]: calculate the variance of a strided array using a two-pass algorithm. -- [`variancetk( N, correction, x, strideX )`][@stdlib/stats/base/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. +- [`variancetk( N, correction, x, strideX )`][@stdlib/stats/strided/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. - [`variancewd( N, correction, x, stride )`][@stdlib/stats/strided/variancewd]: calculate the variance of a strided array using Welford's algorithm. - [`varianceyc( N, correction, x, strideX )`][@stdlib/stats/strided/varianceyc]: calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. @@ -269,7 +269,7 @@ console.log( objectKeys( ns ) ); [@stdlib/stats/base/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancepn -[@stdlib/stats/base/variancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancetk +[@stdlib/stats/strided/variancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancetk [@stdlib/stats/strided/variancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancewd diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancetk/README.md b/lib/node_modules/@stdlib/stats/base/nanvariancetk/README.md index 92f5f4d2c787..f5bad9c64576 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancetk/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanvariancetk/README.md @@ -235,7 +235,7 @@ console.log( v ); - [`@stdlib/stats/base/nanstdevtk`][@stdlib/stats/base/nanstdevtk]: calculate the standard deviation of a strided array ignoring NaN values and using a one-pass textbook algorithm. - [`@stdlib/stats/base/nanvariance`][@stdlib/stats/base/nanvariance]: calculate the variance of a strided array ignoring NaN values. - [`@stdlib/stats/base/snanvariancetk`][@stdlib/stats/base/snanvariancetk]: calculate the variance of a single-precision floating-point strided array ignoring NaN values and using a one-pass textbook algorithm. -- [`@stdlib/stats/base/variancetk`][@stdlib/stats/base/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. +- [`@stdlib/stats/strided/variancetk`][@stdlib/stats/strided/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. @@ -265,7 +265,7 @@ console.log( v ); [@stdlib/stats/base/snanvariancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/snanvariancetk -[@stdlib/stats/base/variancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancetk +[@stdlib/stats/strided/variancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancetk diff --git a/lib/node_modules/@stdlib/stats/base/stdevtk/README.md b/lib/node_modules/@stdlib/stats/base/stdevtk/README.md index d5d56e6c7609..0e59c49720c7 100644 --- a/lib/node_modules/@stdlib/stats/base/stdevtk/README.md +++ b/lib/node_modules/@stdlib/stats/base/stdevtk/README.md @@ -242,7 +242,7 @@ console.log( v ); - [`@stdlib/stats/base/nanstdevtk`][@stdlib/stats/base/nanstdevtk]: calculate the standard deviation of a strided array ignoring NaN values and using a one-pass textbook algorithm. - [`@stdlib/stats/strided/sstdevtk`][@stdlib/stats/strided/sstdevtk]: calculate the standard deviation of a single-precision floating-point strided array using a one-pass textbook algorithm. - [`@stdlib/stats/base/stdev`][@stdlib/stats/base/stdev]: calculate the standard deviation of a strided array. -- [`@stdlib/stats/base/variancetk`][@stdlib/stats/base/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. +- [`@stdlib/stats/strided/variancetk`][@stdlib/stats/strided/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. @@ -270,7 +270,7 @@ console.log( v ); [@stdlib/stats/base/stdev]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/stdev -[@stdlib/stats/base/variancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancetk +[@stdlib/stats/strided/variancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancetk diff --git a/lib/node_modules/@stdlib/stats/base/stdevtk/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/stdevtk/lib/ndarray.js index 92ad7277b56d..5cb715873769 100644 --- a/lib/node_modules/@stdlib/stats/base/stdevtk/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/stdevtk/lib/ndarray.js @@ -20,7 +20,7 @@ // MODULES // -var variancetk = require( '@stdlib/stats/base/variancetk' ).ndarray; +var variancetk = require( '@stdlib/stats/strided/variancetk' ).ndarray; var sqrt = require( '@stdlib/math/base/special/sqrt' ); diff --git a/lib/node_modules/@stdlib/stats/base/stdevtk/lib/stdevtk.js b/lib/node_modules/@stdlib/stats/base/stdevtk/lib/stdevtk.js index a471a981f9d7..1a06a7e809d5 100644 --- a/lib/node_modules/@stdlib/stats/base/stdevtk/lib/stdevtk.js +++ b/lib/node_modules/@stdlib/stats/base/stdevtk/lib/stdevtk.js @@ -20,7 +20,7 @@ // MODULES // -var variancetk = require( '@stdlib/stats/base/variancetk' ); +var variancetk = require( '@stdlib/stats/strided/variancetk' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); diff --git a/lib/node_modules/@stdlib/stats/strided/dvariancetk/README.md b/lib/node_modules/@stdlib/stats/strided/dvariancetk/README.md index f8aa2ee506f6..c0a3169dadab 100644 --- a/lib/node_modules/@stdlib/stats/strided/dvariancetk/README.md +++ b/lib/node_modules/@stdlib/stats/strided/dvariancetk/README.md @@ -383,7 +383,7 @@ int main( void ) { - [`@stdlib/stats/strided/dstdevtk`][@stdlib/stats/strided/dstdevtk]: calculate the standard deviation of a double-precision floating-point strided array using a one-pass textbook algorithm. - [`@stdlib/stats/strided/dvariance`][@stdlib/stats/strided/dvariance]: calculate the variance of a double-precision floating-point strided array. - [`@stdlib/stats/strided/svariancetk`][@stdlib/stats/strided/svariancetk]: calculate the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. -- [`@stdlib/stats/base/variancetk`][@stdlib/stats/base/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. +- [`@stdlib/stats/strided/variancetk`][@stdlib/stats/strided/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. @@ -411,7 +411,7 @@ int main( void ) { [@stdlib/stats/strided/svariancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancetk -[@stdlib/stats/base/variancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancetk +[@stdlib/stats/strided/variancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancetk diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/README.md b/lib/node_modules/@stdlib/stats/strided/svariancetk/README.md index 8851d59f6ba2..3b6236f8b346 100644 --- a/lib/node_modules/@stdlib/stats/strided/svariancetk/README.md +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/README.md @@ -383,7 +383,7 @@ int main( void ) { - [`@stdlib/stats/base/snanvariancetk`][@stdlib/stats/base/snanvariancetk]: calculate the variance of a single-precision floating-point strided array ignoring NaN values and using a one-pass textbook algorithm. - [`@stdlib/stats/strided/sstdevtk`][@stdlib/stats/strided/sstdevtk]: calculate the standard deviation of a single-precision floating-point strided array using a one-pass textbook algorithm. - [`@stdlib/stats/strided/svariance`][@stdlib/stats/strided/svariance]: calculate the variance of a single-precision floating-point strided array. -- [`@stdlib/stats/base/variancetk`][@stdlib/stats/base/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. +- [`@stdlib/stats/strided/variancetk`][@stdlib/stats/strided/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. @@ -411,7 +411,7 @@ int main( void ) { [@stdlib/stats/strided/svariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariance -[@stdlib/stats/base/variancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancetk +[@stdlib/stats/strided/variancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancetk From d7da0e01dd3a517cb55e5b651bfd80772dd19f79 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:09:33 +0000 Subject: [PATCH 17/32] remove: remove `stats/base/variancetk` This commit removes `@stdlib/stats/base/variancetk` in favor of `@stdlib/stats/strided/variancetk`. BREAKING CHANGE: remove `stats/base/variancetk` To migrate, users should update their require/import paths to use `@stdlib/stats/strided/variancetk`, which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/variancetk/README.md | 266 ------------- .../base/variancetk/benchmark/benchmark.js | 96 ----- .../variancetk/benchmark/benchmark.ndarray.js | 96 ----- .../docs/img/equation_population_mean.svg | 42 -- .../docs/img/equation_population_variance.svg | 54 --- .../docs/img/equation_sample_mean.svg | 43 --- .../img/equation_unbiased_sample_variance.svg | 61 --- .../stats/base/variancetk/docs/repl.txt | 114 ------ .../base/variancetk/docs/types/index.d.ts | 96 ----- .../stats/base/variancetk/docs/types/test.ts | 190 --------- .../stats/base/variancetk/examples/index.js | 30 -- .../stats/base/variancetk/lib/accessors.js | 77 ---- .../stats/base/variancetk/lib/index.js | 59 --- .../@stdlib/stats/base/variancetk/lib/main.js | 51 --- .../stats/base/variancetk/lib/ndarray.js | 80 ---- .../stats/base/variancetk/package.json | 73 ---- .../stats/base/variancetk/test/test.js | 38 -- .../stats/base/variancetk/test/test.main.js | 359 ------------------ .../base/variancetk/test/test.ndarray.js | 350 ----------------- 19 files changed, 2175 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/README.md delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/benchmark/benchmark.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_population_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_population_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_sample_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_unbiased_sample_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/examples/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/lib/accessors.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/lib/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/lib/main.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/lib/ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/package.json delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/test/test.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/test/test.main.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancetk/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/README.md b/lib/node_modules/@stdlib/stats/base/variancetk/README.md deleted file mode 100644 index 14a9fdee00dc..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/README.md +++ /dev/null @@ -1,266 +0,0 @@ - - -# variancetk - -> Calculate the [variance][variance] of a strided array using a one-pass textbook algorithm. - -
- -The population [variance][variance] of a finite size population of size `N` is given by - - - -```math -\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 -``` - - - - - -where the population mean is given by - - - -```math -\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i -``` - - - - - -Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, - - - -```math -s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 -``` - - - - - -where the sample mean is given by - - - -```math -\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i -``` - - - - - -The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. - -
- - - -
- -## Usage - -```javascript -var variancetk = require( '@stdlib/stats/base/variancetk' ); -``` - -#### variancetk( N, correction, x, strideX ) - -Computes the [variance][variance] of a strided array using a one-pass textbook algorithm. - -```javascript -var x = [ 1.0, -2.0, 2.0 ]; - -var v = variancetk( x.length, 1, x, 1 ); -// returns ~4.3333 -``` - -The function has the following parameters: - -- **N**: number of indexed elements. -- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. -- **strideX**: stride length for `x`. - -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, - -```javascript -var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; - -var v = variancetk( 4, 1, x, 2 ); -// returns 6.25 -``` - -Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); - -var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - -var v = variancetk( 4, 1, x1, 2 ); -// returns 6.25 -``` - -#### variancetk.ndarray( N, correction, x, strideX, offsetX ) - -Computes the [variance][variance] of a strided array using a one-pass textbook algorithm and alternative indexing semantics. - -```javascript -var x = [ 1.0, -2.0, 2.0 ]; - -var v = variancetk.ndarray( x.length, 1, x, 1, 0 ); -// returns ~4.33333 -``` - -The function has the following additional parameters: - -- **offsetX**: starting index for `x`. - -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in the strided array starting from the second element - -```javascript -var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; - -var v = variancetk.ndarray( 4, 1, x, 2, 1 ); -// returns 6.25 -``` - -
- - - -
- -## Notes - -- If `N <= 0`, both functions return `NaN`. -- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). -- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. -- Some caution should be exercised when using the one-pass textbook algorithm. Literature overwhelmingly discourages the algorithm's use for two reasons: 1) the lack of safeguards against underflow and overflow and 2) the risk of catastrophic cancellation when subtracting the two sums if the sums are large and the variance small. These concerns have merit; however, the one-pass textbook algorithm should not be dismissed outright. For data distributions with a moderately large standard deviation to mean ratio (i.e., **coefficient of variation**), the one-pass textbook algorithm may be acceptable, especially when performance is paramount and some precision loss is acceptable (including a risk of returning a negative variance due to floating-point rounding errors!). In short, no single "best" algorithm for computing the variance exists. The "best" algorithm depends on the underlying data distribution, your performance requirements, and your minimum precision requirements. When evaluating which algorithm to use, consider the relative pros and cons, and choose the algorithm which best serves your needs. -- Depending on the environment, the typed versions ([`dvariancetk`][@stdlib/stats/strided/dvariancetk], [`svariancetk`][@stdlib/stats/strided/svariancetk], etc.) are likely to be significantly more performant. - -
- - - -
- -## Examples - - - -```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var variancetk = require( '@stdlib/stats/base/variancetk' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); -console.log( x ); - -var v = variancetk( x.length, 1, x, 1 ); -console.log( v ); -``` - -
- - - -* * * - -
- -## References - -- Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154][@ling:1974a]. - -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/variancetk/benchmark/benchmark.js deleted file mode 100644 index a9d37ff8895a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/benchmark/benchmark.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var variancetk = require( './../lib/main.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = variancetk( x.length, 1, x, 1 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/variancetk/benchmark/benchmark.ndarray.js deleted file mode 100644 index f6dcfaf8ba5f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var variancetk = require( './../lib/ndarray.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = variancetk( x.length, 1, x, 1, 0 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':ndarray:len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_population_mean.svg deleted file mode 100644 index 4bbdf0d2a56f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_population_mean.svg +++ /dev/null @@ -1,42 +0,0 @@ - -mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_population_variance.svg deleted file mode 100644 index 4130ba0750d2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_population_variance.svg +++ /dev/null @@ -1,54 +0,0 @@ - -sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_sample_mean.svg deleted file mode 100644 index aea7a5f6687a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_sample_mean.svg +++ /dev/null @@ -1,43 +0,0 @@ - -x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_unbiased_sample_variance.svg deleted file mode 100644 index 1ae1283e7fb1..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/docs/img/equation_unbiased_sample_variance.svg +++ /dev/null @@ -1,61 +0,0 @@ - -s squared equals 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 - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/variancetk/docs/repl.txt deleted file mode 100644 index 0908cebb5d28..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/docs/repl.txt +++ /dev/null @@ -1,114 +0,0 @@ - -{{alias}}( N, correction, x, strideX ) - Computes the variance of a strided array using a one-pass textbook - algorithm. - - The `N` and stride parameters determine which elements in the strided array - are accessed at runtime. - - Indexing is relative to the first index. To introduce an offset, use a typed - array view. - - If `N <= 0`, the function returns `NaN`. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Array|TypedArray - Input array. - - strideX: integer - Stride length. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = [ 1.0, -2.0, 2.0 ]; - > {{alias}}( x.length, 1, x, 1 ) - ~4.3333 - - // Using `N` and stride parameters: - > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; - > {{alias}}( 3, 1, x, 2 ) - ~4.3333 - - // Using view offsets: - > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 1, x1, 2 ) - ~4.3333 - - -{{alias}}.ndarray( N, correction, x, strideX, offsetX ) - Computes the variance of a strided array using a one-pass textbook algorithm - and alternative indexing semantics. - - While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a - starting index. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Array|TypedArray - Input array. - - strideX: integer - Stride length. - - offsetX: integer - Starting index. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = [ 1.0, -2.0, 2.0 ]; - > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) - ~4.3333 - - // Using offset parameter: - > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; - > {{alias}}.ndarray( 3, 1, x, 2, 1 ) - ~4.3333 - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/variancetk/docs/types/index.d.ts deleted file mode 100644 index 5a08bc438850..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/docs/types/index.d.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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 - -/// - -import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; - -/** -* Input array. -*/ -type InputArray = NumericArray | Collection | AccessorArrayLike; - -/** -* Interface describing `variancetk`. -*/ -interface Routine { - /** - * Computes the variance of a strided array using a one-pass textbook algorithm. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = variancetk( x.length, 1, x, 1 ); - * // returns ~4.3333 - */ - ( N: number, correction: number, x: InputArray, strideX: number ): number; - - /** - * Computes the variance of a strided array using a one-pass textbook algorithm and alternative indexing semantics. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @param offsetX - starting index - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = variancetk.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - ndarray( N: number, correction: number, x: InputArray, strideX: number, offsetX: number ): number; -} - -/** -* Computes the variance of a strided array using a one-pass textbook algorithm. -* -* @param N - number of indexed elements -* @param correction - degrees of freedom adjustment -* @param x - input array -* @param strideX - stride length -* @returns variance -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancetk( x.length, 1, x, 1 ); -* // returns ~4.3333 -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancetk.ndarray( x.length, 1, x, 1, 0 ); -* // returns ~4.3333 -*/ -declare var variancetk: Routine; - - -// EXPORTS // - -export = variancetk; diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/variancetk/docs/types/test.ts deleted file mode 100644 index 8a654deb2d90..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/docs/types/test.ts +++ /dev/null @@ -1,190 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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 AccessorArray = require( '@stdlib/array/base/accessor' ); -import variancetk = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const x = new Float64Array( 10 ); - - variancetk( x.length, 1, x, 1 ); // $ExpectType number - variancetk( x.length, 1, new AccessorArray( x ), 1 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancetk( '10', 1, x, 1 ); // $ExpectError - variancetk( true, 1, x, 1 ); // $ExpectError - variancetk( false, 1, x, 1 ); // $ExpectError - variancetk( null, 1, x, 1 ); // $ExpectError - variancetk( undefined, 1, x, 1 ); // $ExpectError - variancetk( [], 1, x, 1 ); // $ExpectError - variancetk( {}, 1, x, 1 ); // $ExpectError - variancetk( ( x: number ): number => x, 1, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancetk( x.length, '10', x, 1 ); // $ExpectError - variancetk( x.length, true, x, 1 ); // $ExpectError - variancetk( x.length, false, x, 1 ); // $ExpectError - variancetk( x.length, null, x, 1 ); // $ExpectError - variancetk( x.length, undefined, x, 1 ); // $ExpectError - variancetk( x.length, [], x, 1 ); // $ExpectError - variancetk( x.length, {}, x, 1 ); // $ExpectError - variancetk( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a numeric array... -{ - const x = new Float64Array( 10 ); - - variancetk( x.length, 1, 10, 1 ); // $ExpectError - variancetk( x.length, 1, '10', 1 ); // $ExpectError - variancetk( x.length, 1, true, 1 ); // $ExpectError - variancetk( x.length, 1, false, 1 ); // $ExpectError - variancetk( x.length, 1, null, 1 ); // $ExpectError - variancetk( x.length, 1, undefined, 1 ); // $ExpectError - variancetk( x.length, 1, [ '1' ], 1 ); // $ExpectError - variancetk( x.length, 1, {}, 1 ); // $ExpectError - variancetk( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancetk( x.length, 1, x, '10' ); // $ExpectError - variancetk( x.length, 1, x, true ); // $ExpectError - variancetk( x.length, 1, x, false ); // $ExpectError - variancetk( x.length, 1, x, null ); // $ExpectError - variancetk( x.length, 1, x, undefined ); // $ExpectError - variancetk( x.length, 1, x, [] ); // $ExpectError - variancetk( x.length, 1, x, {} ); // $ExpectError - variancetk( x.length, 1, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - - variancetk(); // $ExpectError - variancetk( x.length ); // $ExpectError - variancetk( x.length, 1 ); // $ExpectError - variancetk( x.length, 1, x ); // $ExpectError - variancetk( x.length, 1, x, 1, 10 ); // $ExpectError -} - -// Attached to main export is an `ndarray` method which returns a number... -{ - const x = new Float64Array( 10 ); - - variancetk.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number - variancetk.ndarray( x.length, 1, new AccessorArray( x ), 1, 0 ); // $ExpectType number -} - -// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancetk.ndarray( '10', 1, x, 1, 0 ); // $ExpectError - variancetk.ndarray( true, 1, x, 1, 0 ); // $ExpectError - variancetk.ndarray( false, 1, x, 1, 0 ); // $ExpectError - variancetk.ndarray( null, 1, x, 1, 0 ); // $ExpectError - variancetk.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError - variancetk.ndarray( [], 1, x, 1, 0 ); // $ExpectError - variancetk.ndarray( {}, 1, x, 1, 0 ); // $ExpectError - variancetk.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancetk.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, true, x, 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, false, x, 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, null, x, 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, [], x, 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... -{ - const x = new Float64Array( 10 ); - - variancetk.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, [ '1' ], 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancetk.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, x, true, 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, x, false, 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, x, null, 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, x, [], 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError - variancetk.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancetk.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError - variancetk.ndarray( x.length, 1, x, 1, true ); // $ExpectError - variancetk.ndarray( x.length, 1, x, 1, false ); // $ExpectError - variancetk.ndarray( x.length, 1, x, 1, null ); // $ExpectError - variancetk.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError - variancetk.ndarray( x.length, 1, x, 1, [] ); // $ExpectError - variancetk.ndarray( x.length, 1, x, 1, {} ); // $ExpectError - variancetk.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - - variancetk.ndarray(); // $ExpectError - variancetk.ndarray( x.length ); // $ExpectError - variancetk.ndarray( x.length, 1 ); // $ExpectError - variancetk.ndarray( x.length, 1, x ); // $ExpectError - variancetk.ndarray( x.length, 1, x, 1 ); // $ExpectError - variancetk.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/examples/index.js b/lib/node_modules/@stdlib/stats/base/variancetk/examples/index.js deleted file mode 100644 index 50517c278915..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/examples/index.js +++ /dev/null @@ -1,30 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var variancetk = require( './../lib' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); -console.log( x ); - -var v = variancetk( x.length, 1, x, 1 ); -console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/variancetk/lib/accessors.js deleted file mode 100644 index 05afdc9ca84c..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/lib/accessors.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @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'; - -// MAIN // - -/** -* Computes the variance of a strided array using a one-pass textbook algorithm. -* -* @private -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {Object} x - input array object -* @param {Collection} x.data - input array data -* @param {Array} x.accessors - array element accessors -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index -* @returns {number} variance -* -* @example -* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -* -* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* -* var v = variancetk( 4, 1, arraylike2object( x ), 2, 1 ); -* // returns 6.25 -*/ -function variancetk( N, correction, x, strideX, offsetX ) { - var xbuf; - var get; - var S2; - var ix; - var S; - var v; - var n; - var i; - - // Cache reference to array data: - xbuf = x.data; - - // Cache a reference to the element accessor: - get = x.accessors[ 0 ]; - - n = N - correction; - ix = offsetX; - S2 = 0.0; - S = 0.0; - for ( i = 0; i < N; i++ ) { - v = get( xbuf, ix ); - S2 += v * v; - S += v; - ix += strideX; - } - return (S2 - ((S/N)*S)) / n; -} - - -// EXPORTS // - -module.exports = variancetk; diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/lib/index.js b/lib/node_modules/@stdlib/stats/base/variancetk/lib/index.js deleted file mode 100644 index c7393ac857a5..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/lib/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 the variance of a strided array using a one-pass textbook algorithm. -* -* @module @stdlib/stats/base/variancetk -* -* @example -* var variancetk = require( '@stdlib/stats/base/variancetk' ); -* -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancetk( x.length, 1, x, 1 ); -* // returns ~4.3333 -* -* @example -* var variancetk = require( '@stdlib/stats/base/variancetk' ); -* -* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* -* var v = variancetk.ndarray( 4, 1, x, 2, 1 ); -* // returns 6.25 -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var ndarray = require( './ndarray.js' ); - - -// MAIN // - -setReadOnly( main, 'ndarray', ndarray ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/lib/main.js b/lib/node_modules/@stdlib/stats/base/variancetk/lib/main.js deleted file mode 100644 index 3e845eec090e..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/lib/main.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); -var ndarray = require( './ndarray.js' ); - - -// MAIN // - -/** -* Computes the variance of a strided array using a one-pass textbook algorithm. -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array -* @param {integer} strideX - stride length -* @returns {number} variance -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancetk( x.length, 1, x, 1 ); -* // returns ~4.3333 -*/ -function variancetk( N, correction, x, strideX ) { - return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); -} - - -// EXPORTS // - -module.exports = variancetk; diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/variancetk/lib/ndarray.js deleted file mode 100644 index d534a0f403c8..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/lib/ndarray.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -var accessors = require( './accessors.js' ); - - -// MAIN // - -/** -* Computes the variance of a strided array using a one-pass textbook algorithm. -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index -* @returns {number} variance -* -* @example -* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* -* var v = variancetk( 4, 1, x, 2, 1 ); -* // returns 6.25 -*/ -function variancetk( N, correction, x, strideX, offsetX ) { - var S2; - var ix; - var o; - var S; - var v; - var n; - var i; - - n = N - correction; - if ( N <= 0 || n <= 0.0 ) { - return NaN; - } - if ( N === 1 || strideX === 0 ) { - return 0.0; - } - o = arraylike2object( x ); - if ( o.accessorProtocol ) { - return accessors( N, correction, o, strideX, offsetX ); - } - ix = offsetX; - S2 = 0.0; - S = 0.0; - for ( i = 0; i < N; i++ ) { - v = x[ ix ]; - S2 += v * v; - S += v; - ix += strideX; - } - return (S2 - ((S/N)*S)) / n; -} - - -// EXPORTS // - -module.exports = variancetk; diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/package.json b/lib/node_modules/@stdlib/stats/base/variancetk/package.json deleted file mode 100644 index dfc7cc8dfc05..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/package.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "name": "@stdlib/stats/base/variancetk", - "version": "0.0.0", - "description": "Calculate the variance of a strided array using a one-pass textbook algorithm.", - "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", - "var", - "deviation", - "dispersion", - "sample variance", - "unbiased", - "stdev", - "std", - "standard deviation", - "strided", - "strided array", - "typed", - "array" - ], - "__stdlib__": {} -} diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/test/test.js b/lib/node_modules/@stdlib/stats/base/variancetk/test/test.js deleted file mode 100644 index 83c744d39274..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 variancetk = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variancetk, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { - t.strictEqual( typeof variancetk.ndarray, 'function', 'method is a function' ); - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/test/test.main.js b/lib/node_modules/@stdlib/stats/base/variancetk/test/test.main.js deleted file mode 100644 index ba84f5cb26e5..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/test/test.main.js +++ /dev/null @@ -1,359 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -var Float64Array = require( '@stdlib/array/float64' ); -var variancetk = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variancetk, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( variancetk.length, 4, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancetk( x.length, 0, x, 1 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancetk( x.length, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancetk( x.length, 0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancetk( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancetk( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancetk( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancetk( x.length, 1, x, 1 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancetk( x.length, 1, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancetk( x.length, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancetk( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancetk( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancetk( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( 0, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancetk( -1, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( 0, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancetk( -1, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( 1, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( 1, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancetk( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( x.length, x.length, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancetk( x.length, x.length+1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancetk( 4, 1, x, 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancetk( 4, 1, toAccessorArray( x ), 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancetk( 4, 1, x, -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancetk( 4, 1, toAccessorArray( x ), -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( x.length, 1, x, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( x.length, 1, toAccessorArray( x ), 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float64Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = variancetk( 4, 1, x1, 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets (accessors)', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float64Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = variancetk( 4, 1, toAccessorArray( x1 ), 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/variancetk/test/test.ndarray.js deleted file mode 100644 index 423d140d3821..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancetk/test/test.ndarray.js +++ /dev/null @@ -1,350 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -var variancetk = require( './../lib/ndarray.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variancetk, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( variancetk.length, 5, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancetk( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancetk( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancetk( x.length, 0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancetk( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancetk( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancetk( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancetk( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancetk( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancetk( x.length, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancetk( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancetk( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancetk( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( 0, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancetk( -1, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( 0, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancetk( -1, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( 1, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( 1, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancetk( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( x.length, x.length, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancetk( x.length, x.length+1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancetk( 4, 1, x, 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancetk( 4, 1, toAccessorArray( x ), 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancetk( 4, 1, x, -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancetk( 4, 1, toAccessorArray( x ), -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( x.length, 1, x, 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancetk( x.length, 1, toAccessorArray( x ), 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter', function test( t ) { - var x; - var v; - - x = [ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]; - - v = variancetk( 4, 1, x, 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]; - - v = variancetk( 4, 1, toAccessorArray( x ), 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); From 9620756c1d37e87cbe4d29f75206b670aa0666a2 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:15:03 +0000 Subject: [PATCH 18/32] feat: add `stats/strided/variancepn` Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../stats/strided/variancepn/README.md | 268 +++++++++++++ .../strided/variancepn/benchmark/benchmark.js | 96 +++++ .../variancepn/benchmark/benchmark.ndarray.js | 96 +++++ .../docs/img/equation_population_mean.svg | 42 ++ .../docs/img/equation_population_variance.svg | 54 +++ .../docs/img/equation_sample_mean.svg | 43 +++ .../img/equation_unbiased_sample_variance.svg | 61 +++ .../stats/strided/variancepn/docs/repl.txt | 113 ++++++ .../strided/variancepn/docs/types/index.d.ts | 96 +++++ .../strided/variancepn/docs/types/test.ts | 190 +++++++++ .../strided/variancepn/examples/index.js | 30 ++ .../stats/strided/variancepn/lib/accessors.js | 97 +++++ .../stats/strided/variancepn/lib/index.js | 59 +++ .../stats/strided/variancepn/lib/main.js | 62 +++ .../stats/strided/variancepn/lib/ndarray.js | 95 +++++ .../stats/strided/variancepn/package.json | 73 ++++ .../stats/strided/variancepn/test/test.js | 38 ++ .../strided/variancepn/test/test.ndarray.js | 350 +++++++++++++++++ .../variancepn/test/test.variancepn.js | 359 ++++++++++++++++++ 19 files changed, 2222 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_population_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_population_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_sample_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_unbiased_sample_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancepn/test/test.variancepn.js diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/README.md b/lib/node_modules/@stdlib/stats/strided/variancepn/README.md new file mode 100644 index 000000000000..a44c7f82f427 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/README.md @@ -0,0 +1,268 @@ + + +# variancepn + +> Calculate the [variance][variance] of a strided array using a two-pass algorithm. + +
+ +The population [variance][variance] of a finite size population of size `N` is given by + + + +```math +\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 +``` + + + + + +where the population mean is given by + + + +```math +\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i +``` + + + + + +Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, + + + +```math +s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 +``` + + + + + +where the sample mean is given by + + + +```math +\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + + + +The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. + +
+ + + +
+ +## Usage + +```javascript +var variancepn = require( '@stdlib/stats/strided/variancepn' ); +``` + +#### variancepn( N, correction, x, strideX ) + +Computes the [variance][variance] of a strided array using a two-pass algorithm. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; + +var v = variancepn( x.length, 1, x, 1 ); +// returns ~4.3333 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, + +```javascript +var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; + +var v = variancepn( 4, 1, x, 2 ); +// returns 6.25 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var v = variancepn( 4, 1, x1, 2 ); +// returns 6.25 +``` + +#### variancepn.ndarray( N, correction, x, strideX, offsetX ) + +Computes the [variance][variance] of a strided array using a two-pass algorithm and alternative indexing semantics. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; + +var v = variancepn.ndarray( x.length, 1, x, 1, 0 ); +// returns ~4.33333 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element + +```javascript +var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; + +var v = variancepn.ndarray( 4, 1, x, 2, 1 ); +// returns 6.25 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `NaN`. +- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). +- Depending on the environment, the typed versions ([`dvariancepn`][@stdlib/stats/strided/dvariancepn], [`svariancepn`][@stdlib/stats/strided/svariancepn], etc.) are likely to be significantly more performant. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var variancepn = require( '@stdlib/stats/strided/variancepn' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +console.log( x ); + +var v = variancepn( x.length, 1, x, 1 ); +console.log( v ); +``` + +
+ + + +* * * + +
+ +## References + +- Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958][@neely:1966a]. +- Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036][@schubert:2018a]. + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/variancepn/benchmark/benchmark.js new file mode 100644 index 000000000000..39accf4d64b1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/benchmark/benchmark.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var variancepn = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = variancepn( x.length, 1, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/variancepn/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..95fcc33e9c07 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/benchmark/benchmark.ndarray.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var variancepn = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = variancepn( x.length, 1, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_population_mean.svg new file mode 100644 index 000000000000..4bbdf0d2a56f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_population_mean.svg @@ -0,0 +1,42 @@ + +mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_population_variance.svg new file mode 100644 index 000000000000..4130ba0750d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_population_variance.svg @@ -0,0 +1,54 @@ + +sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_sample_mean.svg new file mode 100644 index 000000000000..aea7a5f6687a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_sample_mean.svg @@ -0,0 +1,43 @@ + +x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_unbiased_sample_variance.svg new file mode 100644 index 000000000000..1ae1283e7fb1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/docs/img/equation_unbiased_sample_variance.svg @@ -0,0 +1,61 @@ + +s squared equals 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 + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/variancepn/docs/repl.txt new file mode 100644 index 000000000000..0f5b45ec364c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/docs/repl.txt @@ -0,0 +1,113 @@ + +{{alias}}( N, correction, x, strideX ) + Computes the variance of a strided array using a two-pass algorithm. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns `NaN`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > {{alias}}( x.length, 1, x, 1 ) + ~4.3333 + + // Using `N` and stride parameters: + > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; + > {{alias}}( 3, 1, x, 2 ) + ~4.3333 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, 1, x1, 2 ) + ~4.3333 + + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) + Computes the variance of a strided array using a two-pass algorithm and + alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the `offset` parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) + ~4.3333 + + // Using offset parameter: + > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; + > {{alias}}.ndarray( 3, 1, x, 2, 1 ) + ~4.3333 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/variancepn/docs/types/index.d.ts new file mode 100644 index 000000000000..067b117ec1b1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/docs/types/index.d.ts @@ -0,0 +1,96 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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 + +/// + +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `variancepn`. +*/ +interface Routine { + /** + * Computes the variance of a strided array using a two-pass algorithm. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @returns variance + * + * @example + * var x = [ 1.0, -2.0, 2.0 ]; + * + * var v = variancepn( x.length, 1, x, 1 ); + * // returns ~4.3333 + */ + ( N: number, correction: number, x: InputArray, strideX: number ): number; + + /** + * Computes the variance of a strided array using a two-pass algorithm and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns variance + * + * @example + * var x = [ 1.0, -2.0, 2.0 ]; + * + * var v = variancepn.ndarray( x.length, 1, x, 1, 0 ); + * // returns ~4.3333 + */ + ndarray( N: number, correction: number, x: InputArray, strideX: number, offsetX: number ): number; +} + +/** +* Computes the variance of a strided array using a two-pass algorithm. +* +* @param N - number of indexed elements +* @param correction - degrees of freedom adjustment +* @param x - input array +* @param strideX - stride length +* @returns variance +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancepn( x.length, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancepn.ndarray( x.length, 1, x, 1, 0 ); +* // returns ~4.3333 +*/ +declare var variancepn: Routine; + + +// EXPORTS // + +export = variancepn; diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/variancepn/docs/types/test.ts new file mode 100644 index 000000000000..6d421920bf71 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/docs/types/test.ts @@ -0,0 +1,190 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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 AccessorArray = require( '@stdlib/array/base/accessor' ); +import variancepn = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Float64Array( 10 ); + + variancepn( x.length, 1, x, 1 ); // $ExpectType number + variancepn( x.length, 1, new AccessorArray( x ), 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancepn( '10', 1, x, 1 ); // $ExpectError + variancepn( true, 1, x, 1 ); // $ExpectError + variancepn( false, 1, x, 1 ); // $ExpectError + variancepn( null, 1, x, 1 ); // $ExpectError + variancepn( undefined, 1, x, 1 ); // $ExpectError + variancepn( [], 1, x, 1 ); // $ExpectError + variancepn( {}, 1, x, 1 ); // $ExpectError + variancepn( ( x: number ): number => x, 1, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancepn( x.length, '10', x, 1 ); // $ExpectError + variancepn( x.length, true, x, 1 ); // $ExpectError + variancepn( x.length, false, x, 1 ); // $ExpectError + variancepn( x.length, null, x, 1 ); // $ExpectError + variancepn( x.length, undefined, x, 1 ); // $ExpectError + variancepn( x.length, [], x, 1 ); // $ExpectError + variancepn( x.length, {}, x, 1 ); // $ExpectError + variancepn( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + variancepn( x.length, 1, 10, 1 ); // $ExpectError + variancepn( x.length, 1, '10', 1 ); // $ExpectError + variancepn( x.length, 1, true, 1 ); // $ExpectError + variancepn( x.length, 1, false, 1 ); // $ExpectError + variancepn( x.length, 1, null, 1 ); // $ExpectError + variancepn( x.length, 1, undefined, 1 ); // $ExpectError + variancepn( x.length, 1, [ '1' ], 1 ); // $ExpectError + variancepn( x.length, 1, {}, 1 ); // $ExpectError + variancepn( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancepn( x.length, 1, x, '10' ); // $ExpectError + variancepn( x.length, 1, x, true ); // $ExpectError + variancepn( x.length, 1, x, false ); // $ExpectError + variancepn( x.length, 1, x, null ); // $ExpectError + variancepn( x.length, 1, x, undefined ); // $ExpectError + variancepn( x.length, 1, x, [] ); // $ExpectError + variancepn( x.length, 1, x, {} ); // $ExpectError + variancepn( x.length, 1, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + variancepn(); // $ExpectError + variancepn( x.length ); // $ExpectError + variancepn( x.length, 1 ); // $ExpectError + variancepn( x.length, 1, x ); // $ExpectError + variancepn( x.length, 1, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + + variancepn.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number + variancepn.ndarray( x.length, 1, new AccessorArray( x ), 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancepn.ndarray( '10', 1, x, 1, 0 ); // $ExpectError + variancepn.ndarray( true, 1, x, 1, 0 ); // $ExpectError + variancepn.ndarray( false, 1, x, 1, 0 ); // $ExpectError + variancepn.ndarray( null, 1, x, 1, 0 ); // $ExpectError + variancepn.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError + variancepn.ndarray( [], 1, x, 1, 0 ); // $ExpectError + variancepn.ndarray( {}, 1, x, 1, 0 ); // $ExpectError + variancepn.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancepn.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, [], x, 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + variancepn.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, [ '1' ], 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancepn.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, x, true, 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, x, false, 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, x, null, 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, x, [], 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError + variancepn.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancepn.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError + variancepn.ndarray( x.length, 1, x, 1, true ); // $ExpectError + variancepn.ndarray( x.length, 1, x, 1, false ); // $ExpectError + variancepn.ndarray( x.length, 1, x, 1, null ); // $ExpectError + variancepn.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError + variancepn.ndarray( x.length, 1, x, 1, [] ); // $ExpectError + variancepn.ndarray( x.length, 1, x, 1, {} ); // $ExpectError + variancepn.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + variancepn.ndarray(); // $ExpectError + variancepn.ndarray( x.length ); // $ExpectError + variancepn.ndarray( x.length, 1 ); // $ExpectError + variancepn.ndarray( x.length, 1, x ); // $ExpectError + variancepn.ndarray( x.length, 1, x, 1 ); // $ExpectError + variancepn.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/examples/index.js b/lib/node_modules/@stdlib/stats/strided/variancepn/examples/index.js new file mode 100644 index 000000000000..1604300161f2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/examples/index.js @@ -0,0 +1,30 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var variancepn = require( './../lib' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +console.log( x ); + +var v = variancepn( x.length, 1, x, 1 ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/lib/accessors.js b/lib/node_modules/@stdlib/stats/strided/variancepn/lib/accessors.js new file mode 100644 index 000000000000..70c77a3760dc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/lib/accessors.js @@ -0,0 +1,97 @@ +/** +* @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 gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ).ndarray; + + +// MAIN // + +/** +* Computes the variance of a strided array using a two-pass algorithm. +* +* ## Method +* +* - This implementation uses a two-pass approach, as suggested by Neely (1966). +* +* ## References +* +* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). +* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} variance +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +* +* var v = variancepn( 4, 1, arraylike2object( x ), 2, 1 ); +* // returns 6.25 +*/ +function variancepn( N, correction, x, strideX, offsetX ) { + var xbuf; + var get; + var mu; + var ix; + var M2; + var M; + var d; + var n; + var i; + + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessor: + get = x.accessors[ 0 ]; + + // Compute an estimate for the mean: + mu = gsumpw( N, xbuf, strideX, offsetX ) / N; + + n = N - correction; + ix = offsetX; + + // Compute the variance... + M2 = 0.0; + M = 0.0; + + for ( i = 0; i < N; i++ ) { + d = get( xbuf, ix ) - mu; + M2 += d * d; + M += d; + ix += strideX; + } + return (M2/n) - ((M/N)*(M/n)); +} + + +// EXPORTS // + +module.exports = variancepn; diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/lib/index.js b/lib/node_modules/@stdlib/stats/strided/variancepn/lib/index.js new file mode 100644 index 000000000000..660a6dbb5006 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/lib/index.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 the variance of a strided array using a two-pass algorithm. +* +* @module @stdlib/stats/strided/variancepn +* +* @example +* var variancepn = require( '@stdlib/stats/strided/variancepn' ); +* +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancepn( x.length, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var variancepn = require( '@stdlib/stats/strided/variancepn' ); +* +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = variancepn.ndarray( 4, 1, x, 2, 1 ); +* // returns 6.25 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/lib/main.js b/lib/node_modules/@stdlib/stats/strided/variancepn/lib/main.js new file mode 100644 index 000000000000..a9378f2693ab --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/lib/main.js @@ -0,0 +1,62 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes the variance of a strided array using a two-pass algorithm. +* +* ## Method +* +* - This implementation uses a two-pass approach, as suggested by Neely (1966). +* +* ## References +* +* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). +* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {Object} x - input array object +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {integer} offsetX - starting index +* @returns {number} variance +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancepn( x.length, 1, x, 1); +* // returns ~4.3333 +*/ +function variancepn( N, correction, x, strideX ) { + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = variancepn; diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/variancepn/lib/ndarray.js new file mode 100644 index 000000000000..8e032e6811aa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/lib/ndarray.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ).ndarray; +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Computes the variance of a strided array using a two-pass algorithm. +* +* ## Method +* +* - This implementation uses a two-pass approach, as suggested by Neely (1966). +* +* ## References +* +* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). +* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} variance +* +* @example +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = variancepn( 4, 1, x, 2, 1 ); +* // returns 6.25 +*/ +function variancepn( N, correction, x, strideX, offsetX ) { + var mu; + var ix; + var M2; + var o; + var M; + var d; + var n; + var i; + + n = N - correction; + if ( N <= 0 || n <= 0.0 ) { + return NaN; + } + if ( N === 1 || strideX === 0 ) { + return 0.0; + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, correction, o, strideX, offsetX ); + } + // Compute an estimate for the mean: + mu = gsumpw( N, x, strideX, offsetX ) / N; + + // Compute the variance... + ix = offsetX; + M2 = 0.0; + M = 0.0; + for ( i = 0; i < N; i++ ) { + d = x[ ix ] - mu; + M2 += d * d; + M += d; + ix += strideX; + } + return (M2/n) - ((M/N)*(M/n)); +} + + +// EXPORTS // + +module.exports = variancepn; diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/package.json b/lib/node_modules/@stdlib/stats/strided/variancepn/package.json new file mode 100644 index 000000000000..dc1164d41cd4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/stats/strided/variancepn", + "version": "0.0.0", + "description": "Calculate the variance of a strided array using a two-pass algorithm.", + "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", + "var", + "deviation", + "dispersion", + "sample variance", + "unbiased", + "stdev", + "std", + "standard deviation", + "strided", + "strided array", + "typed", + "array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/test/test.js b/lib/node_modules/@stdlib/stats/strided/variancepn/test/test.js new file mode 100644 index 000000000000..952358607ce1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 variancepn = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variancepn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof variancepn.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/variancepn/test/test.ndarray.js new file mode 100644 index 000000000000..2747ec614540 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/test/test.ndarray.js @@ -0,0 +1,350 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var variancepn = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variancepn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( variancepn.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancepn( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancepn( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancepn( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancepn( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancepn( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancepn( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancepn( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancepn( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancepn( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancepn( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancepn( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancepn( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( 0, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancepn( -1, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( 0, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancepn( -1, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( 1, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( 1, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancepn( x.length, x.length+1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( x.length, x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancepn( x.length, x.length+1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancepn( 4, 1, x, 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessor)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancepn( 4, 1, toAccessorArray( x ), 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancepn( 4, 1, x, -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessor)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancepn( 4, 1, toAccessorArray( x ), -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( x.length, 1, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( x.length, 1, toAccessorArray( x ), 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + + v = variancepn( 4, 1, x, 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter (accessor)', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + + v = variancepn( 4, 1, toAccessorArray( x ), 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/test/test.variancepn.js b/lib/node_modules/@stdlib/stats/strided/variancepn/test/test.variancepn.js new file mode 100644 index 000000000000..985611269c21 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/test/test.variancepn.js @@ -0,0 +1,359 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var variancepn = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variancepn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( variancepn.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancepn( x.length, 0, x, 1 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancepn( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancepn( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancepn( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancepn( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancepn( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancepn( x.length, 1, x, 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancepn( x.length, 1, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancepn( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancepn( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancepn( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancepn( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( 0, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancepn( -1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( 0, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancepn( -1, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( 1, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancepn( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( x.length, x.length, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancepn( x.length, x.length+1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancepn( 4, 1, x, 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessor)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancepn( 4, 1, toAccessorArray( x ), 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancepn( 4, 1, x, -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessor)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancepn( 4, 1, toAccessorArray( x ), -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( x.length, 1, toAccessorArray( x ), 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = variancepn( 4, 1, x1, 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets (accessor)', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = variancepn( 4, 1, toAccessorArray( x1 ), 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); From 72558ad7139b4fb3bb662b0e95ba24fdf439a700 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:16:55 +0000 Subject: [PATCH 19/32] remove: remove `variancepn` from namespace This commit removes the `variancepn` symbol from the `@stdlib/stats/base` namespace due to a package migration. BREAKING CHANGE: remove `variancepn` To migrate, users should access the same symbol via the `@stdlib/stats/strided` namespace. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/docs/types/index.d.ts | 24 ------------------- .../@stdlib/stats/base/lib/index.js | 9 ------- 2 files changed, 33 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts index 9553a9e60c26..915d1fa6fb2d 100644 --- a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts @@ -68,7 +68,6 @@ import stdevwd = require( '@stdlib/stats/base/stdevwd' ); import stdevyc = require( '@stdlib/stats/base/stdevyc' ); import variance = require( '@stdlib/stats/base/variance' ); import variancech = require( '@stdlib/stats/base/variancech' ); -import variancepn = require( '@stdlib/stats/base/variancepn' ); import dmeankbn2 = require( '@stdlib/stats/strided/dmeankbn2' ); import dmeanli = require( '@stdlib/stats/strided/dmeanli' ); import dmeanlipw = require( '@stdlib/stats/strided/dmeanlipw' ); @@ -1297,29 +1296,6 @@ interface Namespace { */ variancech: typeof variancech; - /** - * Computes the variance of a strided array using a two-pass algorithm. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param stride - stride length - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = ns.variancepn( x.length, 1, x, 1 ); - * // returns ~4.3333 - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = ns.variancepn.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - variancepn: typeof variancepn; - /** * Computes the arithmetic mean of a double-precision floating-point strided array using a second-order iterative Kahan–Babuška algorithm. * diff --git a/lib/node_modules/@stdlib/stats/base/lib/index.js b/lib/node_modules/@stdlib/stats/base/lib/index.js index 07b0a0075fac..c97b4c4ac4dd 100644 --- a/lib/node_modules/@stdlib/stats/base/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/lib/index.js @@ -477,15 +477,6 @@ setReadOnly( ns, 'variance', require( '@stdlib/stats/base/variance' ) ); */ setReadOnly( ns, 'variancech', require( '@stdlib/stats/base/variancech' ) ); -/** -* @name variancepn -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/stats/base/variancepn} -*/ -setReadOnly( ns, 'variancepn', require( '@stdlib/stats/base/variancepn' ) ); - /** * @name dmeankbn2 * @memberof ns From ad8dd231d796efb1677112b8072caf8fbe1d6f69 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:17:47 +0000 Subject: [PATCH 20/32] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/namespace/lib/namespace/base/strided/d.js | 4 ++-- .../@stdlib/namespace/lib/namespace/base/strided/n.js | 2 +- .../@stdlib/namespace/lib/namespace/base/strided/s.js | 4 ++-- .../@stdlib/namespace/lib/namespace/base/strided/v.js | 4 ++-- lib/node_modules/@stdlib/stats/array/variancepn/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/base/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/nanvariancepn/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/stdevpn/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/stdevpn/lib/ndarray.js | 2 +- lib/node_modules/@stdlib/stats/base/variance/lib/ndarray.js | 2 +- lib/node_modules/@stdlib/stats/base/variance/lib/variance.js | 2 +- lib/node_modules/@stdlib/stats/strided/dsvariancepn/README.md | 4 ++-- lib/node_modules/@stdlib/stats/strided/dvariancepn/README.md | 4 ++-- lib/node_modules/@stdlib/stats/strided/svariancepn/README.md | 4 ++-- 14 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js index 84ace489c5ed..587ab5aaee50 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js @@ -2166,7 +2166,7 @@ ns.push({ '@stdlib/stats/strided/dvariancepn', '@stdlib/stats/base/dsnanvariancepn', '@stdlib/stats/strided/dsvariance', - '@stdlib/stats/base/variancepn', + '@stdlib/stats/strided/variancepn', '@stdlib/stats/base/sdsvariance', '@stdlib/stats/strided/svariancepn' ] @@ -2281,7 +2281,7 @@ ns.push({ '@stdlib/stats/strided/dstdevpn', '@stdlib/stats/strided/dvariance', '@stdlib/stats/strided/svariancepn', - '@stdlib/stats/base/variancepn' + '@stdlib/stats/strided/variancepn' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js index 796c53c8ea0f..5d9f7186789e 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js @@ -354,7 +354,7 @@ ns.push({ '@stdlib/stats/base/nanstdevpn', '@stdlib/stats/base/nanvariance', '@stdlib/stats/base/snanvariancepn', - '@stdlib/stats/base/variancepn' + '@stdlib/stats/strided/variancepn' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js index 4f0e35a81fac..eb5a459de1e8 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js @@ -1826,7 +1826,7 @@ ns.push({ '@stdlib/stats/strided/sstdevpn', '@stdlib/stats/base/stdev', '@stdlib/stats/base/stdevmpn', - '@stdlib/stats/base/variancepn' + '@stdlib/stats/strided/variancepn' ] }); @@ -1929,7 +1929,7 @@ ns.push({ '@stdlib/stats/strided/sstdevpn', '@stdlib/stats/strided/svariance', '@stdlib/stats/base/svarmpn', - '@stdlib/stats/base/variancepn' + '@stdlib/stats/strided/variancepn' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js index d71863c07e3c..f89c591a3ef1 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js @@ -55,8 +55,8 @@ ns.push({ ns.push({ 'alias': 'base.strided.variancepn', - 'path': '@stdlib/stats/base/variancepn', - 'value': require( '@stdlib/stats/base/variancepn' ), + 'path': '@stdlib/stats/strided/variancepn', + 'value': require( '@stdlib/stats/strided/variancepn' ), 'type': 'Function', 'related': [ '@stdlib/stats/strided/dvariancepn', diff --git a/lib/node_modules/@stdlib/stats/array/variancepn/lib/main.js b/lib/node_modules/@stdlib/stats/array/variancepn/lib/main.js index 1c24564b63d1..6a6d0693fd49 100644 --- a/lib/node_modules/@stdlib/stats/array/variancepn/lib/main.js +++ b/lib/node_modules/@stdlib/stats/array/variancepn/lib/main.js @@ -26,7 +26,7 @@ var dtypes = require( '@stdlib/array/dtypes' ); var dtype = require( '@stdlib/array/dtype' ); var contains = require( '@stdlib/array/base/assert/contains' ); var join = require( '@stdlib/array/base/join' ); -var strided = require( '@stdlib/stats/base/variancepn' ).ndarray; +var strided = require( '@stdlib/stats/strided/variancepn' ).ndarray; var format = require( '@stdlib/string/format' ); diff --git a/lib/node_modules/@stdlib/stats/base/README.md b/lib/node_modules/@stdlib/stats/base/README.md index 8a0a53325b18..70e8e07216e9 100644 --- a/lib/node_modules/@stdlib/stats/base/README.md +++ b/lib/node_modules/@stdlib/stats/base/README.md @@ -109,7 +109,7 @@ The namespace contains the following statistical functions: - [`stdevyc( N, correction, x, stride )`][@stdlib/stats/base/stdevyc]: calculate the standard deviation of a strided array using a one-pass algorithm proposed by Youngs and Cramer. - [`variance( N, correction, x, strideX )`][@stdlib/stats/base/variance]: calculate the variance of a strided array. - [`variancech( N, correction, x, strideX )`][@stdlib/stats/base/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. -- [`variancepn( N, correction, x, strideX )`][@stdlib/stats/base/variancepn]: calculate the variance of a strided array using a two-pass algorithm. +- [`variancepn( N, correction, x, strideX )`][@stdlib/stats/strided/variancepn]: calculate the variance of a strided array using a two-pass algorithm. - [`variancetk( N, correction, x, strideX )`][@stdlib/stats/strided/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. - [`variancewd( N, correction, x, stride )`][@stdlib/stats/strided/variancewd]: calculate the variance of a strided array using Welford's algorithm. - [`varianceyc( N, correction, x, strideX )`][@stdlib/stats/strided/varianceyc]: calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. @@ -267,7 +267,7 @@ console.log( objectKeys( ns ) ); [@stdlib/stats/base/variancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancech -[@stdlib/stats/base/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancepn +[@stdlib/stats/strided/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancepn [@stdlib/stats/strided/variancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancetk diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancepn/README.md b/lib/node_modules/@stdlib/stats/base/nanvariancepn/README.md index dcb9fb7388b6..8143f6b4b0a5 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanvariancepn/README.md @@ -235,7 +235,7 @@ console.log( v ); - [`@stdlib/stats/base/nanstdevpn`][@stdlib/stats/base/nanstdevpn]: calculate the standard deviation of a strided array ignoring NaN values and using a two-pass algorithm. - [`@stdlib/stats/base/nanvariance`][@stdlib/stats/base/nanvariance]: calculate the variance of a strided array ignoring NaN values. - [`@stdlib/stats/base/snanvariancepn`][@stdlib/stats/base/snanvariancepn]: calculate the variance of a single-precision floating-point strided array ignoring NaN values and using a two-pass algorithm. -- [`@stdlib/stats/base/variancepn`][@stdlib/stats/base/variancepn]: calculate the variance of a strided array using a two-pass algorithm. +- [`@stdlib/stats/strided/variancepn`][@stdlib/stats/strided/variancepn]: calculate the variance of a strided array using a two-pass algorithm. @@ -267,7 +267,7 @@ console.log( v ); [@stdlib/stats/base/snanvariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/snanvariancepn -[@stdlib/stats/base/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancepn +[@stdlib/stats/strided/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancepn diff --git a/lib/node_modules/@stdlib/stats/base/stdevpn/README.md b/lib/node_modules/@stdlib/stats/base/stdevpn/README.md index a1bc18a66a8e..509644994df8 100644 --- a/lib/node_modules/@stdlib/stats/base/stdevpn/README.md +++ b/lib/node_modules/@stdlib/stats/base/stdevpn/README.md @@ -228,7 +228,7 @@ console.log( v ); - [`@stdlib/stats/base/nanstdevpn`][@stdlib/stats/base/nanstdevpn]: calculate the standard deviation of a strided array ignoring NaN values and using a two-pass algorithm. - [`@stdlib/stats/strided/sstdevpn`][@stdlib/stats/strided/sstdevpn]: calculate the standard deviation of a single-precision floating-point strided array using a two-pass algorithm. - [`@stdlib/stats/base/stdev`][@stdlib/stats/base/stdev]: calculate the standard deviation of a strided array. -- [`@stdlib/stats/base/variancepn`][@stdlib/stats/base/variancepn]: calculate the variance of a strided array using a two-pass algorithm. +- [`@stdlib/stats/strided/variancepn`][@stdlib/stats/strided/variancepn]: calculate the variance of a strided array using a two-pass algorithm. @@ -260,7 +260,7 @@ console.log( v ); [@stdlib/stats/base/stdev]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/stdev -[@stdlib/stats/base/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancepn +[@stdlib/stats/strided/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancepn diff --git a/lib/node_modules/@stdlib/stats/base/stdevpn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/stdevpn/lib/ndarray.js index 035eb84ea73b..180e306b41a7 100644 --- a/lib/node_modules/@stdlib/stats/base/stdevpn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/stdevpn/lib/ndarray.js @@ -20,7 +20,7 @@ // MODULES // -var variancepn = require( '@stdlib/stats/base/variancepn' ).ndarray; +var variancepn = require( '@stdlib/stats/strided/variancepn' ).ndarray; var sqrt = require( '@stdlib/math/base/special/sqrt' ); diff --git a/lib/node_modules/@stdlib/stats/base/variance/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/variance/lib/ndarray.js index ce974d3a0c0a..1cd7667fb326 100644 --- a/lib/node_modules/@stdlib/stats/base/variance/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/variance/lib/ndarray.js @@ -20,7 +20,7 @@ // MODULES // -var variancepn = require( '@stdlib/stats/base/variancepn' ).ndarray; +var variancepn = require( '@stdlib/stats/strided/variancepn' ).ndarray; // MAIN // diff --git a/lib/node_modules/@stdlib/stats/base/variance/lib/variance.js b/lib/node_modules/@stdlib/stats/base/variance/lib/variance.js index a3a52133fa6b..90873fa2cf62 100644 --- a/lib/node_modules/@stdlib/stats/base/variance/lib/variance.js +++ b/lib/node_modules/@stdlib/stats/base/variance/lib/variance.js @@ -20,7 +20,7 @@ // MODULES // -var variancepn = require( '@stdlib/stats/base/variancepn' ); +var variancepn = require( '@stdlib/stats/strided/variancepn' ); // MAIN // diff --git a/lib/node_modules/@stdlib/stats/strided/dsvariancepn/README.md b/lib/node_modules/@stdlib/stats/strided/dsvariancepn/README.md index 531a7ddea356..435818df74ab 100644 --- a/lib/node_modules/@stdlib/stats/strided/dsvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/strided/dsvariancepn/README.md @@ -352,7 +352,7 @@ int main( void ) { - [`@stdlib/stats/strided/dvariancepn`][@stdlib/stats/strided/dvariancepn]: calculate the variance of a double-precision floating-point strided array using a two-pass algorithm. - [`@stdlib/stats/strided/dsvariance`][@stdlib/stats/strided/dsvariance]: calculate the variance of a single-precision floating-point strided array using extended accumulation and returning an extended precision result. -- [`@stdlib/stats/base/variancepn`][@stdlib/stats/base/variancepn]: calculate the variance of a strided array using a two-pass algorithm. +- [`@stdlib/stats/strided/variancepn`][@stdlib/stats/strided/variancepn]: calculate the variance of a strided array using a two-pass algorithm. - [`@stdlib/stats/strided/svariancepn`][@stdlib/stats/strided/svariancepn]: calculate the variance of a single-precision floating-point strided array using a two-pass algorithm. @@ -379,7 +379,7 @@ int main( void ) { [@stdlib/stats/strided/dsvariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dsvariance -[@stdlib/stats/base/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancepn +[@stdlib/stats/strided/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancepn [@stdlib/stats/strided/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancepn diff --git a/lib/node_modules/@stdlib/stats/strided/dvariancepn/README.md b/lib/node_modules/@stdlib/stats/strided/dvariancepn/README.md index fe0650b2339c..3f06234afb99 100644 --- a/lib/node_modules/@stdlib/stats/strided/dvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/strided/dvariancepn/README.md @@ -353,7 +353,7 @@ int main( void ) { - [`@stdlib/stats/strided/dstdevpn`][@stdlib/stats/strided/dstdevpn]: calculate the standard deviation of a double-precision floating-point strided array using a two-pass algorithm. - [`@stdlib/stats/strided/dvariance`][@stdlib/stats/strided/dvariance]: calculate the variance of a double-precision floating-point strided array. - [`@stdlib/stats/strided/svariancepn`][@stdlib/stats/strided/svariancepn]: calculate the variance of a single-precision floating-point strided array using a two-pass algorithm. -- [`@stdlib/stats/base/variancepn`][@stdlib/stats/base/variancepn]: calculate the variance of a strided array using a two-pass algorithm. +- [`@stdlib/stats/strided/variancepn`][@stdlib/stats/strided/variancepn]: calculate the variance of a strided array using a two-pass algorithm. @@ -383,7 +383,7 @@ int main( void ) { [@stdlib/stats/strided/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancepn -[@stdlib/stats/base/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancepn +[@stdlib/stats/strided/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancepn diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/README.md b/lib/node_modules/@stdlib/stats/strided/svariancepn/README.md index 94825d3ed87a..58ffdc42e8b5 100644 --- a/lib/node_modules/@stdlib/stats/strided/svariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/README.md @@ -353,7 +353,7 @@ int main( void ) { - [`@stdlib/stats/base/snanvariancepn`][@stdlib/stats/base/snanvariancepn]: calculate the variance of a single-precision floating-point strided array ignoring NaN values and using a two-pass algorithm. - [`@stdlib/stats/strided/sstdevpn`][@stdlib/stats/strided/sstdevpn]: calculate the standard deviation of a single-precision floating-point strided array using a two-pass algorithm. - [`@stdlib/stats/strided/svariance`][@stdlib/stats/strided/svariance]: calculate the variance of a single-precision floating-point strided array. -- [`@stdlib/stats/base/variancepn`][@stdlib/stats/base/variancepn]: calculate the variance of a strided array using a two-pass algorithm. +- [`@stdlib/stats/strided/variancepn`][@stdlib/stats/strided/variancepn]: calculate the variance of a strided array using a two-pass algorithm. @@ -383,7 +383,7 @@ int main( void ) { [@stdlib/stats/strided/svariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariance -[@stdlib/stats/base/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancepn +[@stdlib/stats/strided/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancepn From 4445e7ad033a632f987a3dee9bf9afde3ccba7a8 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:19:35 +0000 Subject: [PATCH 21/32] remove: remove `stats/base/variancepn` This commit removes `@stdlib/stats/base/variancepn` in favor of `@stdlib/stats/strided/variancepn`. BREAKING CHANGE: remove `stats/base/variancepn` To migrate, users should update their require/import paths to use `@stdlib/stats/strided/variancepn`, which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/variancepn/README.md | 268 ------------- .../base/variancepn/benchmark/benchmark.js | 96 ----- .../variancepn/benchmark/benchmark.ndarray.js | 96 ----- .../docs/img/equation_population_mean.svg | 42 -- .../docs/img/equation_population_variance.svg | 54 --- .../docs/img/equation_sample_mean.svg | 43 --- .../img/equation_unbiased_sample_variance.svg | 61 --- .../stats/base/variancepn/docs/repl.txt | 113 ------ .../base/variancepn/docs/types/index.d.ts | 96 ----- .../stats/base/variancepn/docs/types/test.ts | 190 --------- .../stats/base/variancepn/examples/index.js | 30 -- .../stats/base/variancepn/lib/accessors.js | 97 ----- .../stats/base/variancepn/lib/index.js | 59 --- .../@stdlib/stats/base/variancepn/lib/main.js | 62 --- .../stats/base/variancepn/lib/ndarray.js | 95 ----- .../stats/base/variancepn/package.json | 73 ---- .../stats/base/variancepn/test/test.js | 38 -- .../base/variancepn/test/test.ndarray.js | 350 ----------------- .../base/variancepn/test/test.variancepn.js | 359 ------------------ 19 files changed, 2222 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/README.md delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_population_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_population_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_sample_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_unbiased_sample_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/examples/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/lib/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/lib/main.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/package.json delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/test/test.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/test/test.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/test/test.variancepn.js diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/README.md b/lib/node_modules/@stdlib/stats/base/variancepn/README.md deleted file mode 100644 index 0bfd12f46a3b..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/README.md +++ /dev/null @@ -1,268 +0,0 @@ - - -# variancepn - -> Calculate the [variance][variance] of a strided array using a two-pass algorithm. - -
- -The population [variance][variance] of a finite size population of size `N` is given by - - - -```math -\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 -``` - - - - - -where the population mean is given by - - - -```math -\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i -``` - - - - - -Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, - - - -```math -s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 -``` - - - - - -where the sample mean is given by - - - -```math -\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i -``` - - - - - -The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. - -
- - - -
- -## Usage - -```javascript -var variancepn = require( '@stdlib/stats/base/variancepn' ); -``` - -#### variancepn( N, correction, x, strideX ) - -Computes the [variance][variance] of a strided array using a two-pass algorithm. - -```javascript -var x = [ 1.0, -2.0, 2.0 ]; - -var v = variancepn( x.length, 1, x, 1 ); -// returns ~4.3333 -``` - -The function has the following parameters: - -- **N**: number of indexed elements. -- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. -- **strideX**: stride length for `x`. - -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, - -```javascript -var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; - -var v = variancepn( 4, 1, x, 2 ); -// returns 6.25 -``` - -Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); - -var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - -var v = variancepn( 4, 1, x1, 2 ); -// returns 6.25 -``` - -#### variancepn.ndarray( N, correction, x, strideX, offsetX ) - -Computes the [variance][variance] of a strided array using a two-pass algorithm and alternative indexing semantics. - -```javascript -var x = [ 1.0, -2.0, 2.0 ]; - -var v = variancepn.ndarray( x.length, 1, x, 1, 0 ); -// returns ~4.33333 -``` - -The function has the following additional parameters: - -- **offsetX**: starting index for `x`. - -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element - -```javascript -var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; - -var v = variancepn.ndarray( 4, 1, x, 2, 1 ); -// returns 6.25 -``` - -
- - - -
- -## Notes - -- If `N <= 0`, both functions return `NaN`. -- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. -- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). -- Depending on the environment, the typed versions ([`dvariancepn`][@stdlib/stats/strided/dvariancepn], [`svariancepn`][@stdlib/stats/strided/svariancepn], etc.) are likely to be significantly more performant. - -
- - - -
- -## Examples - - - -```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var variancepn = require( '@stdlib/stats/base/variancepn' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); -console.log( x ); - -var v = variancepn( x.length, 1, x, 1 ); -console.log( v ); -``` - -
- - - -* * * - -
- -## References - -- Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958][@neely:1966a]. -- Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036][@schubert:2018a]. - -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.js deleted file mode 100644 index 39accf4d64b1..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var variancepn = require( './../lib/main.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = variancepn( x.length, 1, x, 1 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.ndarray.js deleted file mode 100644 index 95fcc33e9c07..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var variancepn = require( './../lib/ndarray.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = variancepn( x.length, 1, x, 1, 0 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':ndarray:len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_population_mean.svg deleted file mode 100644 index 4bbdf0d2a56f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_population_mean.svg +++ /dev/null @@ -1,42 +0,0 @@ - -mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_population_variance.svg deleted file mode 100644 index 4130ba0750d2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_population_variance.svg +++ /dev/null @@ -1,54 +0,0 @@ - -sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_sample_mean.svg deleted file mode 100644 index aea7a5f6687a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_sample_mean.svg +++ /dev/null @@ -1,43 +0,0 @@ - -x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_unbiased_sample_variance.svg deleted file mode 100644 index 1ae1283e7fb1..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/img/equation_unbiased_sample_variance.svg +++ /dev/null @@ -1,61 +0,0 @@ - -s squared equals 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 - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt deleted file mode 100644 index 0f5b45ec364c..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt +++ /dev/null @@ -1,113 +0,0 @@ - -{{alias}}( N, correction, x, strideX ) - Computes the variance of a strided array using a two-pass algorithm. - - The `N` and stride parameters determine which elements in the strided array - are accessed at runtime. - - Indexing is relative to the first index. To introduce an offset, use a typed - array view. - - If `N <= 0`, the function returns `NaN`. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Array|TypedArray - Input array. - - strideX: integer - Stride length. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = [ 1.0, -2.0, 2.0 ]; - > {{alias}}( x.length, 1, x, 1 ) - ~4.3333 - - // Using `N` and stride parameters: - > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; - > {{alias}}( 3, 1, x, 2 ) - ~4.3333 - - // Using view offsets: - > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 1, x1, 2 ) - ~4.3333 - - -{{alias}}.ndarray( N, correction, x, strideX, offsetX ) - Computes the variance of a strided array using a two-pass algorithm and - alternative indexing semantics. - - While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a - starting index. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Array|TypedArray - Input array. - - strideX: integer - Stride length. - - offsetX: integer - Starting index. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = [ 1.0, -2.0, 2.0 ]; - > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) - ~4.3333 - - // Using offset parameter: - > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; - > {{alias}}.ndarray( 3, 1, x, 2, 1 ) - ~4.3333 - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts deleted file mode 100644 index 067b117ec1b1..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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 - -/// - -import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; - -/** -* Input array. -*/ -type InputArray = NumericArray | Collection | AccessorArrayLike; - -/** -* Interface describing `variancepn`. -*/ -interface Routine { - /** - * Computes the variance of a strided array using a two-pass algorithm. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = variancepn( x.length, 1, x, 1 ); - * // returns ~4.3333 - */ - ( N: number, correction: number, x: InputArray, strideX: number ): number; - - /** - * Computes the variance of a strided array using a two-pass algorithm and alternative indexing semantics. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @param offsetX - starting index - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = variancepn.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - ndarray( N: number, correction: number, x: InputArray, strideX: number, offsetX: number ): number; -} - -/** -* Computes the variance of a strided array using a two-pass algorithm. -* -* @param N - number of indexed elements -* @param correction - degrees of freedom adjustment -* @param x - input array -* @param strideX - stride length -* @returns variance -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancepn( x.length, 1, x, 1 ); -* // returns ~4.3333 -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancepn.ndarray( x.length, 1, x, 1, 0 ); -* // returns ~4.3333 -*/ -declare var variancepn: Routine; - - -// EXPORTS // - -export = variancepn; diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/test.ts deleted file mode 100644 index 6d421920bf71..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/test.ts +++ /dev/null @@ -1,190 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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 AccessorArray = require( '@stdlib/array/base/accessor' ); -import variancepn = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const x = new Float64Array( 10 ); - - variancepn( x.length, 1, x, 1 ); // $ExpectType number - variancepn( x.length, 1, new AccessorArray( x ), 1 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancepn( '10', 1, x, 1 ); // $ExpectError - variancepn( true, 1, x, 1 ); // $ExpectError - variancepn( false, 1, x, 1 ); // $ExpectError - variancepn( null, 1, x, 1 ); // $ExpectError - variancepn( undefined, 1, x, 1 ); // $ExpectError - variancepn( [], 1, x, 1 ); // $ExpectError - variancepn( {}, 1, x, 1 ); // $ExpectError - variancepn( ( x: number ): number => x, 1, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancepn( x.length, '10', x, 1 ); // $ExpectError - variancepn( x.length, true, x, 1 ); // $ExpectError - variancepn( x.length, false, x, 1 ); // $ExpectError - variancepn( x.length, null, x, 1 ); // $ExpectError - variancepn( x.length, undefined, x, 1 ); // $ExpectError - variancepn( x.length, [], x, 1 ); // $ExpectError - variancepn( x.length, {}, x, 1 ); // $ExpectError - variancepn( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a numeric array... -{ - const x = new Float64Array( 10 ); - - variancepn( x.length, 1, 10, 1 ); // $ExpectError - variancepn( x.length, 1, '10', 1 ); // $ExpectError - variancepn( x.length, 1, true, 1 ); // $ExpectError - variancepn( x.length, 1, false, 1 ); // $ExpectError - variancepn( x.length, 1, null, 1 ); // $ExpectError - variancepn( x.length, 1, undefined, 1 ); // $ExpectError - variancepn( x.length, 1, [ '1' ], 1 ); // $ExpectError - variancepn( x.length, 1, {}, 1 ); // $ExpectError - variancepn( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancepn( x.length, 1, x, '10' ); // $ExpectError - variancepn( x.length, 1, x, true ); // $ExpectError - variancepn( x.length, 1, x, false ); // $ExpectError - variancepn( x.length, 1, x, null ); // $ExpectError - variancepn( x.length, 1, x, undefined ); // $ExpectError - variancepn( x.length, 1, x, [] ); // $ExpectError - variancepn( x.length, 1, x, {} ); // $ExpectError - variancepn( x.length, 1, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - - variancepn(); // $ExpectError - variancepn( x.length ); // $ExpectError - variancepn( x.length, 1 ); // $ExpectError - variancepn( x.length, 1, x ); // $ExpectError - variancepn( x.length, 1, x, 1, 10 ); // $ExpectError -} - -// Attached to main export is an `ndarray` method which returns a number... -{ - const x = new Float64Array( 10 ); - - variancepn.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number - variancepn.ndarray( x.length, 1, new AccessorArray( x ), 1, 0 ); // $ExpectType number -} - -// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancepn.ndarray( '10', 1, x, 1, 0 ); // $ExpectError - variancepn.ndarray( true, 1, x, 1, 0 ); // $ExpectError - variancepn.ndarray( false, 1, x, 1, 0 ); // $ExpectError - variancepn.ndarray( null, 1, x, 1, 0 ); // $ExpectError - variancepn.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError - variancepn.ndarray( [], 1, x, 1, 0 ); // $ExpectError - variancepn.ndarray( {}, 1, x, 1, 0 ); // $ExpectError - variancepn.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancepn.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, true, x, 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, false, x, 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, null, x, 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, [], x, 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... -{ - const x = new Float64Array( 10 ); - - variancepn.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, [ '1' ], 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancepn.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, x, true, 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, x, false, 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, x, null, 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, x, [], 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError - variancepn.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancepn.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError - variancepn.ndarray( x.length, 1, x, 1, true ); // $ExpectError - variancepn.ndarray( x.length, 1, x, 1, false ); // $ExpectError - variancepn.ndarray( x.length, 1, x, 1, null ); // $ExpectError - variancepn.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError - variancepn.ndarray( x.length, 1, x, 1, [] ); // $ExpectError - variancepn.ndarray( x.length, 1, x, 1, {} ); // $ExpectError - variancepn.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - - variancepn.ndarray(); // $ExpectError - variancepn.ndarray( x.length ); // $ExpectError - variancepn.ndarray( x.length, 1 ); // $ExpectError - variancepn.ndarray( x.length, 1, x ); // $ExpectError - variancepn.ndarray( x.length, 1, x, 1 ); // $ExpectError - variancepn.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/examples/index.js b/lib/node_modules/@stdlib/stats/base/variancepn/examples/index.js deleted file mode 100644 index 1604300161f2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/examples/index.js +++ /dev/null @@ -1,30 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var variancepn = require( './../lib' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); -console.log( x ); - -var v = variancepn( x.length, 1, x, 1 ); -console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js deleted file mode 100644 index 70c77a3760dc..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js +++ /dev/null @@ -1,97 +0,0 @@ -/** -* @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 gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ).ndarray; - - -// MAIN // - -/** -* Computes the variance of a strided array using a two-pass algorithm. -* -* ## Method -* -* - This implementation uses a two-pass approach, as suggested by Neely (1966). -* -* ## References -* -* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). -* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {Object} x - input array object -* @param {Collection} x.data - input array data -* @param {Array} x.accessors - array element accessors -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index -* @returns {number} variance -* -* @example -* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -* -* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* -* var v = variancepn( 4, 1, arraylike2object( x ), 2, 1 ); -* // returns 6.25 -*/ -function variancepn( N, correction, x, strideX, offsetX ) { - var xbuf; - var get; - var mu; - var ix; - var M2; - var M; - var d; - var n; - var i; - - // Cache reference to array data: - xbuf = x.data; - - // Cache a reference to the element accessor: - get = x.accessors[ 0 ]; - - // Compute an estimate for the mean: - mu = gsumpw( N, xbuf, strideX, offsetX ) / N; - - n = N - correction; - ix = offsetX; - - // Compute the variance... - M2 = 0.0; - M = 0.0; - - for ( i = 0; i < N; i++ ) { - d = get( xbuf, ix ) - mu; - M2 += d * d; - M += d; - ix += strideX; - } - return (M2/n) - ((M/N)*(M/n)); -} - - -// EXPORTS // - -module.exports = variancepn; diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/lib/index.js b/lib/node_modules/@stdlib/stats/base/variancepn/lib/index.js deleted file mode 100644 index 0c47634b9930..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/lib/index.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 the variance of a strided array using a two-pass algorithm. -* -* @module @stdlib/stats/base/variancepn -* -* @example -* var variancepn = require( '@stdlib/stats/base/variancepn' ); -* -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancepn( x.length, 1, x, 1 ); -* // returns ~4.3333 -* -* @example -* var variancepn = require( '@stdlib/stats/base/variancepn' ); -* -* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* -* var v = variancepn.ndarray( 4, 1, x, 2, 1 ); -* // returns 6.25 -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var ndarray = require( './ndarray.js' ); - - -// MAIN // - -setReadOnly( main, 'ndarray', ndarray ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/lib/main.js b/lib/node_modules/@stdlib/stats/base/variancepn/lib/main.js deleted file mode 100644 index a9378f2693ab..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/lib/main.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); -var ndarray = require( './ndarray.js' ); - - -// MAIN // - -/** -* Computes the variance of a strided array using a two-pass algorithm. -* -* ## Method -* -* - This implementation uses a two-pass approach, as suggested by Neely (1966). -* -* ## References -* -* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). -* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {Object} x - input array object -* @param {Array} x.accessors - array element accessors -* @param {integer} strideX - stride length -* @param {integer} offsetX - starting index -* @returns {number} variance -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancepn( x.length, 1, x, 1); -* // returns ~4.3333 -*/ -function variancepn( N, correction, x, strideX ) { - return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); -} - - -// EXPORTS // - -module.exports = variancepn; diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js deleted file mode 100644 index 8e032e6811aa..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ).ndarray; -var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -var accessors = require( './accessors.js' ); - - -// MAIN // - -/** -* Computes the variance of a strided array using a two-pass algorithm. -* -* ## Method -* -* - This implementation uses a two-pass approach, as suggested by Neely (1966). -* -* ## References -* -* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). -* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index -* @returns {number} variance -* -* @example -* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* -* var v = variancepn( 4, 1, x, 2, 1 ); -* // returns 6.25 -*/ -function variancepn( N, correction, x, strideX, offsetX ) { - var mu; - var ix; - var M2; - var o; - var M; - var d; - var n; - var i; - - n = N - correction; - if ( N <= 0 || n <= 0.0 ) { - return NaN; - } - if ( N === 1 || strideX === 0 ) { - return 0.0; - } - o = arraylike2object( x ); - if ( o.accessorProtocol ) { - return accessors( N, correction, o, strideX, offsetX ); - } - // Compute an estimate for the mean: - mu = gsumpw( N, x, strideX, offsetX ) / N; - - // Compute the variance... - ix = offsetX; - M2 = 0.0; - M = 0.0; - for ( i = 0; i < N; i++ ) { - d = x[ ix ] - mu; - M2 += d * d; - M += d; - ix += strideX; - } - return (M2/n) - ((M/N)*(M/n)); -} - - -// EXPORTS // - -module.exports = variancepn; diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/package.json b/lib/node_modules/@stdlib/stats/base/variancepn/package.json deleted file mode 100644 index ac2cbbe989a4..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/package.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "name": "@stdlib/stats/base/variancepn", - "version": "0.0.0", - "description": "Calculate the variance of a strided array using a two-pass algorithm.", - "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", - "var", - "deviation", - "dispersion", - "sample variance", - "unbiased", - "stdev", - "std", - "standard deviation", - "strided", - "strided array", - "typed", - "array" - ], - "__stdlib__": {} -} diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.js b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.js deleted file mode 100644 index 952358607ce1..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 variancepn = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variancepn, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { - t.strictEqual( typeof variancepn.ndarray, 'function', 'method is a function' ); - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.ndarray.js deleted file mode 100644 index 2747ec614540..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.ndarray.js +++ /dev/null @@ -1,350 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -var variancepn = require( './../lib/ndarray.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variancepn, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( variancepn.length, 5, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancepn( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancepn( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancepn( x.length, 0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancepn( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancepn( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancepn( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancepn( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancepn( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancepn( x.length, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancepn( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancepn( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancepn( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( 0, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancepn( -1, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( 0, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancepn( -1, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( 1, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( 1, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancepn( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( x.length, x.length, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancepn( x.length, x.length+1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancepn( 4, 1, x, 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a `stride` parameter (accessor)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancepn( 4, 1, toAccessorArray( x ), 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancepn( 4, 1, x, -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter (accessor)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancepn( 4, 1, toAccessorArray( x ), -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( x.length, 1, x, 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( x.length, 1, toAccessorArray( x ), 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter', function test( t ) { - var x; - var v; - - x = [ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]; - - v = variancepn( 4, 1, x, 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter (accessor)', function test( t ) { - var x; - var v; - - x = [ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]; - - v = variancepn( 4, 1, toAccessorArray( x ), 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.variancepn.js b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.variancepn.js deleted file mode 100644 index 985611269c21..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.variancepn.js +++ /dev/null @@ -1,359 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var Float64Array = require( '@stdlib/array/float64' ); -var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -var variancepn = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variancepn, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( variancepn.length, 4, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancepn( x.length, 0, x, 1 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancepn( x.length, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancepn( x.length, 0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancepn( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancepn( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancepn( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancepn( x.length, 1, x, 1 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancepn( x.length, 1, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancepn( x.length, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancepn( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancepn( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancepn( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( 0, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancepn( -1, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( 0, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancepn( -1, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( 1, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( 1, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancepn( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( x.length, x.length, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancepn( x.length, x.length+1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancepn( 4, 1, x, 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a `stride` parameter (accessor)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancepn( 4, 1, toAccessorArray( x ), 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancepn( 4, 1, x, -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter (accessor)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancepn( 4, 1, toAccessorArray( x ), -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( x.length, 1, x, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessor)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancepn( x.length, 1, toAccessorArray( x ), 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float64Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = variancepn( 4, 1, x1, 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets (accessor)', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float64Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = variancepn( 4, 1, toAccessorArray( x1 ), 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); From f9595aae3104a02826b98a64618c4f22d7edc70b Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:23:12 +0000 Subject: [PATCH 22/32] feat: add `stats/strided/variancech` Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../stats/strided/variancech/README.md | 275 ++++++++++++++ .../strided/variancech/benchmark/benchmark.js | 96 +++++ .../variancech/benchmark/benchmark.ndarray.js | 96 +++++ .../docs/img/equation_population_mean.svg | 42 ++ .../docs/img/equation_population_variance.svg | 54 +++ .../docs/img/equation_sample_mean.svg | 43 +++ .../img/equation_unbiased_sample_variance.svg | 61 +++ .../stats/strided/variancech/docs/repl.txt | 114 ++++++ .../strided/variancech/docs/types/index.d.ts | 96 +++++ .../strided/variancech/docs/types/test.ts | 190 ++++++++++ .../strided/variancech/examples/index.js | 30 ++ .../stats/strided/variancech/lib/accessors.js | 95 +++++ .../stats/strided/variancech/lib/index.js | 52 +++ .../stats/strided/variancech/lib/main.js | 35 ++ .../stats/strided/variancech/lib/ndarray.js | 98 +++++ .../strided/variancech/lib/variancech.js | 62 +++ .../stats/strided/variancech/package.json | 73 ++++ .../stats/strided/variancech/test/test.js | 38 ++ .../strided/variancech/test/test.ndarray.js | 350 +++++++++++++++++ .../variancech/test/test.variancech.js | 358 ++++++++++++++++++ 20 files changed, 2258 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_population_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_population_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_sample_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_unbiased_sample_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/lib/variancech.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variancech/test/test.variancech.js diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/README.md b/lib/node_modules/@stdlib/stats/strided/variancech/README.md new file mode 100644 index 000000000000..61e92a5e7b15 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/README.md @@ -0,0 +1,275 @@ + + +# variancech + +> Calculate the [variance][variance] of a strided array using a one-pass trial mean algorithm. + +
+ +The population [variance][variance] of a finite size population of size `N` is given by + + + +```math +\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 +``` + + + + + +where the population mean is given by + + + +```math +\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i +``` + + + + + +Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, + + + +```math +s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 +``` + + + + + +where the sample mean is given by + + + +```math +\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + + + +The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. + +
+ + + +
+ +## Usage + +```javascript +var variancech = require( '@stdlib/stats/strided/variancech' ); +``` + +#### variancech( N, correction, x, strideX ) + +Computes the [variance][variance] of a strided array using a one-pass trial mean algorithm. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; + +var v = variancech( x.length, 1, x, 1 ); +// returns ~4.3333 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, + +```javascript +var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; + +var v = variancech( 4, 1, x, 2 ); +// returns 6.25 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var v = variancech( 4, 1, x1, 2 ); +// returns 6.25 +``` + +#### variancech.ndarray( N, correction, x, strideX, offsetX ) + +Computes the [variance][variance] of a strided array using a one-pass trial mean algorithm and alternative indexing semantics. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; + +var v = variancech.ndarray( x.length, 1, x, 1, 0 ); +// returns ~4.33333 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element + +```javascript +var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; + +var v = variancech.ndarray( 4, 1, x, 2, 1 ); +// returns 6.25 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `NaN`. +- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. +- The underlying algorithm is a specialized case of Neely's two-pass algorithm. As the variance is invariant with respect to changes in the location parameter, the underlying algorithm uses the first strided array element as a trial mean to shift subsequent data values and thus mitigate catastrophic cancellation. Accordingly, the algorithm's accuracy is best when data is **unordered** (i.e., the data is **not** sorted in either ascending or descending order such that the first value is an "extreme" value). +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). +- Depending on the environment, the typed versions ([`dvariancech`][@stdlib/stats/strided/dvariancech], [`svariancech`][@stdlib/stats/strided/svariancech], etc.) are likely to be significantly more performant. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var variancech = require( '@stdlib/stats/strided/variancech' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +console.log( x ); + +var v = variancech( x.length, 1, x, 1 ); +console.log( v ); +``` + +
+ + + +* * * + +
+ +## References + +- Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958][@neely:1966a]. +- Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154][@ling:1974a]. +- Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. 1983. "Algorithms for Computing the Sample Variance: Analysis and Recommendations." _The American Statistician_ 37 (3). American Statistical Association, Taylor & Francis, Ltd.: 242–47. doi:[10.1080/00031305.1983.10483115][@chan:1983a]. +- Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036][@schubert:2018a]. + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/variancech/benchmark/benchmark.js new file mode 100644 index 000000000000..ac477d0789d7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/benchmark/benchmark.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var variancech = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = variancech( x.length, 1, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/variancech/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..b273ff4a8d68 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/benchmark/benchmark.ndarray.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var variancech = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = variancech( x.length, 1, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_population_mean.svg new file mode 100644 index 000000000000..4bbdf0d2a56f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_population_mean.svg @@ -0,0 +1,42 @@ + +mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_population_variance.svg new file mode 100644 index 000000000000..4130ba0750d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_population_variance.svg @@ -0,0 +1,54 @@ + +sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_sample_mean.svg new file mode 100644 index 000000000000..aea7a5f6687a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_sample_mean.svg @@ -0,0 +1,43 @@ + +x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_unbiased_sample_variance.svg new file mode 100644 index 000000000000..1ae1283e7fb1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/docs/img/equation_unbiased_sample_variance.svg @@ -0,0 +1,61 @@ + +s squared equals 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 + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/variancech/docs/repl.txt new file mode 100644 index 000000000000..929365feac6b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/docs/repl.txt @@ -0,0 +1,114 @@ + +{{alias}}( N, correction, x, strideX ) + Computes the variance of a strided array using a one-pass trial mean + algorithm. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns `NaN`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > {{alias}}( x.length, 1, x, 1 ) + ~4.3333 + + // Using `N` and stride parameters: + > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; + > {{alias}}( 3, 1, x, 2 ) + ~4.3333 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, 1, x1, 2 ) + ~4.3333 + + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) + Computes the variance of a strided array using a one-pass trial mean + algorithm and alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the `offset` parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) + ~4.3333 + + // Using offset parameter: + > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; + > {{alias}}.ndarray( 3, 1, x, 2, 1 ) + ~4.3333 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/variancech/docs/types/index.d.ts new file mode 100644 index 000000000000..749ed66d2ca5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/docs/types/index.d.ts @@ -0,0 +1,96 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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 + +/// + +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `variancech`. +*/ +interface Routine { + /** + * Computes the variance of a strided array using a one-pass trial mean algorithm. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @returns variance + * + * @example + * var x = [ 1.0, -2.0, 2.0 ]; + * + * var v = variancech( x.length, 1, x, 1 ); + * // returns ~4.3333 + */ + ( N: number, correction: number, x: InputArray, strideX: number ): number; + + /** + * Computes the variance of a strided array using a one-pass trial mean algorithm and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns variance + * + * @example + * var x = [ 1.0, -2.0, 2.0 ]; + * + * var v = variancech.ndarray( x.length, 1, x, 1, 0 ); + * // returns ~4.3333 + */ + ndarray( N: number, correction: number, x: InputArray, strideX: number, offsetX: number ): number; +} + +/** +* Computes the variance of a strided array using a one-pass trial mean algorithm. +* +* @param N - number of indexed elements +* @param correction - degrees of freedom adjustment +* @param x - input array +* @param strideX - stride length +* @returns variance +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancech( x.length, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancech.ndarray( x.length, 1, x, 1, 0 ); +* // returns ~4.3333 +*/ +declare var variancech: Routine; + + +// EXPORTS // + +export = variancech; diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/variancech/docs/types/test.ts new file mode 100644 index 000000000000..7c9a437186d3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/docs/types/test.ts @@ -0,0 +1,190 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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 AccessorArray = require( '@stdlib/array/base/accessor' ); +import variancech = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Float64Array( 10 ); + + variancech( x.length, 1, x, 1 ); // $ExpectType number + variancech( x.length, 1, new AccessorArray( x ), 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancech( '10', 1, x, 1 ); // $ExpectError + variancech( true, 1, x, 1 ); // $ExpectError + variancech( false, 1, x, 1 ); // $ExpectError + variancech( null, 1, x, 1 ); // $ExpectError + variancech( undefined, 1, x, 1 ); // $ExpectError + variancech( [], 1, x, 1 ); // $ExpectError + variancech( {}, 1, x, 1 ); // $ExpectError + variancech( ( x: number ): number => x, 1, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancech( x.length, '10', x, 1 ); // $ExpectError + variancech( x.length, true, x, 1 ); // $ExpectError + variancech( x.length, false, x, 1 ); // $ExpectError + variancech( x.length, null, x, 1 ); // $ExpectError + variancech( x.length, undefined, x, 1 ); // $ExpectError + variancech( x.length, [], x, 1 ); // $ExpectError + variancech( x.length, {}, x, 1 ); // $ExpectError + variancech( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + variancech( x.length, 1, 10, 1 ); // $ExpectError + variancech( x.length, 1, '10', 1 ); // $ExpectError + variancech( x.length, 1, true, 1 ); // $ExpectError + variancech( x.length, 1, false, 1 ); // $ExpectError + variancech( x.length, 1, null, 1 ); // $ExpectError + variancech( x.length, 1, undefined, 1 ); // $ExpectError + variancech( x.length, 1, [ '1' ], 1 ); // $ExpectError + variancech( x.length, 1, {}, 1 ); // $ExpectError + variancech( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancech( x.length, 1, x, '10' ); // $ExpectError + variancech( x.length, 1, x, true ); // $ExpectError + variancech( x.length, 1, x, false ); // $ExpectError + variancech( x.length, 1, x, null ); // $ExpectError + variancech( x.length, 1, x, undefined ); // $ExpectError + variancech( x.length, 1, x, [] ); // $ExpectError + variancech( x.length, 1, x, {} ); // $ExpectError + variancech( x.length, 1, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + variancech(); // $ExpectError + variancech( x.length ); // $ExpectError + variancech( x.length, 1 ); // $ExpectError + variancech( x.length, 1, x ); // $ExpectError + variancech( x.length, 1, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + + variancech.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number + variancech.ndarray( x.length, 1, new AccessorArray( x ), 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancech.ndarray( '10', 1, x, 1, 0 ); // $ExpectError + variancech.ndarray( true, 1, x, 1, 0 ); // $ExpectError + variancech.ndarray( false, 1, x, 1, 0 ); // $ExpectError + variancech.ndarray( null, 1, x, 1, 0 ); // $ExpectError + variancech.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError + variancech.ndarray( [], 1, x, 1, 0 ); // $ExpectError + variancech.ndarray( {}, 1, x, 1, 0 ); // $ExpectError + variancech.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancech.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError + variancech.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + variancech.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + variancech.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + variancech.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + variancech.ndarray( x.length, [], x, 1, 0 ); // $ExpectError + variancech.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + variancech.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + variancech.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError + variancech.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError + variancech.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError + variancech.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError + variancech.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError + variancech.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError + variancech.ndarray( x.length, 1, [ '1' ], 1, 0 ); // $ExpectError + variancech.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError + variancech.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancech.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError + variancech.ndarray( x.length, 1, x, true, 0 ); // $ExpectError + variancech.ndarray( x.length, 1, x, false, 0 ); // $ExpectError + variancech.ndarray( x.length, 1, x, null, 0 ); // $ExpectError + variancech.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError + variancech.ndarray( x.length, 1, x, [], 0 ); // $ExpectError + variancech.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError + variancech.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variancech.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError + variancech.ndarray( x.length, 1, x, 1, true ); // $ExpectError + variancech.ndarray( x.length, 1, x, 1, false ); // $ExpectError + variancech.ndarray( x.length, 1, x, 1, null ); // $ExpectError + variancech.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError + variancech.ndarray( x.length, 1, x, 1, [] ); // $ExpectError + variancech.ndarray( x.length, 1, x, 1, {} ); // $ExpectError + variancech.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + variancech.ndarray(); // $ExpectError + variancech.ndarray( x.length ); // $ExpectError + variancech.ndarray( x.length, 1 ); // $ExpectError + variancech.ndarray( x.length, 1, x ); // $ExpectError + variancech.ndarray( x.length, 1, x, 1 ); // $ExpectError + variancech.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/examples/index.js b/lib/node_modules/@stdlib/stats/strided/variancech/examples/index.js new file mode 100644 index 000000000000..adaae05a5d6d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/examples/index.js @@ -0,0 +1,30 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var variancech = require( './../lib' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +console.log( x ); + +var v = variancech( x.length, 1, x, 1 ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/lib/accessors.js b/lib/node_modules/@stdlib/stats/strided/variancech/lib/accessors.js new file mode 100644 index 000000000000..149ba4659feb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/lib/accessors.js @@ -0,0 +1,95 @@ +/** +* @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'; + +// MAIN // + +/** +* Computes the variance of a strided array using a one-pass trial mean algorithm. +* +* ## Method +* +* - This implementation uses a one-pass trial mean approach, as suggested by Chan et al (1983). +* +* ## References +* +* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). +* - Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154](https://doi.org/10.2307/2286154). +* - Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. 1983. "Algorithms for Computing the Sample Variance: Analysis and Recommendations." _The American Statistician_ 37 (3). American Statistical Association, Taylor & Francis, Ltd.: 242–47. doi:[10.1080/00031305.1983.10483115](https://doi.org/10.1080/00031305.1983.10483115). +* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} variance +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +* +* var v = variancech( 4, 1, arraylike2object( x ), 2, 1 ); +* // returns 6.25 +*/ +function variancech( N, correction, x, strideX, offsetX ) { + var xbuf; + var get; + var mu; + var ix; + var M2; + var M; + var d; + var n; + var i; + + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessor: + get = x.accessors[ 0 ]; + + n = N - correction; + ix = offsetX; + + // Use an estimate for the mean: + mu = get( xbuf, ix ); + ix += strideX; + + // Compute the variance... + M2 = 0.0; + M = 0.0; + for ( i = 1; i < N; i++ ) { + d = get( xbuf, ix ) - mu; + M2 += d * d; + M += d; + ix += strideX; + } + return (M2/n) - ((M/N)*(M/n)); +} + + +// EXPORTS // + +module.exports = variancech; diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/lib/index.js b/lib/node_modules/@stdlib/stats/strided/variancech/lib/index.js new file mode 100644 index 000000000000..55485c1e8dd8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/lib/index.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 the variance of a strided array using a one-pass trial mean algorithm. +* +* @module @stdlib/stats/strided/variancech +* +* @example +* var variancech = require( '@stdlib/stats/strided/variancech' ); +* +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancech( x.length, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var variancech = require( '@stdlib/stats/strided/variancech' ); +* +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = variancech.ndarray( 4, 1, x, 2, 1 ); +* // returns 6.25 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/lib/main.js b/lib/node_modules/@stdlib/stats/strided/variancech/lib/main.js new file mode 100644 index 000000000000..8a2fd7a5a1ad --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var variancech = require( './variancech.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( variancech, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = variancech; diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/variancech/lib/ndarray.js new file mode 100644 index 000000000000..1c04ab725cd3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/lib/ndarray.js @@ -0,0 +1,98 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Computes the variance of a strided array using a one-pass trial mean algorithm. +* +* ## Method +* +* - This implementation uses a one-pass trial mean approach, as suggested by Chan et al (1983). +* +* ## References +* +* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). +* - Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154](https://doi.org/10.2307/2286154). +* - Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. 1983. "Algorithms for Computing the Sample Variance: Analysis and Recommendations." _The American Statistician_ 37 (3). American Statistical Association, Taylor & Francis, Ltd.: 242–47. doi:[10.1080/00031305.1983.10483115](https://doi.org/10.1080/00031305.1983.10483115). +* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} variance +* +* @example +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = variancech( 4, 1, x, 2, 1 ); +* // returns 6.25 +*/ +function variancech( N, correction, x, strideX, offsetX ) { + var mu; + var ix; + var M2; + var M; + var d; + var n; + var o; + var i; + + n = N - correction; + if ( N <= 0 || n <= 0.0 ) { + return NaN; + } + if ( N === 1 || strideX === 0 ) { + return 0.0; + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, correction, o, strideX, offsetX ); + } + ix = offsetX; + + // Use an estimate for the mean: + mu = x[ ix ]; + ix += strideX; + + // Compute the variance... + M2 = 0.0; + M = 0.0; + for ( i = 1; i < N; i++ ) { + d = x[ ix ] - mu; + M2 += d * d; + M += d; + ix += strideX; + } + return (M2/n) - ((M/N)*(M/n)); +} + + +// EXPORTS // + +module.exports = variancech; diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/lib/variancech.js b/lib/node_modules/@stdlib/stats/strided/variancech/lib/variancech.js new file mode 100644 index 000000000000..d6ef6233ab47 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/lib/variancech.js @@ -0,0 +1,62 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes the variance of a strided array using a one-pass trial mean algorithm. +* +* ## Method +* +* - This implementation uses a one-pass trial mean approach, as suggested by Chan et al (1983). +* +* ## References +* +* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). +* - Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154](https://doi.org/10.2307/2286154). +* - Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. 1983. "Algorithms for Computing the Sample Variance: Analysis and Recommendations." _The American Statistician_ 37 (3). American Statistical Association, Taylor & Francis, Ltd.: 242–47. doi:[10.1080/00031305.1983.10483115](https://doi.org/10.1080/00031305.1983.10483115). +* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @returns {number} variance +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancech( x.length, 1, x, 1 ); +* // returns ~4.3333 +*/ +function variancech( N, correction, x, strideX ) { + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = variancech; diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/package.json b/lib/node_modules/@stdlib/stats/strided/variancech/package.json new file mode 100644 index 000000000000..32fb8d768bc3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/stats/strided/variancech", + "version": "0.0.0", + "description": "Calculate the variance of a strided array using a one-pass trial mean algorithm.", + "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", + "var", + "deviation", + "dispersion", + "sample variance", + "unbiased", + "stdev", + "std", + "standard deviation", + "strided", + "strided array", + "typed", + "array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/test/test.js b/lib/node_modules/@stdlib/stats/strided/variancech/test/test.js new file mode 100644 index 000000000000..aec1f7916119 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 variancech = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variancech, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof variancech.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/variancech/test/test.ndarray.js new file mode 100644 index 000000000000..c1327184ccfb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/test/test.ndarray.js @@ -0,0 +1,350 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var variancech = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variancech, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( variancech.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancech( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancech( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancech( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancech( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancech( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancech( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancech( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancech( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancech( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancech( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancech( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancech( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( 0, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancech( -1, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( 0, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancech( -1, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( 1, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( 1, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancech( x.length, x.length+1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( x.length, x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancech( x.length, x.length+1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancech( 4, 1, x, 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancech( 4, 1, toAccessorArray( x ), 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancech( 4, 1, x, -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancech( 4, 1, toAccessorArray( x ), -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( x.length, 1, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( x.length, 1, toAccessorArray( x ), 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + + v = variancech( 4, 1, x, 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + + v = variancech( 4, 1, toAccessorArray( x ), 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/test/test.variancech.js b/lib/node_modules/@stdlib/stats/strided/variancech/test/test.variancech.js new file mode 100644 index 000000000000..83fc264cbc23 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variancech/test/test.variancech.js @@ -0,0 +1,358 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var variancech = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variancech, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( variancech.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancech( x.length, 0, x, 1 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancech( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancech( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancech( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancech( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancech( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancech( x.length, 1, x, 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancech( x.length, 1, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancech( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancech( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancech( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancech( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( 0, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancech( -1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( 0, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancech( -1, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( 1, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancech( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( x.length, x.length, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancech( x.length, x.length+1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancech( 4, 1, x, 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variancech( 4, 1, toAccessorArray( x ), 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancech( 4, 1, x, -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variancech( 4, 1, toAccessorArray( x ), -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancech( x.length, 1, toAccessorArray( x ), 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = variancech( 4, 1, x1, 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets (accessors)', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = variancech( 4, 1, toAccessorArray( x1 ), 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); From 0e2d1cd7814c85b64c4307363de4fcc65e50c339 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:26:07 +0000 Subject: [PATCH 23/32] remove: remove `variancech` from namespace This commit removes the `variancech` symbol from the `@stdlib/stats/base` namespace due to a package migration. BREAKING CHANGE: remove `variancech` To migrate, users should access the same symbol via the `@stdlib/stats/strided` namespace. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/docs/types/index.d.ts | 24 ------------------- .../@stdlib/stats/base/lib/index.js | 9 ------- 2 files changed, 33 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts index 915d1fa6fb2d..4942d136ffb9 100644 --- a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts @@ -67,7 +67,6 @@ import stdevtk = require( '@stdlib/stats/base/stdevtk' ); import stdevwd = require( '@stdlib/stats/base/stdevwd' ); import stdevyc = require( '@stdlib/stats/base/stdevyc' ); import variance = require( '@stdlib/stats/base/variance' ); -import variancech = require( '@stdlib/stats/base/variancech' ); import dmeankbn2 = require( '@stdlib/stats/strided/dmeankbn2' ); import dmeanli = require( '@stdlib/stats/strided/dmeanli' ); import dmeanlipw = require( '@stdlib/stats/strided/dmeanlipw' ); @@ -1273,29 +1272,6 @@ interface Namespace { */ variance: typeof variance; - /** - * Computes the variance of a strided array using a one-pass trial mean algorithm. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param stride - stride length - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = ns.variancech( x.length, 1, x, 1 ); - * // returns ~4.3333 - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = ns.variancech.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - variancech: typeof variancech; - /** * Computes the arithmetic mean of a double-precision floating-point strided array using a second-order iterative Kahan–Babuška algorithm. * diff --git a/lib/node_modules/@stdlib/stats/base/lib/index.js b/lib/node_modules/@stdlib/stats/base/lib/index.js index c97b4c4ac4dd..207b1be7094b 100644 --- a/lib/node_modules/@stdlib/stats/base/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/lib/index.js @@ -468,15 +468,6 @@ setReadOnly( ns, 'stdevyc', require( '@stdlib/stats/base/stdevyc' ) ); */ setReadOnly( ns, 'variance', require( '@stdlib/stats/base/variance' ) ); -/** -* @name variancech -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/stats/base/variancech} -*/ -setReadOnly( ns, 'variancech', require( '@stdlib/stats/base/variancech' ) ); - /** * @name dmeankbn2 * @memberof ns From 0ddde834e00e55c588e91d04f49e89e6ae6839c3 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:27:25 +0000 Subject: [PATCH 24/32] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/namespace/lib/namespace/base/strided/d.js | 2 +- .../@stdlib/namespace/lib/namespace/base/strided/n.js | 2 +- .../@stdlib/namespace/lib/namespace/base/strided/s.js | 4 ++-- .../@stdlib/namespace/lib/namespace/base/strided/v.js | 4 ++-- lib/node_modules/@stdlib/stats/array/variancech/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/base/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/nanvariancech/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/stdevch/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/stdevch/lib/ndarray.js | 2 +- lib/node_modules/@stdlib/stats/base/stdevch/lib/stdevch.js | 2 +- lib/node_modules/@stdlib/stats/strided/dvariancech/README.md | 4 ++-- lib/node_modules/@stdlib/stats/strided/svariancech/README.md | 4 ++-- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js index 587ab5aaee50..5074b08cb7e8 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js @@ -2267,7 +2267,7 @@ ns.push({ '@stdlib/stats/strided/dstdevch', '@stdlib/stats/strided/dvariance', '@stdlib/stats/strided/svariancech', - '@stdlib/stats/base/variancech' + '@stdlib/stats/strided/variancech' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js index 5d9f7186789e..1c8d697396b6 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js @@ -340,7 +340,7 @@ ns.push({ '@stdlib/stats/base/nanstdevch', '@stdlib/stats/base/nanvariance', '@stdlib/stats/base/snanvariancech', - '@stdlib/stats/base/variancech' + '@stdlib/stats/strided/variancech' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js index eb5a459de1e8..f23bc54fe95e 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js @@ -1811,7 +1811,7 @@ ns.push({ '@stdlib/stats/base/nanstdevch', '@stdlib/stats/strided/sstdevch', '@stdlib/stats/base/stdev', - '@stdlib/stats/base/variancech' + '@stdlib/stats/strided/variancech' ] }); @@ -1914,7 +1914,7 @@ ns.push({ '@stdlib/stats/base/snanvariancech', '@stdlib/stats/strided/sstdevch', '@stdlib/stats/strided/svariance', - '@stdlib/stats/base/variancech' + '@stdlib/stats/strided/variancech' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js index f89c591a3ef1..da84e1ec2847 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js @@ -42,8 +42,8 @@ ns.push({ ns.push({ 'alias': 'base.strided.variancech', - 'path': '@stdlib/stats/base/variancech', - 'value': require( '@stdlib/stats/base/variancech' ), + 'path': '@stdlib/stats/strided/variancech', + 'value': require( '@stdlib/stats/strided/variancech' ), 'type': 'Function', 'related': [ '@stdlib/stats/strided/dvariancech', diff --git a/lib/node_modules/@stdlib/stats/array/variancech/lib/main.js b/lib/node_modules/@stdlib/stats/array/variancech/lib/main.js index 923ed7c3a286..e227ed3488ed 100644 --- a/lib/node_modules/@stdlib/stats/array/variancech/lib/main.js +++ b/lib/node_modules/@stdlib/stats/array/variancech/lib/main.js @@ -26,7 +26,7 @@ var dtypes = require( '@stdlib/array/dtypes' ); var dtype = require( '@stdlib/array/dtype' ); var contains = require( '@stdlib/array/base/assert/contains' ); var join = require( '@stdlib/array/base/join' ); -var strided = require( '@stdlib/stats/base/variancech' ).ndarray; +var strided = require( '@stdlib/stats/strided/variancech' ).ndarray; var format = require( '@stdlib/string/format' ); diff --git a/lib/node_modules/@stdlib/stats/base/README.md b/lib/node_modules/@stdlib/stats/base/README.md index 70e8e07216e9..63f672048f9f 100644 --- a/lib/node_modules/@stdlib/stats/base/README.md +++ b/lib/node_modules/@stdlib/stats/base/README.md @@ -108,7 +108,7 @@ The namespace contains the following statistical functions: - [`stdevwd( N, correction, x, stride )`][@stdlib/stats/base/stdevwd]: calculate the standard deviation of a strided array using Welford's algorithm. - [`stdevyc( N, correction, x, stride )`][@stdlib/stats/base/stdevyc]: calculate the standard deviation of a strided array using a one-pass algorithm proposed by Youngs and Cramer. - [`variance( N, correction, x, strideX )`][@stdlib/stats/base/variance]: calculate the variance of a strided array. -- [`variancech( N, correction, x, strideX )`][@stdlib/stats/base/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. +- [`variancech( N, correction, x, strideX )`][@stdlib/stats/strided/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. - [`variancepn( N, correction, x, strideX )`][@stdlib/stats/strided/variancepn]: calculate the variance of a strided array using a two-pass algorithm. - [`variancetk( N, correction, x, strideX )`][@stdlib/stats/strided/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. - [`variancewd( N, correction, x, stride )`][@stdlib/stats/strided/variancewd]: calculate the variance of a strided array using Welford's algorithm. @@ -265,7 +265,7 @@ console.log( objectKeys( ns ) ); [@stdlib/stats/base/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variance -[@stdlib/stats/base/variancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancech +[@stdlib/stats/strided/variancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancech [@stdlib/stats/strided/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancepn diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancech/README.md b/lib/node_modules/@stdlib/stats/base/nanvariancech/README.md index 59f915f9f341..fdb6ece5c363 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancech/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanvariancech/README.md @@ -238,7 +238,7 @@ console.log( v ); - [`@stdlib/stats/base/nanstdevch`][@stdlib/stats/base/nanstdevch]: calculate the standard deviation of a strided array ignoring NaN values and using a one-pass trial mean algorithm. - [`@stdlib/stats/base/nanvariance`][@stdlib/stats/base/nanvariance]: calculate the variance of a strided array ignoring NaN values. - [`@stdlib/stats/base/snanvariancech`][@stdlib/stats/base/snanvariancech]: calculate the variance of a single-precision floating-point strided array ignoring NaN values and using a one-pass trial mean algorithm. -- [`@stdlib/stats/base/variancech`][@stdlib/stats/base/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. +- [`@stdlib/stats/strided/variancech`][@stdlib/stats/strided/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. @@ -274,7 +274,7 @@ console.log( v ); [@stdlib/stats/base/snanvariancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/snanvariancech -[@stdlib/stats/base/variancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancech +[@stdlib/stats/strided/variancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancech diff --git a/lib/node_modules/@stdlib/stats/base/stdevch/README.md b/lib/node_modules/@stdlib/stats/base/stdevch/README.md index 57113cbfc354..a97f21dcec91 100644 --- a/lib/node_modules/@stdlib/stats/base/stdevch/README.md +++ b/lib/node_modules/@stdlib/stats/base/stdevch/README.md @@ -231,7 +231,7 @@ console.log( v ); - [`@stdlib/stats/base/nanstdevch`][@stdlib/stats/base/nanstdevch]: calculate the standard deviation of a strided array ignoring NaN values and using a one-pass trial mean algorithm. - [`@stdlib/stats/strided/sstdevch`][@stdlib/stats/strided/sstdevch]: calculate the standard deviation of a single-precision floating-point strided array using a one-pass trial mean algorithm. - [`@stdlib/stats/base/stdev`][@stdlib/stats/base/stdev]: calculate the standard deviation of a strided array. -- [`@stdlib/stats/base/variancech`][@stdlib/stats/base/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. +- [`@stdlib/stats/strided/variancech`][@stdlib/stats/strided/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. @@ -267,7 +267,7 @@ console.log( v ); [@stdlib/stats/base/stdev]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/stdev -[@stdlib/stats/base/variancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancech +[@stdlib/stats/strided/variancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancech diff --git a/lib/node_modules/@stdlib/stats/base/stdevch/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/stdevch/lib/ndarray.js index 96cf74336a45..10cac4e97819 100644 --- a/lib/node_modules/@stdlib/stats/base/stdevch/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/stdevch/lib/ndarray.js @@ -20,7 +20,7 @@ // MODULES // -var variancech = require( '@stdlib/stats/base/variancech' ).ndarray; +var variancech = require( '@stdlib/stats/strided/variancech' ).ndarray; var sqrt = require( '@stdlib/math/base/special/sqrt' ); diff --git a/lib/node_modules/@stdlib/stats/base/stdevch/lib/stdevch.js b/lib/node_modules/@stdlib/stats/base/stdevch/lib/stdevch.js index 3d2860e89567..a4f93eb958df 100644 --- a/lib/node_modules/@stdlib/stats/base/stdevch/lib/stdevch.js +++ b/lib/node_modules/@stdlib/stats/base/stdevch/lib/stdevch.js @@ -20,7 +20,7 @@ // MODULES // -var variancech = require( '@stdlib/stats/base/variancech' ); +var variancech = require( '@stdlib/stats/strided/variancech' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); diff --git a/lib/node_modules/@stdlib/stats/strided/dvariancech/README.md b/lib/node_modules/@stdlib/stats/strided/dvariancech/README.md index 3804f58a9add..0746562cd0d1 100644 --- a/lib/node_modules/@stdlib/stats/strided/dvariancech/README.md +++ b/lib/node_modules/@stdlib/stats/strided/dvariancech/README.md @@ -356,7 +356,7 @@ int main( void ) { - [`@stdlib/stats/strided/dstdevch`][@stdlib/stats/strided/dstdevch]: calculate the standard deviation of a double-precision floating-point strided array using a one-pass trial mean algorithm. - [`@stdlib/stats/strided/dvariance`][@stdlib/stats/strided/dvariance]: calculate the variance of a double-precision floating-point strided array. - [`@stdlib/stats/strided/svariancech`][@stdlib/stats/strided/svariancech]: calculate the variance of a single-precision floating-point strided array using a one-pass trial mean algorithm. -- [`@stdlib/stats/base/variancech`][@stdlib/stats/base/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. +- [`@stdlib/stats/strided/variancech`][@stdlib/stats/strided/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. @@ -390,7 +390,7 @@ int main( void ) { [@stdlib/stats/strided/svariancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancech -[@stdlib/stats/base/variancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancech +[@stdlib/stats/strided/variancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancech diff --git a/lib/node_modules/@stdlib/stats/strided/svariancech/README.md b/lib/node_modules/@stdlib/stats/strided/svariancech/README.md index d87bbc4708ed..e298b3dc1098 100644 --- a/lib/node_modules/@stdlib/stats/strided/svariancech/README.md +++ b/lib/node_modules/@stdlib/stats/strided/svariancech/README.md @@ -356,7 +356,7 @@ int main( void ) { - [`@stdlib/stats/base/snanvariancech`][@stdlib/stats/base/snanvariancech]: calculate the variance of a single-precision floating-point strided array ignoring NaN values and using a one-pass trial mean algorithm. - [`@stdlib/stats/strided/sstdevch`][@stdlib/stats/strided/sstdevch]: calculate the standard deviation of a single-precision floating-point strided array using a one-pass trial mean algorithm. - [`@stdlib/stats/strided/svariance`][@stdlib/stats/strided/svariance]: calculate the variance of a single-precision floating-point strided array. -- [`@stdlib/stats/base/variancech`][@stdlib/stats/base/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. +- [`@stdlib/stats/strided/variancech`][@stdlib/stats/strided/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. @@ -390,7 +390,7 @@ int main( void ) { [@stdlib/stats/strided/svariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariance -[@stdlib/stats/base/variancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancech +[@stdlib/stats/strided/variancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancech From 9269948a63af3fe89a07080ddcc2a722e7ea5b33 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:29:28 +0000 Subject: [PATCH 25/32] remove: remove `stats/base/variancech` This commit removes `@stdlib/stats/base/variancech` in favor of `@stdlib/stats/strided/variancech`. BREAKING CHANGE: remove `stats/base/variancech` To migrate, users should update their require/import paths to use `@stdlib/stats/strided/variancech`, which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/variancech/README.md | 275 -------------- .../base/variancech/benchmark/benchmark.js | 96 ----- .../variancech/benchmark/benchmark.ndarray.js | 96 ----- .../docs/img/equation_population_mean.svg | 42 -- .../docs/img/equation_population_variance.svg | 54 --- .../docs/img/equation_sample_mean.svg | 43 --- .../img/equation_unbiased_sample_variance.svg | 61 --- .../stats/base/variancech/docs/repl.txt | 114 ------ .../base/variancech/docs/types/index.d.ts | 96 ----- .../stats/base/variancech/docs/types/test.ts | 190 ---------- .../stats/base/variancech/examples/index.js | 30 -- .../stats/base/variancech/lib/accessors.js | 95 ----- .../stats/base/variancech/lib/index.js | 52 --- .../@stdlib/stats/base/variancech/lib/main.js | 35 -- .../stats/base/variancech/lib/ndarray.js | 98 ----- .../stats/base/variancech/lib/variancech.js | 62 --- .../stats/base/variancech/package.json | 73 ---- .../stats/base/variancech/test/test.js | 38 -- .../base/variancech/test/test.ndarray.js | 350 ----------------- .../base/variancech/test/test.variancech.js | 358 ------------------ 20 files changed, 2258 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/README.md delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/benchmark/benchmark.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_population_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_population_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_sample_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_unbiased_sample_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/examples/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/lib/accessors.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/lib/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/lib/main.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/lib/ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/lib/variancech.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/package.json delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/test/test.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/test/test.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variancech/test/test.variancech.js diff --git a/lib/node_modules/@stdlib/stats/base/variancech/README.md b/lib/node_modules/@stdlib/stats/base/variancech/README.md deleted file mode 100644 index a4875152ee2e..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/README.md +++ /dev/null @@ -1,275 +0,0 @@ - - -# variancech - -> Calculate the [variance][variance] of a strided array using a one-pass trial mean algorithm. - -
- -The population [variance][variance] of a finite size population of size `N` is given by - - - -```math -\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 -``` - - - - - -where the population mean is given by - - - -```math -\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i -``` - - - - - -Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, - - - -```math -s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 -``` - - - - - -where the sample mean is given by - - - -```math -\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i -``` - - - - - -The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. - -
- - - -
- -## Usage - -```javascript -var variancech = require( '@stdlib/stats/base/variancech' ); -``` - -#### variancech( N, correction, x, strideX ) - -Computes the [variance][variance] of a strided array using a one-pass trial mean algorithm. - -```javascript -var x = [ 1.0, -2.0, 2.0 ]; - -var v = variancech( x.length, 1, x, 1 ); -// returns ~4.3333 -``` - -The function has the following parameters: - -- **N**: number of indexed elements. -- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. -- **strideX**: stride length for `x`. - -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, - -```javascript -var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; - -var v = variancech( 4, 1, x, 2 ); -// returns 6.25 -``` - -Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); - -var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - -var v = variancech( 4, 1, x1, 2 ); -// returns 6.25 -``` - -#### variancech.ndarray( N, correction, x, strideX, offsetX ) - -Computes the [variance][variance] of a strided array using a one-pass trial mean algorithm and alternative indexing semantics. - -```javascript -var x = [ 1.0, -2.0, 2.0 ]; - -var v = variancech.ndarray( x.length, 1, x, 1, 0 ); -// returns ~4.33333 -``` - -The function has the following additional parameters: - -- **offsetX**: starting index for `x`. - -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element - -```javascript -var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; - -var v = variancech.ndarray( 4, 1, x, 2, 1 ); -// returns 6.25 -``` - -
- - - -
- -## Notes - -- If `N <= 0`, both functions return `NaN`. -- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. -- The underlying algorithm is a specialized case of Neely's two-pass algorithm. As the variance is invariant with respect to changes in the location parameter, the underlying algorithm uses the first strided array element as a trial mean to shift subsequent data values and thus mitigate catastrophic cancellation. Accordingly, the algorithm's accuracy is best when data is **unordered** (i.e., the data is **not** sorted in either ascending or descending order such that the first value is an "extreme" value). -- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). -- Depending on the environment, the typed versions ([`dvariancech`][@stdlib/stats/strided/dvariancech], [`svariancech`][@stdlib/stats/strided/svariancech], etc.) are likely to be significantly more performant. - -
- - - -
- -## Examples - - - -```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var variancech = require( '@stdlib/stats/base/variancech' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); -console.log( x ); - -var v = variancech( x.length, 1, x, 1 ); -console.log( v ); -``` - -
- - - -* * * - -
- -## References - -- Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958][@neely:1966a]. -- Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154][@ling:1974a]. -- Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. 1983. "Algorithms for Computing the Sample Variance: Analysis and Recommendations." _The American Statistician_ 37 (3). American Statistical Association, Taylor & Francis, Ltd.: 242–47. doi:[10.1080/00031305.1983.10483115][@chan:1983a]. -- Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036][@schubert:2018a]. - -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/stats/base/variancech/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/variancech/benchmark/benchmark.js deleted file mode 100644 index ac477d0789d7..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/benchmark/benchmark.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var variancech = require( './../lib/main.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = variancech( x.length, 1, x, 1 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/variancech/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/variancech/benchmark/benchmark.ndarray.js deleted file mode 100644 index b273ff4a8d68..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var variancech = require( './../lib/ndarray.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = variancech( x.length, 1, x, 1, 0 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':ndarray:len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_population_mean.svg deleted file mode 100644 index 4bbdf0d2a56f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_population_mean.svg +++ /dev/null @@ -1,42 +0,0 @@ - -mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_population_variance.svg deleted file mode 100644 index 4130ba0750d2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_population_variance.svg +++ /dev/null @@ -1,54 +0,0 @@ - -sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_sample_mean.svg deleted file mode 100644 index aea7a5f6687a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_sample_mean.svg +++ /dev/null @@ -1,43 +0,0 @@ - -x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_unbiased_sample_variance.svg deleted file mode 100644 index 1ae1283e7fb1..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/docs/img/equation_unbiased_sample_variance.svg +++ /dev/null @@ -1,61 +0,0 @@ - -s squared equals 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 - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variancech/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/variancech/docs/repl.txt deleted file mode 100644 index 929365feac6b..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/docs/repl.txt +++ /dev/null @@ -1,114 +0,0 @@ - -{{alias}}( N, correction, x, strideX ) - Computes the variance of a strided array using a one-pass trial mean - algorithm. - - The `N` and stride parameters determine which elements in the strided array - are accessed at runtime. - - Indexing is relative to the first index. To introduce an offset, use a typed - array view. - - If `N <= 0`, the function returns `NaN`. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Array|TypedArray - Input array. - - strideX: integer - Stride length. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = [ 1.0, -2.0, 2.0 ]; - > {{alias}}( x.length, 1, x, 1 ) - ~4.3333 - - // Using `N` and stride parameters: - > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; - > {{alias}}( 3, 1, x, 2 ) - ~4.3333 - - // Using view offsets: - > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 1, x1, 2 ) - ~4.3333 - - -{{alias}}.ndarray( N, correction, x, strideX, offsetX ) - Computes the variance of a strided array using a one-pass trial mean - algorithm and alternative indexing semantics. - - While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a - starting index. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Array|TypedArray - Input array. - - strideX: integer - Stride length. - - offsetX: integer - Starting index. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = [ 1.0, -2.0, 2.0 ]; - > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) - ~4.3333 - - // Using offset parameter: - > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; - > {{alias}}.ndarray( 3, 1, x, 2, 1 ) - ~4.3333 - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/stats/base/variancech/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/variancech/docs/types/index.d.ts deleted file mode 100644 index 749ed66d2ca5..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/docs/types/index.d.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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 - -/// - -import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; - -/** -* Input array. -*/ -type InputArray = NumericArray | Collection | AccessorArrayLike; - -/** -* Interface describing `variancech`. -*/ -interface Routine { - /** - * Computes the variance of a strided array using a one-pass trial mean algorithm. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = variancech( x.length, 1, x, 1 ); - * // returns ~4.3333 - */ - ( N: number, correction: number, x: InputArray, strideX: number ): number; - - /** - * Computes the variance of a strided array using a one-pass trial mean algorithm and alternative indexing semantics. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @param offsetX - starting index - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = variancech.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - ndarray( N: number, correction: number, x: InputArray, strideX: number, offsetX: number ): number; -} - -/** -* Computes the variance of a strided array using a one-pass trial mean algorithm. -* -* @param N - number of indexed elements -* @param correction - degrees of freedom adjustment -* @param x - input array -* @param strideX - stride length -* @returns variance -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancech( x.length, 1, x, 1 ); -* // returns ~4.3333 -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancech.ndarray( x.length, 1, x, 1, 0 ); -* // returns ~4.3333 -*/ -declare var variancech: Routine; - - -// EXPORTS // - -export = variancech; diff --git a/lib/node_modules/@stdlib/stats/base/variancech/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/variancech/docs/types/test.ts deleted file mode 100644 index 7c9a437186d3..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/docs/types/test.ts +++ /dev/null @@ -1,190 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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 AccessorArray = require( '@stdlib/array/base/accessor' ); -import variancech = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const x = new Float64Array( 10 ); - - variancech( x.length, 1, x, 1 ); // $ExpectType number - variancech( x.length, 1, new AccessorArray( x ), 1 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancech( '10', 1, x, 1 ); // $ExpectError - variancech( true, 1, x, 1 ); // $ExpectError - variancech( false, 1, x, 1 ); // $ExpectError - variancech( null, 1, x, 1 ); // $ExpectError - variancech( undefined, 1, x, 1 ); // $ExpectError - variancech( [], 1, x, 1 ); // $ExpectError - variancech( {}, 1, x, 1 ); // $ExpectError - variancech( ( x: number ): number => x, 1, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancech( x.length, '10', x, 1 ); // $ExpectError - variancech( x.length, true, x, 1 ); // $ExpectError - variancech( x.length, false, x, 1 ); // $ExpectError - variancech( x.length, null, x, 1 ); // $ExpectError - variancech( x.length, undefined, x, 1 ); // $ExpectError - variancech( x.length, [], x, 1 ); // $ExpectError - variancech( x.length, {}, x, 1 ); // $ExpectError - variancech( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a numeric array... -{ - const x = new Float64Array( 10 ); - - variancech( x.length, 1, 10, 1 ); // $ExpectError - variancech( x.length, 1, '10', 1 ); // $ExpectError - variancech( x.length, 1, true, 1 ); // $ExpectError - variancech( x.length, 1, false, 1 ); // $ExpectError - variancech( x.length, 1, null, 1 ); // $ExpectError - variancech( x.length, 1, undefined, 1 ); // $ExpectError - variancech( x.length, 1, [ '1' ], 1 ); // $ExpectError - variancech( x.length, 1, {}, 1 ); // $ExpectError - variancech( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancech( x.length, 1, x, '10' ); // $ExpectError - variancech( x.length, 1, x, true ); // $ExpectError - variancech( x.length, 1, x, false ); // $ExpectError - variancech( x.length, 1, x, null ); // $ExpectError - variancech( x.length, 1, x, undefined ); // $ExpectError - variancech( x.length, 1, x, [] ); // $ExpectError - variancech( x.length, 1, x, {} ); // $ExpectError - variancech( x.length, 1, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - - variancech(); // $ExpectError - variancech( x.length ); // $ExpectError - variancech( x.length, 1 ); // $ExpectError - variancech( x.length, 1, x ); // $ExpectError - variancech( x.length, 1, x, 1, 10 ); // $ExpectError -} - -// Attached to main export is an `ndarray` method which returns a number... -{ - const x = new Float64Array( 10 ); - - variancech.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number - variancech.ndarray( x.length, 1, new AccessorArray( x ), 1, 0 ); // $ExpectType number -} - -// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancech.ndarray( '10', 1, x, 1, 0 ); // $ExpectError - variancech.ndarray( true, 1, x, 1, 0 ); // $ExpectError - variancech.ndarray( false, 1, x, 1, 0 ); // $ExpectError - variancech.ndarray( null, 1, x, 1, 0 ); // $ExpectError - variancech.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError - variancech.ndarray( [], 1, x, 1, 0 ); // $ExpectError - variancech.ndarray( {}, 1, x, 1, 0 ); // $ExpectError - variancech.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancech.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError - variancech.ndarray( x.length, true, x, 1, 0 ); // $ExpectError - variancech.ndarray( x.length, false, x, 1, 0 ); // $ExpectError - variancech.ndarray( x.length, null, x, 1, 0 ); // $ExpectError - variancech.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError - variancech.ndarray( x.length, [], x, 1, 0 ); // $ExpectError - variancech.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError - variancech.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... -{ - const x = new Float64Array( 10 ); - - variancech.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError - variancech.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError - variancech.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError - variancech.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError - variancech.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError - variancech.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError - variancech.ndarray( x.length, 1, [ '1' ], 1, 0 ); // $ExpectError - variancech.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError - variancech.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancech.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError - variancech.ndarray( x.length, 1, x, true, 0 ); // $ExpectError - variancech.ndarray( x.length, 1, x, false, 0 ); // $ExpectError - variancech.ndarray( x.length, 1, x, null, 0 ); // $ExpectError - variancech.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError - variancech.ndarray( x.length, 1, x, [], 0 ); // $ExpectError - variancech.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError - variancech.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variancech.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError - variancech.ndarray( x.length, 1, x, 1, true ); // $ExpectError - variancech.ndarray( x.length, 1, x, 1, false ); // $ExpectError - variancech.ndarray( x.length, 1, x, 1, null ); // $ExpectError - variancech.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError - variancech.ndarray( x.length, 1, x, 1, [] ); // $ExpectError - variancech.ndarray( x.length, 1, x, 1, {} ); // $ExpectError - variancech.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - - variancech.ndarray(); // $ExpectError - variancech.ndarray( x.length ); // $ExpectError - variancech.ndarray( x.length, 1 ); // $ExpectError - variancech.ndarray( x.length, 1, x ); // $ExpectError - variancech.ndarray( x.length, 1, x, 1 ); // $ExpectError - variancech.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/stats/base/variancech/examples/index.js b/lib/node_modules/@stdlib/stats/base/variancech/examples/index.js deleted file mode 100644 index adaae05a5d6d..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/examples/index.js +++ /dev/null @@ -1,30 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var variancech = require( './../lib' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); -console.log( x ); - -var v = variancech( x.length, 1, x, 1 ); -console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/variancech/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/variancech/lib/accessors.js deleted file mode 100644 index 149ba4659feb..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/lib/accessors.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @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'; - -// MAIN // - -/** -* Computes the variance of a strided array using a one-pass trial mean algorithm. -* -* ## Method -* -* - This implementation uses a one-pass trial mean approach, as suggested by Chan et al (1983). -* -* ## References -* -* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). -* - Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154](https://doi.org/10.2307/2286154). -* - Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. 1983. "Algorithms for Computing the Sample Variance: Analysis and Recommendations." _The American Statistician_ 37 (3). American Statistical Association, Taylor & Francis, Ltd.: 242–47. doi:[10.1080/00031305.1983.10483115](https://doi.org/10.1080/00031305.1983.10483115). -* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). -* -* @private -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {Object} x - input array object -* @param {Collection} x.data - input array data -* @param {Array} x.accessors - array element accessors -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index -* @returns {number} variance -* -* @example -* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -* -* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* -* var v = variancech( 4, 1, arraylike2object( x ), 2, 1 ); -* // returns 6.25 -*/ -function variancech( N, correction, x, strideX, offsetX ) { - var xbuf; - var get; - var mu; - var ix; - var M2; - var M; - var d; - var n; - var i; - - // Cache reference to array data: - xbuf = x.data; - - // Cache a reference to the element accessor: - get = x.accessors[ 0 ]; - - n = N - correction; - ix = offsetX; - - // Use an estimate for the mean: - mu = get( xbuf, ix ); - ix += strideX; - - // Compute the variance... - M2 = 0.0; - M = 0.0; - for ( i = 1; i < N; i++ ) { - d = get( xbuf, ix ) - mu; - M2 += d * d; - M += d; - ix += strideX; - } - return (M2/n) - ((M/N)*(M/n)); -} - - -// EXPORTS // - -module.exports = variancech; diff --git a/lib/node_modules/@stdlib/stats/base/variancech/lib/index.js b/lib/node_modules/@stdlib/stats/base/variancech/lib/index.js deleted file mode 100644 index 94ddc67f28c7..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/lib/index.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 the variance of a strided array using a one-pass trial mean algorithm. -* -* @module @stdlib/stats/base/variancech -* -* @example -* var variancech = require( '@stdlib/stats/base/variancech' ); -* -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancech( x.length, 1, x, 1 ); -* // returns ~4.3333 -* -* @example -* var variancech = require( '@stdlib/stats/base/variancech' ); -* -* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* -* var v = variancech.ndarray( 4, 1, x, 2, 1 ); -* // returns 6.25 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/base/variancech/lib/main.js b/lib/node_modules/@stdlib/stats/base/variancech/lib/main.js deleted file mode 100644 index 8a2fd7a5a1ad..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/lib/main.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var variancech = require( './variancech.js' ); -var ndarray = require( './ndarray.js' ); - - -// MAIN // - -setReadOnly( variancech, 'ndarray', ndarray ); - - -// EXPORTS // - -module.exports = variancech; diff --git a/lib/node_modules/@stdlib/stats/base/variancech/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/variancech/lib/ndarray.js deleted file mode 100644 index 1c04ab725cd3..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/lib/ndarray.js +++ /dev/null @@ -1,98 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -var accessors = require( './accessors.js' ); - - -// MAIN // - -/** -* Computes the variance of a strided array using a one-pass trial mean algorithm. -* -* ## Method -* -* - This implementation uses a one-pass trial mean approach, as suggested by Chan et al (1983). -* -* ## References -* -* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). -* - Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154](https://doi.org/10.2307/2286154). -* - Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. 1983. "Algorithms for Computing the Sample Variance: Analysis and Recommendations." _The American Statistician_ 37 (3). American Statistical Association, Taylor & Francis, Ltd.: 242–47. doi:[10.1080/00031305.1983.10483115](https://doi.org/10.1080/00031305.1983.10483115). -* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index -* @returns {number} variance -* -* @example -* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* -* var v = variancech( 4, 1, x, 2, 1 ); -* // returns 6.25 -*/ -function variancech( N, correction, x, strideX, offsetX ) { - var mu; - var ix; - var M2; - var M; - var d; - var n; - var o; - var i; - - n = N - correction; - if ( N <= 0 || n <= 0.0 ) { - return NaN; - } - if ( N === 1 || strideX === 0 ) { - return 0.0; - } - o = arraylike2object( x ); - if ( o.accessorProtocol ) { - return accessors( N, correction, o, strideX, offsetX ); - } - ix = offsetX; - - // Use an estimate for the mean: - mu = x[ ix ]; - ix += strideX; - - // Compute the variance... - M2 = 0.0; - M = 0.0; - for ( i = 1; i < N; i++ ) { - d = x[ ix ] - mu; - M2 += d * d; - M += d; - ix += strideX; - } - return (M2/n) - ((M/N)*(M/n)); -} - - -// EXPORTS // - -module.exports = variancech; diff --git a/lib/node_modules/@stdlib/stats/base/variancech/lib/variancech.js b/lib/node_modules/@stdlib/stats/base/variancech/lib/variancech.js deleted file mode 100644 index d6ef6233ab47..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/lib/variancech.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); -var ndarray = require( './ndarray.js' ); - - -// MAIN // - -/** -* Computes the variance of a strided array using a one-pass trial mean algorithm. -* -* ## Method -* -* - This implementation uses a one-pass trial mean approach, as suggested by Chan et al (1983). -* -* ## References -* -* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). -* - Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154](https://doi.org/10.2307/2286154). -* - Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. 1983. "Algorithms for Computing the Sample Variance: Analysis and Recommendations." _The American Statistician_ 37 (3). American Statistical Association, Taylor & Francis, Ltd.: 242–47. doi:[10.1080/00031305.1983.10483115](https://doi.org/10.1080/00031305.1983.10483115). -* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array -* @param {integer} strideX - stride length -* @returns {number} variance -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variancech( x.length, 1, x, 1 ); -* // returns ~4.3333 -*/ -function variancech( N, correction, x, strideX ) { - return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); -} - - -// EXPORTS // - -module.exports = variancech; diff --git a/lib/node_modules/@stdlib/stats/base/variancech/package.json b/lib/node_modules/@stdlib/stats/base/variancech/package.json deleted file mode 100644 index ec87d6fabf13..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/package.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "name": "@stdlib/stats/base/variancech", - "version": "0.0.0", - "description": "Calculate the variance of a strided array using a one-pass trial mean algorithm.", - "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", - "var", - "deviation", - "dispersion", - "sample variance", - "unbiased", - "stdev", - "std", - "standard deviation", - "strided", - "strided array", - "typed", - "array" - ], - "__stdlib__": {} -} diff --git a/lib/node_modules/@stdlib/stats/base/variancech/test/test.js b/lib/node_modules/@stdlib/stats/base/variancech/test/test.js deleted file mode 100644 index aec1f7916119..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 variancech = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variancech, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { - t.strictEqual( typeof variancech.ndarray, 'function', 'method is a function' ); - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/variancech/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/variancech/test/test.ndarray.js deleted file mode 100644 index c1327184ccfb..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/test/test.ndarray.js +++ /dev/null @@ -1,350 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -var variancech = require( './../lib/ndarray.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variancech, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( variancech.length, 5, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancech( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancech( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancech( x.length, 0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancech( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancech( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancech( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancech( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancech( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancech( x.length, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancech( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancech( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancech( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( 0, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancech( -1, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( 0, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancech( -1, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( 1, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( 1, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancech( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( x.length, x.length, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancech( x.length, x.length+1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancech( 4, 1, x, 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancech( 4, 1, toAccessorArray( x ), 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancech( 4, 1, x, -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancech( 4, 1, toAccessorArray( x ), -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( x.length, 1, x, 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( x.length, 1, toAccessorArray( x ), 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter', function test( t ) { - var x; - var v; - - x = [ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]; - - v = variancech( 4, 1, x, 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]; - - v = variancech( 4, 1, toAccessorArray( x ), 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/variancech/test/test.variancech.js b/lib/node_modules/@stdlib/stats/base/variancech/test/test.variancech.js deleted file mode 100644 index 83fc264cbc23..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancech/test/test.variancech.js +++ /dev/null @@ -1,358 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var Float64Array = require( '@stdlib/array/float64' ); -var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -var variancech = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variancech, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( variancech.length, 4, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancech( x.length, 0, x, 1 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancech( x.length, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancech( x.length, 0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancech( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancech( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancech( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancech( x.length, 1, x, 1 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancech( x.length, 1, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancech( x.length, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variancech( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variancech( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variancech( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( 0, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancech( -1, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( 0, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancech( -1, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( 1, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( 1, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancech( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( x.length, x.length, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variancech( x.length, x.length+1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancech( 4, 1, x, 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variancech( 4, 1, toAccessorArray( x ), 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancech( 4, 1, x, -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); -tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variancech( 4, 1, toAccessorArray( x ), -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( x.length, 1, x, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variancech( x.length, 1, toAccessorArray( x ), 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float64Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = variancech( 4, 1, x1, 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets (accessors)', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float64Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = variancech( 4, 1, toAccessorArray( x1 ), 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); From 09be71bc241b529b2d10f0e4669610dd1c1d32ee Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:34:39 +0000 Subject: [PATCH 26/32] feat: add `stats/strided/variance` Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/stats/strided/variance/README.md | 255 +++++++++++++ .../strided/variance/benchmark/benchmark.js | 96 +++++ .../variance/benchmark/benchmark.ndarray.js | 96 +++++ .../docs/img/equation_population_mean.svg | 42 ++ .../docs/img/equation_population_variance.svg | 54 +++ .../docs/img/equation_sample_mean.svg | 43 +++ .../img/equation_unbiased_sample_variance.svg | 61 +++ .../stats/strided/variance/docs/repl.txt | 113 ++++++ .../strided/variance/docs/types/index.d.ts | 96 +++++ .../stats/strided/variance/docs/types/test.ts | 190 +++++++++ .../stats/strided/variance/examples/index.js | 30 ++ .../stats/strided/variance/lib/index.js | 52 +++ .../stats/strided/variance/lib/main.js | 35 ++ .../stats/strided/variance/lib/ndarray.js | 51 +++ .../stats/strided/variance/lib/variance.js | 50 +++ .../stats/strided/variance/package.json | 73 ++++ .../stats/strided/variance/test/test.js | 38 ++ .../strided/variance/test/test.ndarray.js | 350 +++++++++++++++++ .../strided/variance/test/test.variance.js | 359 ++++++++++++++++++ 19 files changed, 2084 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_population_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_population_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_sample_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_unbiased_sample_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/lib/variance.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/variance/test/test.variance.js diff --git a/lib/node_modules/@stdlib/stats/strided/variance/README.md b/lib/node_modules/@stdlib/stats/strided/variance/README.md new file mode 100644 index 000000000000..a665d9fcac06 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/README.md @@ -0,0 +1,255 @@ + + +# variance + +> Calculate the [variance][variance] of a strided array. + +
+ +The population [variance][variance] of a finite size population of size `N` is given by + + + +```math +\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 +``` + + + + + +where the population mean is given by + + + +```math +\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i +``` + + + + + +Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, + + + +```math +s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 +``` + + + + + +where the sample mean is given by + + + +```math +\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + + + +The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. + +
+ + + +
+ +## Usage + +```javascript +var variance = require( '@stdlib/stats/strided/variance' ); +``` + +#### variance( N, correction, x, strideX ) + +Computes the [variance][variance] of a strided array. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; + +var v = variance( x.length, 1, x, 1 ); +// returns ~4.3333 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, + +```javascript +var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; + +var v = variance( 4, 1, x, 2 ); +// returns 6.25 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var v = variance( 4, 1, x1, 2 ); +// returns 6.25 +``` + +#### variance.ndarray( N, correction, x, strideX, offsetX ) + +Computes the [variance][variance] of a strided array using alternative indexing semantics. + +```javascript +var x = [ 1.0, -2.0, 2.0 ]; + +var v = variance.ndarray( x.length, 1, x, 1, 0 ); +// returns ~4.33333 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element + +```javascript +var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; + +var v = variance.ndarray( 4, 1, x, 2, 1 ); +// returns 6.25 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `NaN`. +- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). +- Depending on the environment, the typed versions ([`dvariance`][@stdlib/stats/strided/dvariance], [`svariance`][@stdlib/stats/strided/svariance], etc.) are likely to be significantly more performant. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var variance = require( '@stdlib/stats/strided/variance' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +console.log( x ); + +var v = variance( x.length, 1, x, 1 ); +console.log( v ); +``` + +
+ + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/variance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/variance/benchmark/benchmark.js new file mode 100644 index 000000000000..5575120b06ab --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/benchmark/benchmark.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var variance = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = variance( x.length, 1, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/variance/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/variance/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..c02c1ba01b37 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/benchmark/benchmark.ndarray.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var variance = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = variance( x.length, 1, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_population_mean.svg new file mode 100644 index 000000000000..4bbdf0d2a56f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_population_mean.svg @@ -0,0 +1,42 @@ + +mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_population_variance.svg new file mode 100644 index 000000000000..4130ba0750d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_population_variance.svg @@ -0,0 +1,54 @@ + +sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_sample_mean.svg new file mode 100644 index 000000000000..aea7a5f6687a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_sample_mean.svg @@ -0,0 +1,43 @@ + +x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_unbiased_sample_variance.svg new file mode 100644 index 000000000000..1ae1283e7fb1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/docs/img/equation_unbiased_sample_variance.svg @@ -0,0 +1,61 @@ + +s squared equals 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 + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/variance/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/variance/docs/repl.txt new file mode 100644 index 000000000000..8f5c3fb9ddd5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/docs/repl.txt @@ -0,0 +1,113 @@ + +{{alias}}( N, correction, x, strideX ) + Computes the variance of a strided array. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns `NaN`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > {{alias}}( x.length, 1, x, 1 ) + ~4.3333 + + // Using `N` and stride parameters: + > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; + > {{alias}}( 3, 1, x, 2 ) + ~4.3333 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, 1, x1, 2 ) + ~4.3333 + + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) + Computes the variance of a strided array using alternative indexing + semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the `offset` parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0 ]; + > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) + ~4.3333 + + // Using offset parameter: + > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; + > {{alias}}.ndarray( 3, 1, x, 2, 1 ) + ~4.3333 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/variance/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/variance/docs/types/index.d.ts new file mode 100644 index 000000000000..5d58b7b3268a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/docs/types/index.d.ts @@ -0,0 +1,96 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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 + +/// + +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `variance`. +*/ +interface Routine { + /** + * Computes the variance of a strided array. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @returns variance + * + * @example + * var x = [ 1.0, -2.0, 2.0 ]; + * + * var v = variance( x.length, 1, x, 1 ); + * // returns ~4.3333 + */ + ( N: number, correction: number, x: InputArray, strideX: number ): number; + + /** + * Computes the variance of a strided array using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns variance + * + * @example + * var x = [ 1.0, -2.0, 2.0 ]; + * + * var v = variance.ndarray( x.length, 1, x, 1, 0 ); + * // returns ~4.3333 + */ + ndarray( N: number, correction: number, x: InputArray, strideX: number, offsetX: number ): number; +} + +/** +* Computes the variance of a strided array. +* +* @param N - number of indexed elements +* @param correction - degrees of freedom adjustment +* @param x - input array +* @param strideX - stride length +* @returns variance +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variance( x.length, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variance.ndarray( x.length, 1, x, 1, 0 ); +* // returns ~4.3333 +*/ +declare var variance: Routine; + + +// EXPORTS // + +export = variance; diff --git a/lib/node_modules/@stdlib/stats/strided/variance/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/variance/docs/types/test.ts new file mode 100644 index 000000000000..09e2570ecc52 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/docs/types/test.ts @@ -0,0 +1,190 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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 AccessorArray = require( '@stdlib/array/base/accessor' ); +import variance = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Float64Array( 10 ); + + variance( x.length, 1, x, 1 ); // $ExpectType number + variance( x.length, 1, new AccessorArray( x ), 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variance( '10', 1, x, 1 ); // $ExpectError + variance( true, 1, x, 1 ); // $ExpectError + variance( false, 1, x, 1 ); // $ExpectError + variance( null, 1, x, 1 ); // $ExpectError + variance( undefined, 1, x, 1 ); // $ExpectError + variance( [], 1, x, 1 ); // $ExpectError + variance( {}, 1, x, 1 ); // $ExpectError + variance( ( x: number ): number => x, 1, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variance( x.length, '10', x, 1 ); // $ExpectError + variance( x.length, true, x, 1 ); // $ExpectError + variance( x.length, false, x, 1 ); // $ExpectError + variance( x.length, null, x, 1 ); // $ExpectError + variance( x.length, undefined, x, 1 ); // $ExpectError + variance( x.length, [], x, 1 ); // $ExpectError + variance( x.length, {}, x, 1 ); // $ExpectError + variance( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + variance( x.length, 1, 10, 1 ); // $ExpectError + variance( x.length, 1, '10', 1 ); // $ExpectError + variance( x.length, 1, true, 1 ); // $ExpectError + variance( x.length, 1, false, 1 ); // $ExpectError + variance( x.length, 1, null, 1 ); // $ExpectError + variance( x.length, 1, undefined, 1 ); // $ExpectError + variance( x.length, 1, [ '1' ], 1 ); // $ExpectError + variance( x.length, 1, {}, 1 ); // $ExpectError + variance( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variance( x.length, 1, x, '10' ); // $ExpectError + variance( x.length, 1, x, true ); // $ExpectError + variance( x.length, 1, x, false ); // $ExpectError + variance( x.length, 1, x, null ); // $ExpectError + variance( x.length, 1, x, undefined ); // $ExpectError + variance( x.length, 1, x, [] ); // $ExpectError + variance( x.length, 1, x, {} ); // $ExpectError + variance( x.length, 1, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + variance(); // $ExpectError + variance( x.length ); // $ExpectError + variance( x.length, 1 ); // $ExpectError + variance( x.length, 1, x ); // $ExpectError + variance( x.length, 1, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + + variance.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number + variance.ndarray( x.length, 1, new AccessorArray( x ), 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variance.ndarray( '10', 1, x, 1, 0 ); // $ExpectError + variance.ndarray( true, 1, x, 1, 0 ); // $ExpectError + variance.ndarray( false, 1, x, 1, 0 ); // $ExpectError + variance.ndarray( null, 1, x, 1, 0 ); // $ExpectError + variance.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError + variance.ndarray( [], 1, x, 1, 0 ); // $ExpectError + variance.ndarray( {}, 1, x, 1, 0 ); // $ExpectError + variance.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variance.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError + variance.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + variance.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + variance.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + variance.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + variance.ndarray( x.length, [], x, 1, 0 ); // $ExpectError + variance.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + variance.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + variance.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError + variance.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError + variance.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError + variance.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError + variance.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError + variance.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError + variance.ndarray( x.length, 1, [ '1' ], 1, 0 ); // $ExpectError + variance.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError + variance.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variance.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError + variance.ndarray( x.length, 1, x, true, 0 ); // $ExpectError + variance.ndarray( x.length, 1, x, false, 0 ); // $ExpectError + variance.ndarray( x.length, 1, x, null, 0 ); // $ExpectError + variance.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError + variance.ndarray( x.length, 1, x, [], 0 ); // $ExpectError + variance.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError + variance.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + variance.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError + variance.ndarray( x.length, 1, x, 1, true ); // $ExpectError + variance.ndarray( x.length, 1, x, 1, false ); // $ExpectError + variance.ndarray( x.length, 1, x, 1, null ); // $ExpectError + variance.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError + variance.ndarray( x.length, 1, x, 1, [] ); // $ExpectError + variance.ndarray( x.length, 1, x, 1, {} ); // $ExpectError + variance.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + variance.ndarray(); // $ExpectError + variance.ndarray( x.length ); // $ExpectError + variance.ndarray( x.length, 1 ); // $ExpectError + variance.ndarray( x.length, 1, x ); // $ExpectError + variance.ndarray( x.length, 1, x, 1 ); // $ExpectError + variance.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/variance/examples/index.js b/lib/node_modules/@stdlib/stats/strided/variance/examples/index.js new file mode 100644 index 000000000000..ccf70cf0735d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/examples/index.js @@ -0,0 +1,30 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var variance = require( './../lib' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +console.log( x ); + +var v = variance( x.length, 1, x, 1 ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/strided/variance/lib/index.js b/lib/node_modules/@stdlib/stats/strided/variance/lib/index.js new file mode 100644 index 000000000000..71930e4b9d9f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/lib/index.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 the variance of a strided array. +* +* @module @stdlib/stats/strided/variance +* +* @example +* var variance = require( '@stdlib/stats/strided/variance' ); +* +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variance( x.length, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var variance = require( '@stdlib/stats/strided/variance' ); +* +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = variance.ndarray( 4, 1, x, 2, 1 ); +* // returns 6.25 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/strided/variance/lib/main.js b/lib/node_modules/@stdlib/stats/strided/variance/lib/main.js new file mode 100644 index 000000000000..d7ff74d08f57 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var variance = require( './variance.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( variance, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = variance; diff --git a/lib/node_modules/@stdlib/stats/strided/variance/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/variance/lib/ndarray.js new file mode 100644 index 000000000000..1cd7667fb326 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/lib/ndarray.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 variancepn = require( '@stdlib/stats/strided/variancepn' ).ndarray; + + +// MAIN // + +/** +* Computes the variance of a strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} variance +* +* @example +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = variance( 4, 1, x, 2, 1 ); +* // returns 6.25 +*/ +function variance( N, correction, x, strideX, offsetX ) { + return variancepn( N, correction, x, strideX, offsetX ); +} + + +// EXPORTS // + +module.exports = variance; diff --git a/lib/node_modules/@stdlib/stats/strided/variance/lib/variance.js b/lib/node_modules/@stdlib/stats/strided/variance/lib/variance.js new file mode 100644 index 000000000000..90873fa2cf62 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/lib/variance.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 variancepn = require( '@stdlib/stats/strided/variancepn' ); + + +// MAIN // + +/** +* Computes the variance of a strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @returns {number} variance +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variance( x.length, 1, x, 1 ); +* // returns ~4.3333 +*/ +function variance( N, correction, x, strideX ) { + return variancepn( N, correction, x, strideX ); +} + + +// EXPORTS // + +module.exports = variance; diff --git a/lib/node_modules/@stdlib/stats/strided/variance/package.json b/lib/node_modules/@stdlib/stats/strided/variance/package.json new file mode 100644 index 000000000000..31266660e2f5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/stats/strided/variance", + "version": "0.0.0", + "description": "Calculate the variance of a strided array.", + "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", + "var", + "deviation", + "dispersion", + "sample variance", + "unbiased", + "stdev", + "std", + "standard deviation", + "strided", + "strided array", + "typed", + "array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/variance/test/test.js b/lib/node_modules/@stdlib/stats/strided/variance/test/test.js new file mode 100644 index 000000000000..af6863992aaf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 variance = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variance, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof variance.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/variance/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/variance/test/test.ndarray.js new file mode 100644 index 000000000000..9fe2c9e1bfc2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/test/test.ndarray.js @@ -0,0 +1,350 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var variance = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variance, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( variance.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variance( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variance( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variance( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variance( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variance( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variance( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variance( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variance( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variance( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variance( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variance( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variance( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( 0, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variance( -1, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( 0, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variance( -1, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( 1, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( 1, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variance( x.length, x.length+1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( x.length, x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variance( x.length, x.length+1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variance( 4, 1, x, 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variance( 4, 1, toAccessorArray( x ), 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variance( 4, 1, x, -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variance( 4, 1, toAccessorArray( x ), -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( x.length, 1, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( x.length, 1, toAccessorArray( x ), 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + + v = variance( 4, 1, x, 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + + v = variance( 4, 1, toAccessorArray( x ), 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/variance/test/test.variance.js b/lib/node_modules/@stdlib/stats/strided/variance/test/test.variance.js new file mode 100644 index 000000000000..6c76484c1a9c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/variance/test/test.variance.js @@ -0,0 +1,359 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var variance = require( './../lib/variance.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variance, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( variance.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variance( x.length, 0, x, 1 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variance( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variance( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variance( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variance( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variance( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variance( x.length, 1, x, 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variance( x.length, 1, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variance( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variance( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variance( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variance( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( 0, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variance( -1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( 0, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variance( -1, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( 1, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variance( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( x.length, x.length, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variance( x.length, x.length+1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variance( 4, 1, x, 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = variance( 4, 1, toAccessorArray( x ), 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variance( 4, 1, x, -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = variance( 4, 1, toAccessorArray( x ), -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variance( x.length, 1, toAccessorArray( x ), 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = variance( 4, 1, x1, 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets (accessors)', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = variance( 4, 1, toAccessorArray( x1 ), 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); From c345633f8162b7c27b94d71f48a478fa5a174999 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:36:55 +0000 Subject: [PATCH 27/32] remove: remove `variance` from namespace This commit removes the `variance` symbol from the `@stdlib/stats/base` namespace due to a package migration. BREAKING CHANGE: remove `variance` To migrate, users should access the same symbol via the `@stdlib/stats/strided` namespace. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/docs/types/index.d.ts | 24 ------------------- .../@stdlib/stats/base/lib/index.js | 9 ------- 2 files changed, 33 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts index 4942d136ffb9..9a7126b92b4b 100644 --- a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts @@ -66,7 +66,6 @@ import stdevpn = require( '@stdlib/stats/base/stdevpn' ); import stdevtk = require( '@stdlib/stats/base/stdevtk' ); import stdevwd = require( '@stdlib/stats/base/stdevwd' ); import stdevyc = require( '@stdlib/stats/base/stdevyc' ); -import variance = require( '@stdlib/stats/base/variance' ); import dmeankbn2 = require( '@stdlib/stats/strided/dmeankbn2' ); import dmeanli = require( '@stdlib/stats/strided/dmeanli' ); import dmeanlipw = require( '@stdlib/stats/strided/dmeanlipw' ); @@ -1249,29 +1248,6 @@ interface Namespace { */ stdevyc: typeof stdevyc; - /** - * Computes the variance of a strided array. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param stride - stride length - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = ns.variance( x.length, 1, x, 1 ); - * // returns ~4.3333 - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = ns.variance.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - variance: typeof variance; - /** * Computes the arithmetic mean of a double-precision floating-point strided array using a second-order iterative Kahan–Babuška algorithm. * diff --git a/lib/node_modules/@stdlib/stats/base/lib/index.js b/lib/node_modules/@stdlib/stats/base/lib/index.js index 207b1be7094b..b9c175e51dd9 100644 --- a/lib/node_modules/@stdlib/stats/base/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/lib/index.js @@ -459,15 +459,6 @@ setReadOnly( ns, 'stdevwd', require( '@stdlib/stats/base/stdevwd' ) ); */ setReadOnly( ns, 'stdevyc', require( '@stdlib/stats/base/stdevyc' ) ); -/** -* @name variance -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/stats/base/variance} -*/ -setReadOnly( ns, 'variance', require( '@stdlib/stats/base/variance' ) ); - /** * @name dmeankbn2 * @memberof ns From e342a388619ab71f5222105ec94c5029e42a4458 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:37:50 +0000 Subject: [PATCH 28/32] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../namespace/lib/namespace/base/strided/d.js | 4 ++-- .../namespace/lib/namespace/base/strided/n.js | 2 +- .../namespace/lib/namespace/base/strided/s.js | 4 ++-- .../namespace/lib/namespace/base/strided/v.js | 14 +++++++------- .../@stdlib/stats/array/variance/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/base/README.md | 4 ++-- .../@stdlib/stats/base/dists/chi/README.md | 2 +- .../@stdlib/stats/base/dists/chi/examples/index.js | 2 +- .../@stdlib/stats/base/dists/gamma/README.md | 2 +- .../stats/base/dists/gamma/examples/index.js | 2 +- .../@stdlib/stats/base/dists/geometric/README.md | 2 +- .../stats/base/dists/geometric/examples/index.js | 2 +- .../@stdlib/stats/base/dists/gumbel/README.md | 2 +- .../stats/base/dists/gumbel/examples/index.js | 2 +- .../@stdlib/stats/base/dists/invgamma/README.md | 2 +- .../stats/base/dists/invgamma/examples/index.js | 2 +- .../@stdlib/stats/base/nanvariance/README.md | 4 ++-- .../@stdlib/stats/base/stdev/README.md | 4 ++-- .../@stdlib/stats/pcorrtest/lib/pcorr.js | 2 +- .../@stdlib/stats/strided/dsvariance/README.md | 4 ++-- .../@stdlib/stats/strided/dvariance/README.md | 4 ++-- .../@stdlib/stats/strided/svariance/README.md | 4 ++-- .../@stdlib/stats/strided/variancech/README.md | 4 ++-- .../@stdlib/stats/strided/variancepn/README.md | 4 ++-- .../@stdlib/stats/strided/variancetk/README.md | 4 ++-- .../@stdlib/stats/strided/variancewd/README.md | 4 ++-- .../@stdlib/stats/strided/varianceyc/README.md | 4 ++-- lib/node_modules/@stdlib/stats/ttest/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/ttest2/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/vartest/lib/main.js | 2 +- 30 files changed, 49 insertions(+), 49 deletions(-) diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js index 5074b08cb7e8..4f4658a10a5c 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js @@ -2151,7 +2151,7 @@ ns.push({ 'related': [ '@stdlib/stats/strided/dvariance', '@stdlib/stats/base/dsnanvariance', - '@stdlib/stats/base/variance', + '@stdlib/stats/strided/variance', '@stdlib/stats/base/sdsvariance', '@stdlib/stats/strided/svariance' ] @@ -2253,7 +2253,7 @@ ns.push({ '@stdlib/stats/strided/dstdev', '@stdlib/stats/strided/dvarm', '@stdlib/stats/strided/svariance', - '@stdlib/stats/base/variance' + '@stdlib/stats/strided/variance' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js index 1c8d697396b6..8cdd074c697a 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/n.js @@ -326,7 +326,7 @@ ns.push({ '@stdlib/stats/strided/dnanvariance', '@stdlib/stats/base/nanstdev', '@stdlib/stats/base/snanvariance', - '@stdlib/stats/base/variance' + '@stdlib/stats/strided/variance' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js index f23bc54fe95e..817232b5bc1d 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js @@ -1797,7 +1797,7 @@ ns.push({ '@stdlib/stats/base/nanstdev', '@stdlib/stats/strided/sstdev', '@stdlib/stats/base/stdevm', - '@stdlib/stats/base/variance' + '@stdlib/stats/strided/variance' ] }); @@ -1900,7 +1900,7 @@ ns.push({ '@stdlib/stats/base/snanvariance', '@stdlib/stats/strided/sstdev', '@stdlib/stats/base/svarm', - '@stdlib/stats/base/variance' + '@stdlib/stats/strided/variance' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js index da84e1ec2847..1ec5197bd922 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/v.js @@ -28,8 +28,8 @@ var ns = []; ns.push({ 'alias': 'base.strided.variance', - 'path': '@stdlib/stats/base/variance', - 'value': require( '@stdlib/stats/base/variance' ), + 'path': '@stdlib/stats/strided/variance', + 'value': require( '@stdlib/stats/strided/variance' ), 'type': 'Function', 'related': [ '@stdlib/stats/strided/dvariance', @@ -49,7 +49,7 @@ ns.push({ '@stdlib/stats/strided/dvariancech', '@stdlib/stats/base/nanvariancech', '@stdlib/stats/base/stdevch', - '@stdlib/stats/base/variance' + '@stdlib/stats/strided/variance' ] }); @@ -62,7 +62,7 @@ ns.push({ '@stdlib/stats/strided/dvariancepn', '@stdlib/stats/base/nanvariancepn', '@stdlib/stats/base/stdevpn', - '@stdlib/stats/base/variance', + '@stdlib/stats/strided/variance', '@stdlib/stats/base/varmpn' ] }); @@ -76,7 +76,7 @@ ns.push({ '@stdlib/stats/strided/dvariancetk', '@stdlib/stats/base/nanvariancetk', '@stdlib/stats/base/stdevtk', - '@stdlib/stats/base/variance' + '@stdlib/stats/strided/variance' ] }); @@ -89,7 +89,7 @@ ns.push({ '@stdlib/stats/strided/dvariancewd', '@stdlib/stats/base/nanvariancewd', '@stdlib/stats/base/stdevwd', - '@stdlib/stats/base/variance' + '@stdlib/stats/strided/variance' ] }); @@ -102,7 +102,7 @@ ns.push({ '@stdlib/stats/strided/dvarianceyc', '@stdlib/stats/base/nanvarianceyc', '@stdlib/stats/base/stdevyc', - '@stdlib/stats/base/variance' + '@stdlib/stats/strided/variance' ] }); diff --git a/lib/node_modules/@stdlib/stats/array/variance/lib/main.js b/lib/node_modules/@stdlib/stats/array/variance/lib/main.js index a6371ffa1b58..8de7e2d1beef 100644 --- a/lib/node_modules/@stdlib/stats/array/variance/lib/main.js +++ b/lib/node_modules/@stdlib/stats/array/variance/lib/main.js @@ -26,7 +26,7 @@ var dtypes = require( '@stdlib/array/dtypes' ); var dtype = require( '@stdlib/array/dtype' ); var contains = require( '@stdlib/array/base/assert/contains' ); var join = require( '@stdlib/array/base/join' ); -var strided = require( '@stdlib/stats/base/variance' ).ndarray; +var strided = require( '@stdlib/stats/strided/variance' ).ndarray; var format = require( '@stdlib/string/format' ); diff --git a/lib/node_modules/@stdlib/stats/base/README.md b/lib/node_modules/@stdlib/stats/base/README.md index 63f672048f9f..6dbebff754c5 100644 --- a/lib/node_modules/@stdlib/stats/base/README.md +++ b/lib/node_modules/@stdlib/stats/base/README.md @@ -107,7 +107,7 @@ The namespace contains the following statistical functions: - [`stdevtk( N, correction, x, stride )`][@stdlib/stats/base/stdevtk]: calculate the standard deviation of a strided array using a one-pass textbook algorithm. - [`stdevwd( N, correction, x, stride )`][@stdlib/stats/base/stdevwd]: calculate the standard deviation of a strided array using Welford's algorithm. - [`stdevyc( N, correction, x, stride )`][@stdlib/stats/base/stdevyc]: calculate the standard deviation of a strided array using a one-pass algorithm proposed by Youngs and Cramer. -- [`variance( N, correction, x, strideX )`][@stdlib/stats/base/variance]: calculate the variance of a strided array. +- [`variance( N, correction, x, strideX )`][@stdlib/stats/strided/variance]: calculate the variance of a strided array. - [`variancech( N, correction, x, strideX )`][@stdlib/stats/strided/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. - [`variancepn( N, correction, x, strideX )`][@stdlib/stats/strided/variancepn]: calculate the variance of a strided array using a two-pass algorithm. - [`variancetk( N, correction, x, strideX )`][@stdlib/stats/strided/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. @@ -263,7 +263,7 @@ console.log( objectKeys( ns ) ); [@stdlib/stats/base/stdevyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/stdevyc -[@stdlib/stats/base/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variance +[@stdlib/stats/strided/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variance [@stdlib/stats/strided/variancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variancech diff --git a/lib/node_modules/@stdlib/stats/base/dists/chi/README.md b/lib/node_modules/@stdlib/stats/base/dists/chi/README.md index ee241a393281..9292e867beff 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/chi/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/chi/README.md @@ -106,7 +106,7 @@ var mu = dist.mean; ```javascript var chiRandomFactory = require( '@stdlib/random/base/chi' ).factory; var filledarrayBy = require( '@stdlib/array/filled-by' ); -var variance = require( '@stdlib/stats/base/variance' ); +var variance = require( '@stdlib/stats/strided/variance' ); var linspace = require( '@stdlib/array/base/linspace' ); var rayleigh = require( '@stdlib/stats/base/dists/rayleigh' ); var absdiff = require( '@stdlib/math/base/utils/absolute-difference' ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/chi/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/chi/examples/index.js index d54da3bd9b5a..bc0fda28fe20 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/chi/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/chi/examples/index.js @@ -20,7 +20,7 @@ var chiRandomFactory = require( '@stdlib/random/base/chi' ).factory; var filledarrayBy = require( '@stdlib/array/filled-by' ); -var variance = require( '@stdlib/stats/base/variance' ); +var variance = require( '@stdlib/stats/strided/variance' ); var linspace = require( '@stdlib/array/base/linspace' ); var rayleigh = require( '@stdlib/stats/base/dists/rayleigh' ); var absdiff = require( '@stdlib/math/base/utils/absolute-difference' ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/gamma/README.md b/lib/node_modules/@stdlib/stats/base/dists/gamma/README.md index 07d7c2de3dd1..90a598402aa5 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/gamma/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/gamma/README.md @@ -111,7 +111,7 @@ var y = dist.cdf( 0.5 ); var gammaRandomFactory = require( '@stdlib/random/base/gamma' ).factory; var filledarrayby = require( '@stdlib/array/filled-by' ); var Float64Array = require( '@stdlib/array/float64' ); -var variance = require( '@stdlib/stats/base/variance' ); +var variance = require( '@stdlib/stats/strided/variance' ); var linspace = require( '@stdlib/array/base/linspace' ); var mean = require( '@stdlib/stats/strided/mean' ); var abs = require( '@stdlib/math/base/special/abs' ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/gamma/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/gamma/examples/index.js index 750d2bac5b8c..8a39f55392b3 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/gamma/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/gamma/examples/index.js @@ -21,7 +21,7 @@ var gammaRandomFactory = require( '@stdlib/random/base/gamma' ).factory; var filledarrayby = require( '@stdlib/array/filled-by' ); var Float64Array = require( '@stdlib/array/float64' ); -var variance = require( '@stdlib/stats/base/variance' ); +var variance = require( '@stdlib/stats/strided/variance' ); var linspace = require( '@stdlib/array/base/linspace' ); var mean = require( '@stdlib/stats/strided/mean' ); var abs = require( '@stdlib/math/base/special/abs' ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/geometric/README.md b/lib/node_modules/@stdlib/stats/base/dists/geometric/README.md index 6230dc3edddb..7d790fa494d4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/geometric/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/geometric/README.md @@ -115,7 +115,7 @@ y = dist.logpmf( 2.3 ); var geometricRandomFactory = require( '@stdlib/random/base/geometric' ).factory; var negativeBinomial = require( '@stdlib/stats/base/dists/negative-binomial' ); var filledarrayBy = require( '@stdlib/array/filled-by' ); -var variance = require( '@stdlib/stats/base/variance' ); +var variance = require( '@stdlib/stats/strided/variance' ); var linspace = require( '@stdlib/array/base/linspace' ); var mean = require( '@stdlib/stats/strided/mean' ); var abs = require( '@stdlib/math/base/special/abs' ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/geometric/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/geometric/examples/index.js index 5976b49eb15e..b243e587112d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/geometric/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/geometric/examples/index.js @@ -21,7 +21,7 @@ var geometricRandomFactory = require( '@stdlib/random/base/geometric' ).factory; var negativeBinomial = require( '@stdlib/stats/base/dists/negative-binomial' ); var filledarrayBy = require( '@stdlib/array/filled-by' ); -var variance = require( '@stdlib/stats/base/variance' ); +var variance = require( '@stdlib/stats/strided/variance' ); var linspace = require( '@stdlib/array/base/linspace' ); var mean = require( '@stdlib/stats/strided/mean' ); var abs = require( '@stdlib/math/base/special/abs' ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/gumbel/README.md b/lib/node_modules/@stdlib/stats/base/dists/gumbel/README.md index d1cb0cced8f8..caf81f35c171 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/gumbel/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/gumbel/README.md @@ -112,7 +112,7 @@ var y = dist.pdf( 2.0 ); var Float64Array = require( '@stdlib/array/float64' ); var filledarrayBy = require( '@stdlib/array/filled-by' ); var mean = require( '@stdlib/stats/strided/mean' ); -var variance = require( '@stdlib/stats/base/variance' ); +var variance = require( '@stdlib/stats/strided/variance' ); var stdev = require( '@stdlib/stats/base/stdev' ); var randGumbel = require( '@stdlib/random/base/gumbel' ).factory; var gumbel = require( '@stdlib/stats/base/dists/gumbel' ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/gumbel/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/gumbel/examples/index.js index 39beae5f615f..cd454fc76aab 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/gumbel/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/gumbel/examples/index.js @@ -21,7 +21,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var filledarrayBy = require( '@stdlib/array/filled-by' ); var mean = require( '@stdlib/stats/strided/mean' ); -var variance = require( '@stdlib/stats/base/variance' ); +var variance = require( '@stdlib/stats/strided/variance' ); var stdev = require( '@stdlib/stats/base/stdev' ); var randGumbel = require( '@stdlib/random/base/gumbel' ).factory; var gumbel = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/invgamma/README.md b/lib/node_modules/@stdlib/stats/base/dists/invgamma/README.md index 59a20113f14e..37e6a6aba9f6 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/invgamma/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/invgamma/README.md @@ -106,7 +106,7 @@ var y = dist.cdf( 0.5 ); ```javascript var invgammaRandomFactory = require( '@stdlib/random/base/invgamma' ).factory; var filledarrayBy = require( '@stdlib/array/filled-by' ); -var variance = require( '@stdlib/stats/base/variance' ); +var variance = require( '@stdlib/stats/strided/variance' ); var linspace = require( '@stdlib/array/base/linspace' ); var gamma = require( '@stdlib/stats/base/dists/gamma' ); var mean = require( '@stdlib/stats/strided/mean' ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/invgamma/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/invgamma/examples/index.js index 41e69b672b98..3b418c70f7a4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/invgamma/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/invgamma/examples/index.js @@ -20,7 +20,7 @@ var invgammaRandomFactory = require( '@stdlib/random/base/invgamma' ).factory; var filledarrayBy = require( '@stdlib/array/filled-by' ); -var variance = require( '@stdlib/stats/base/variance' ); +var variance = require( '@stdlib/stats/strided/variance' ); var linspace = require( '@stdlib/array/base/linspace' ); var gamma = require( '@stdlib/stats/base/dists/gamma' ); var mean = require( '@stdlib/stats/strided/mean' ); diff --git a/lib/node_modules/@stdlib/stats/base/nanvariance/README.md b/lib/node_modules/@stdlib/stats/base/nanvariance/README.md index 110ec445160d..188b1fc09052 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariance/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanvariance/README.md @@ -227,7 +227,7 @@ console.log( v ); - [`@stdlib/stats/strided/dnanvariance`][@stdlib/stats/strided/dnanvariance]: calculate the variance of a double-precision floating-point strided array ignoring NaN values. - [`@stdlib/stats/base/nanstdev`][@stdlib/stats/base/nanstdev]: calculate the standard deviation of a strided array ignoring NaN values. - [`@stdlib/stats/base/snanvariance`][@stdlib/stats/base/snanvariance]: calculate the variance of a single-precision floating-point strided array ignoring NaN values. -- [`@stdlib/stats/base/variance`][@stdlib/stats/base/variance]: calculate the variance of a strided array. +- [`@stdlib/stats/strided/variance`][@stdlib/stats/strided/variance]: calculate the variance of a strided array. @@ -253,7 +253,7 @@ console.log( v ); [@stdlib/stats/base/snanvariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/snanvariance -[@stdlib/stats/base/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variance +[@stdlib/stats/strided/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variance diff --git a/lib/node_modules/@stdlib/stats/base/stdev/README.md b/lib/node_modules/@stdlib/stats/base/stdev/README.md index 6e80f84951e6..6453641ded06 100644 --- a/lib/node_modules/@stdlib/stats/base/stdev/README.md +++ b/lib/node_modules/@stdlib/stats/base/stdev/README.md @@ -220,7 +220,7 @@ console.log( v ); - [`@stdlib/stats/strided/dstdev`][@stdlib/stats/strided/dstdev]: calculate the standard deviation of a double-precision floating-point strided array. - [`@stdlib/stats/base/nanstdev`][@stdlib/stats/base/nanstdev]: calculate the standard deviation of a strided array ignoring NaN values. - [`@stdlib/stats/strided/sstdev`][@stdlib/stats/strided/sstdev]: calculate the standard deviation of a single-precision floating-point strided array. -- [`@stdlib/stats/base/variance`][@stdlib/stats/base/variance]: calculate the variance of a strided array. +- [`@stdlib/stats/strided/variance`][@stdlib/stats/strided/variance]: calculate the variance of a strided array. @@ -246,7 +246,7 @@ console.log( v ); [@stdlib/stats/strided/sstdev]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/sstdev -[@stdlib/stats/base/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variance +[@stdlib/stats/strided/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variance diff --git a/lib/node_modules/@stdlib/stats/pcorrtest/lib/pcorr.js b/lib/node_modules/@stdlib/stats/pcorrtest/lib/pcorr.js index 87d1c53e1bfa..23eb80676051 100644 --- a/lib/node_modules/@stdlib/stats/pcorrtest/lib/pcorr.js +++ b/lib/node_modules/@stdlib/stats/pcorrtest/lib/pcorr.js @@ -23,7 +23,7 @@ var max = require( '@stdlib/math/base/special/max' ); var min = require( '@stdlib/math/base/special/min' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); -var variance = require( '@stdlib/stats/base/variance' ); +var variance = require( '@stdlib/stats/strided/variance' ); var mean = require( '@stdlib/stats/strided/mean' ); diff --git a/lib/node_modules/@stdlib/stats/strided/dsvariance/README.md b/lib/node_modules/@stdlib/stats/strided/dsvariance/README.md index edd938213b56..8e98a1900c9b 100644 --- a/lib/node_modules/@stdlib/stats/strided/dsvariance/README.md +++ b/lib/node_modules/@stdlib/stats/strided/dsvariance/README.md @@ -346,7 +346,7 @@ int main( void ) { ## See Also - [`@stdlib/stats/strided/dvariance`][@stdlib/stats/strided/dvariance]: calculate the variance of a double-precision floating-point strided array. -- [`@stdlib/stats/base/variance`][@stdlib/stats/base/variance]: calculate the variance of a strided array. +- [`@stdlib/stats/strided/variance`][@stdlib/stats/strided/variance]: calculate the variance of a strided array. - [`@stdlib/stats/strided/svariance`][@stdlib/stats/strided/svariance]: calculate the variance of a single-precision floating-point strided array. @@ -367,7 +367,7 @@ int main( void ) { [@stdlib/stats/strided/dvariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dvariance -[@stdlib/stats/base/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variance +[@stdlib/stats/strided/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variance [@stdlib/stats/strided/svariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariance diff --git a/lib/node_modules/@stdlib/stats/strided/dvariance/README.md b/lib/node_modules/@stdlib/stats/strided/dvariance/README.md index 424216decae9..ddea8cdca0dc 100644 --- a/lib/node_modules/@stdlib/stats/strided/dvariance/README.md +++ b/lib/node_modules/@stdlib/stats/strided/dvariance/README.md @@ -346,7 +346,7 @@ int main( void ) { - [`@stdlib/stats/strided/dstdev`][@stdlib/stats/strided/dstdev]: calculate the standard deviation of a double-precision floating-point strided array. - [`@stdlib/stats/strided/dvarm`][@stdlib/stats/strided/dvarm]: calculate the variance of a double-precision floating-point strided array provided a known mean. - [`@stdlib/stats/strided/svariance`][@stdlib/stats/strided/svariance]: calculate the variance of a single-precision floating-point strided array. -- [`@stdlib/stats/base/variance`][@stdlib/stats/base/variance]: calculate the variance of a strided array. +- [`@stdlib/stats/strided/variance`][@stdlib/stats/strided/variance]: calculate the variance of a strided array. @@ -372,7 +372,7 @@ int main( void ) { [@stdlib/stats/strided/svariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariance -[@stdlib/stats/base/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variance +[@stdlib/stats/strided/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variance diff --git a/lib/node_modules/@stdlib/stats/strided/svariance/README.md b/lib/node_modules/@stdlib/stats/strided/svariance/README.md index 43fd53debb74..b8cafd9a1509 100644 --- a/lib/node_modules/@stdlib/stats/strided/svariance/README.md +++ b/lib/node_modules/@stdlib/stats/strided/svariance/README.md @@ -345,7 +345,7 @@ int main( void ) { - [`@stdlib/stats/strided/dvariance`][@stdlib/stats/strided/dvariance]: calculate the variance of a double-precision floating-point strided array. - [`@stdlib/stats/base/snanvariance`][@stdlib/stats/base/snanvariance]: calculate the variance of a single-precision floating-point strided array ignoring NaN values. - [`@stdlib/stats/strided/sstdev`][@stdlib/stats/strided/sstdev]: calculate the standard deviation of a single-precision floating-point strided array. -- [`@stdlib/stats/base/variance`][@stdlib/stats/base/variance]: calculate the variance of a strided array. +- [`@stdlib/stats/strided/variance`][@stdlib/stats/strided/variance]: calculate the variance of a strided array. @@ -369,7 +369,7 @@ int main( void ) { [@stdlib/stats/strided/sstdev]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/sstdev -[@stdlib/stats/base/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variance +[@stdlib/stats/strided/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variance diff --git a/lib/node_modules/@stdlib/stats/strided/variancech/README.md b/lib/node_modules/@stdlib/stats/strided/variancech/README.md index 61e92a5e7b15..3d24e003cb51 100644 --- a/lib/node_modules/@stdlib/stats/strided/variancech/README.md +++ b/lib/node_modules/@stdlib/stats/strided/variancech/README.md @@ -230,7 +230,7 @@ console.log( v ); - [`@stdlib/stats/strided/dvariancech`][@stdlib/stats/strided/dvariancech]: calculate the variance of a double-precision floating-point strided array using a one-pass trial mean algorithm. - [`@stdlib/stats/base/nanvariancech`][@stdlib/stats/base/nanvariancech]: calculate the variance of a strided array ignoring NaN values and using a one-pass trial mean algorithm. - [`@stdlib/stats/base/stdevch`][@stdlib/stats/base/stdevch]: calculate the standard deviation of a strided array using a one-pass trial mean algorithm. -- [`@stdlib/stats/base/variance`][@stdlib/stats/base/variance]: calculate the variance of a strided array. +- [`@stdlib/stats/strided/variance`][@stdlib/stats/strided/variance]: calculate the variance of a strided array. @@ -266,7 +266,7 @@ console.log( v ); [@stdlib/stats/base/stdevch]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/stdevch -[@stdlib/stats/base/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variance +[@stdlib/stats/strided/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variance diff --git a/lib/node_modules/@stdlib/stats/strided/variancepn/README.md b/lib/node_modules/@stdlib/stats/strided/variancepn/README.md index a44c7f82f427..824ae9cd7f66 100644 --- a/lib/node_modules/@stdlib/stats/strided/variancepn/README.md +++ b/lib/node_modules/@stdlib/stats/strided/variancepn/README.md @@ -227,7 +227,7 @@ console.log( v ); - [`@stdlib/stats/strided/dvariancepn`][@stdlib/stats/strided/dvariancepn]: calculate the variance of a double-precision floating-point strided array using a two-pass algorithm. - [`@stdlib/stats/base/nanvariancepn`][@stdlib/stats/base/nanvariancepn]: calculate the variance of a strided array ignoring NaN values and using a two-pass algorithm. - [`@stdlib/stats/base/stdevpn`][@stdlib/stats/base/stdevpn]: calculate the standard deviation of a strided array using a two-pass algorithm. -- [`@stdlib/stats/base/variance`][@stdlib/stats/base/variance]: calculate the variance of a strided array. +- [`@stdlib/stats/strided/variance`][@stdlib/stats/strided/variance]: calculate the variance of a strided array. @@ -259,7 +259,7 @@ console.log( v ); [@stdlib/stats/base/stdevpn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/stdevpn -[@stdlib/stats/base/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variance +[@stdlib/stats/strided/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variance diff --git a/lib/node_modules/@stdlib/stats/strided/variancetk/README.md b/lib/node_modules/@stdlib/stats/strided/variancetk/README.md index 4b359649e62c..48470cb89360 100644 --- a/lib/node_modules/@stdlib/stats/strided/variancetk/README.md +++ b/lib/node_modules/@stdlib/stats/strided/variancetk/README.md @@ -227,7 +227,7 @@ console.log( v ); - [`@stdlib/stats/strided/dvariancetk`][@stdlib/stats/strided/dvariancetk]: calculate the variance of a double-precision floating-point strided array using a one-pass textbook algorithm. - [`@stdlib/stats/base/nanvariancetk`][@stdlib/stats/base/nanvariancetk]: calculate the variance of a strided array ignoring NaN values and using a one-pass textbook algorithm. - [`@stdlib/stats/base/stdevtk`][@stdlib/stats/base/stdevtk]: calculate the standard deviation of a strided array using a one-pass textbook algorithm. -- [`@stdlib/stats/base/variance`][@stdlib/stats/base/variance]: calculate the variance of a strided array. +- [`@stdlib/stats/strided/variance`][@stdlib/stats/strided/variance]: calculate the variance of a strided array. @@ -257,7 +257,7 @@ console.log( v ); [@stdlib/stats/base/stdevtk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/stdevtk -[@stdlib/stats/base/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variance +[@stdlib/stats/strided/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variance diff --git a/lib/node_modules/@stdlib/stats/strided/variancewd/README.md b/lib/node_modules/@stdlib/stats/strided/variancewd/README.md index 4e4b750f5d2b..e22c3e9a84b1 100644 --- a/lib/node_modules/@stdlib/stats/strided/variancewd/README.md +++ b/lib/node_modules/@stdlib/stats/strided/variancewd/README.md @@ -227,7 +227,7 @@ console.log( v ); - [`@stdlib/stats/strided/dvariancewd`][@stdlib/stats/strided/dvariancewd]: calculate the variance of a double-precision floating-point strided array using Welford's algorithm. - [`@stdlib/stats/base/nanvariancewd`][@stdlib/stats/base/nanvariancewd]: calculate the variance of a strided array ignoring NaN values and using Welford's algorithm. - [`@stdlib/stats/base/stdevwd`][@stdlib/stats/base/stdevwd]: calculate the standard deviation of a strided array using Welford's algorithm. -- [`@stdlib/stats/base/variance`][@stdlib/stats/base/variance]: calculate the variance of a strided array. +- [`@stdlib/stats/strided/variance`][@stdlib/stats/strided/variance]: calculate the variance of a strided array. @@ -259,7 +259,7 @@ console.log( v ); [@stdlib/stats/base/stdevwd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/stdevwd -[@stdlib/stats/base/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variance +[@stdlib/stats/strided/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variance diff --git a/lib/node_modules/@stdlib/stats/strided/varianceyc/README.md b/lib/node_modules/@stdlib/stats/strided/varianceyc/README.md index d19a26b562d7..f161630800dd 100644 --- a/lib/node_modules/@stdlib/stats/strided/varianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/strided/varianceyc/README.md @@ -226,7 +226,7 @@ console.log( v ); - [`@stdlib/stats/strided/dvarianceyc`][@stdlib/stats/strided/dvarianceyc]: calculate the variance of a double-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. - [`@stdlib/stats/base/nanvarianceyc`][@stdlib/stats/base/nanvarianceyc]: calculate the variance of a strided array ignoring NaN values and using a one-pass algorithm proposed by Youngs and Cramer. - [`@stdlib/stats/base/stdevyc`][@stdlib/stats/base/stdevyc]: calculate the standard deviation of a strided array using a one-pass algorithm proposed by Youngs and Cramer. -- [`@stdlib/stats/base/variance`][@stdlib/stats/base/variance]: calculate the variance of a strided array. +- [`@stdlib/stats/strided/variance`][@stdlib/stats/strided/variance]: calculate the variance of a strided array. @@ -256,7 +256,7 @@ console.log( v ); [@stdlib/stats/base/stdevyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/stdevyc -[@stdlib/stats/base/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variance +[@stdlib/stats/strided/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/variance diff --git a/lib/node_modules/@stdlib/stats/ttest/lib/main.js b/lib/node_modules/@stdlib/stats/ttest/lib/main.js index 7b77384ae397..3059ef66a34e 100644 --- a/lib/node_modules/@stdlib/stats/ttest/lib/main.js +++ b/lib/node_modules/@stdlib/stats/ttest/lib/main.js @@ -30,7 +30,7 @@ var format = require( '@stdlib/string/format' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); var abs = require( '@stdlib/math/base/special/abs' ); var mean = require( '@stdlib/stats/strided/mean' ); -var variance = require( '@stdlib/stats/base/variance' ); +var variance = require( '@stdlib/stats/strided/variance' ); var gcopy = require( '@stdlib/blas/base/gcopy' ); var NINF = require( '@stdlib/constants/float64/ninf' ); var PINF = require( '@stdlib/constants/float64/pinf' ); diff --git a/lib/node_modules/@stdlib/stats/ttest2/lib/main.js b/lib/node_modules/@stdlib/stats/ttest2/lib/main.js index cdfc96d60292..51fbca7b3c61 100644 --- a/lib/node_modules/@stdlib/stats/ttest2/lib/main.js +++ b/lib/node_modules/@stdlib/stats/ttest2/lib/main.js @@ -29,7 +29,7 @@ var sqrt = require( '@stdlib/math/base/special/sqrt' ); var abs = require( '@stdlib/math/base/special/abs' ); var pow = require( '@stdlib/math/base/special/pow' ); var mean = require( '@stdlib/stats/strided/mean' ); -var variance = require( '@stdlib/stats/base/variance' ); +var variance = require( '@stdlib/stats/strided/variance' ); var format = require( '@stdlib/string/format' ); var NINF = require( '@stdlib/constants/float64/ninf' ); var PINF = require( '@stdlib/constants/float64/pinf' ); diff --git a/lib/node_modules/@stdlib/stats/vartest/lib/main.js b/lib/node_modules/@stdlib/stats/vartest/lib/main.js index ee82cac9680d..8af39664aea5 100644 --- a/lib/node_modules/@stdlib/stats/vartest/lib/main.js +++ b/lib/node_modules/@stdlib/stats/vartest/lib/main.js @@ -25,7 +25,7 @@ var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); var fCDF = require( '@stdlib/stats/base/dists/f/cdf' ); var fQuantile = require( '@stdlib/stats/base/dists/f/quantile' ); -var variance = require( '@stdlib/stats/base/variance' ); +var variance = require( '@stdlib/stats/strided/variance' ); var format = require( '@stdlib/string/format' ); var min = require( '@stdlib/math/base/special/min' ); var PINF = require( '@stdlib/constants/float64/pinf' ); From a1991eadd5b3b5a718363eaa70cd325866574bc5 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 1 Jul 2025 14:41:57 +0000 Subject: [PATCH 29/32] remove: remove `stats/base/variance` This commit removes `@stdlib/stats/base/variance` in favor of `@stdlib/stats/strided/variance`. BREAKING CHANGE: remove `stats/base/variance` To migrate, users should update their require/import paths to use `@stdlib/stats/strided/variance`, which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/variance/README.md | 255 ------------- .../base/variance/benchmark/benchmark.js | 96 ----- .../variance/benchmark/benchmark.ndarray.js | 96 ----- .../docs/img/equation_population_mean.svg | 42 -- .../docs/img/equation_population_variance.svg | 54 --- .../docs/img/equation_sample_mean.svg | 43 --- .../img/equation_unbiased_sample_variance.svg | 61 --- .../@stdlib/stats/base/variance/docs/repl.txt | 113 ------ .../stats/base/variance/docs/types/index.d.ts | 96 ----- .../stats/base/variance/docs/types/test.ts | 190 --------- .../stats/base/variance/examples/index.js | 30 -- .../@stdlib/stats/base/variance/lib/index.js | 52 --- .../@stdlib/stats/base/variance/lib/main.js | 35 -- .../stats/base/variance/lib/ndarray.js | 51 --- .../stats/base/variance/lib/variance.js | 50 --- .../@stdlib/stats/base/variance/package.json | 73 ---- .../@stdlib/stats/base/variance/test/test.js | 38 -- .../stats/base/variance/test/test.ndarray.js | 350 ----------------- .../stats/base/variance/test/test.variance.js | 359 ------------------ 19 files changed, 2084 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/README.md delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/benchmark/benchmark.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_population_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_population_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_sample_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_unbiased_sample_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/examples/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/lib/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/lib/main.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/lib/ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/lib/variance.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/package.json delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/test/test.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/test/test.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/variance/test/test.variance.js diff --git a/lib/node_modules/@stdlib/stats/base/variance/README.md b/lib/node_modules/@stdlib/stats/base/variance/README.md deleted file mode 100644 index 59c07af9c479..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/README.md +++ /dev/null @@ -1,255 +0,0 @@ - - -# variance - -> Calculate the [variance][variance] of a strided array. - -
- -The population [variance][variance] of a finite size population of size `N` is given by - - - -```math -\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 -``` - - - - - -where the population mean is given by - - - -```math -\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i -``` - - - - - -Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, - - - -```math -s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 -``` - - - - - -where the sample mean is given by - - - -```math -\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i -``` - - - - - -The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. - -
- - - -
- -## Usage - -```javascript -var variance = require( '@stdlib/stats/base/variance' ); -``` - -#### variance( N, correction, x, strideX ) - -Computes the [variance][variance] of a strided array. - -```javascript -var x = [ 1.0, -2.0, 2.0 ]; - -var v = variance( x.length, 1, x, 1 ); -// returns ~4.3333 -``` - -The function has the following parameters: - -- **N**: number of indexed elements. -- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. -- **strideX**: stride length for `x`. - -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, - -```javascript -var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; - -var v = variance( 4, 1, x, 2 ); -// returns 6.25 -``` - -Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); - -var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - -var v = variance( 4, 1, x1, 2 ); -// returns 6.25 -``` - -#### variance.ndarray( N, correction, x, strideX, offsetX ) - -Computes the [variance][variance] of a strided array using alternative indexing semantics. - -```javascript -var x = [ 1.0, -2.0, 2.0 ]; - -var v = variance.ndarray( x.length, 1, x, 1, 0 ); -// returns ~4.33333 -``` - -The function has the following additional parameters: - -- **offsetX**: starting index for `x`. - -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element - -```javascript -var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; - -var v = variance.ndarray( 4, 1, x, 2, 1 ); -// returns 6.25 -``` - -
- - - -
- -## Notes - -- If `N <= 0`, both functions return `NaN`. -- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. -- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). -- Depending on the environment, the typed versions ([`dvariance`][@stdlib/stats/strided/dvariance], [`svariance`][@stdlib/stats/strided/svariance], etc.) are likely to be significantly more performant. - -
- - - -
- -## Examples - - - -```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var variance = require( '@stdlib/stats/base/variance' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); -console.log( x ); - -var v = variance( x.length, 1, x, 1 ); -console.log( v ); -``` - -
- - - -
- -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/stats/base/variance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/variance/benchmark/benchmark.js deleted file mode 100644 index 5575120b06ab..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/benchmark/benchmark.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var variance = require( './../lib/main.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = variance( x.length, 1, x, 1 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/variance/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/variance/benchmark/benchmark.ndarray.js deleted file mode 100644 index c02c1ba01b37..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var variance = require( './../lib/ndarray.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = variance( x.length, 1, x, 1, 0 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':ndarray:len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_population_mean.svg deleted file mode 100644 index 4bbdf0d2a56f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_population_mean.svg +++ /dev/null @@ -1,42 +0,0 @@ - -mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_population_variance.svg deleted file mode 100644 index 4130ba0750d2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_population_variance.svg +++ /dev/null @@ -1,54 +0,0 @@ - -sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_sample_mean.svg deleted file mode 100644 index aea7a5f6687a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_sample_mean.svg +++ /dev/null @@ -1,43 +0,0 @@ - -x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_unbiased_sample_variance.svg deleted file mode 100644 index 1ae1283e7fb1..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/docs/img/equation_unbiased_sample_variance.svg +++ /dev/null @@ -1,61 +0,0 @@ - -s squared equals 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 - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/variance/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/variance/docs/repl.txt deleted file mode 100644 index 8f5c3fb9ddd5..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/docs/repl.txt +++ /dev/null @@ -1,113 +0,0 @@ - -{{alias}}( N, correction, x, strideX ) - Computes the variance of a strided array. - - The `N` and stride parameters determine which elements in the strided array - are accessed at runtime. - - Indexing is relative to the first index. To introduce an offset, use a typed - array view. - - If `N <= 0`, the function returns `NaN`. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Array|TypedArray - Input array. - - strideX: integer - Stride length. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = [ 1.0, -2.0, 2.0 ]; - > {{alias}}( x.length, 1, x, 1 ) - ~4.3333 - - // Using `N` and stride parameters: - > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; - > {{alias}}( 3, 1, x, 2 ) - ~4.3333 - - // Using view offsets: - > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 1, x1, 2 ) - ~4.3333 - - -{{alias}}.ndarray( N, correction, x, strideX, offsetX ) - Computes the variance of a strided array using alternative indexing - semantics. - - While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a - starting index. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Array|TypedArray - Input array. - - strideX: integer - Stride length. - - offsetX: integer - Starting index. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = [ 1.0, -2.0, 2.0 ]; - > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) - ~4.3333 - - // Using offset parameter: - > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; - > {{alias}}.ndarray( 3, 1, x, 2, 1 ) - ~4.3333 - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/stats/base/variance/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/variance/docs/types/index.d.ts deleted file mode 100644 index 5d58b7b3268a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/docs/types/index.d.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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 - -/// - -import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; - -/** -* Input array. -*/ -type InputArray = NumericArray | Collection | AccessorArrayLike; - -/** -* Interface describing `variance`. -*/ -interface Routine { - /** - * Computes the variance of a strided array. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = variance( x.length, 1, x, 1 ); - * // returns ~4.3333 - */ - ( N: number, correction: number, x: InputArray, strideX: number ): number; - - /** - * Computes the variance of a strided array using alternative indexing semantics. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @param offsetX - starting index - * @returns variance - * - * @example - * var x = [ 1.0, -2.0, 2.0 ]; - * - * var v = variance.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - ndarray( N: number, correction: number, x: InputArray, strideX: number, offsetX: number ): number; -} - -/** -* Computes the variance of a strided array. -* -* @param N - number of indexed elements -* @param correction - degrees of freedom adjustment -* @param x - input array -* @param strideX - stride length -* @returns variance -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variance( x.length, 1, x, 1 ); -* // returns ~4.3333 -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variance.ndarray( x.length, 1, x, 1, 0 ); -* // returns ~4.3333 -*/ -declare var variance: Routine; - - -// EXPORTS // - -export = variance; diff --git a/lib/node_modules/@stdlib/stats/base/variance/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/variance/docs/types/test.ts deleted file mode 100644 index 09e2570ecc52..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/docs/types/test.ts +++ /dev/null @@ -1,190 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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 AccessorArray = require( '@stdlib/array/base/accessor' ); -import variance = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const x = new Float64Array( 10 ); - - variance( x.length, 1, x, 1 ); // $ExpectType number - variance( x.length, 1, new AccessorArray( x ), 1 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variance( '10', 1, x, 1 ); // $ExpectError - variance( true, 1, x, 1 ); // $ExpectError - variance( false, 1, x, 1 ); // $ExpectError - variance( null, 1, x, 1 ); // $ExpectError - variance( undefined, 1, x, 1 ); // $ExpectError - variance( [], 1, x, 1 ); // $ExpectError - variance( {}, 1, x, 1 ); // $ExpectError - variance( ( x: number ): number => x, 1, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variance( x.length, '10', x, 1 ); // $ExpectError - variance( x.length, true, x, 1 ); // $ExpectError - variance( x.length, false, x, 1 ); // $ExpectError - variance( x.length, null, x, 1 ); // $ExpectError - variance( x.length, undefined, x, 1 ); // $ExpectError - variance( x.length, [], x, 1 ); // $ExpectError - variance( x.length, {}, x, 1 ); // $ExpectError - variance( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a numeric array... -{ - const x = new Float64Array( 10 ); - - variance( x.length, 1, 10, 1 ); // $ExpectError - variance( x.length, 1, '10', 1 ); // $ExpectError - variance( x.length, 1, true, 1 ); // $ExpectError - variance( x.length, 1, false, 1 ); // $ExpectError - variance( x.length, 1, null, 1 ); // $ExpectError - variance( x.length, 1, undefined, 1 ); // $ExpectError - variance( x.length, 1, [ '1' ], 1 ); // $ExpectError - variance( x.length, 1, {}, 1 ); // $ExpectError - variance( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variance( x.length, 1, x, '10' ); // $ExpectError - variance( x.length, 1, x, true ); // $ExpectError - variance( x.length, 1, x, false ); // $ExpectError - variance( x.length, 1, x, null ); // $ExpectError - variance( x.length, 1, x, undefined ); // $ExpectError - variance( x.length, 1, x, [] ); // $ExpectError - variance( x.length, 1, x, {} ); // $ExpectError - variance( x.length, 1, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - - variance(); // $ExpectError - variance( x.length ); // $ExpectError - variance( x.length, 1 ); // $ExpectError - variance( x.length, 1, x ); // $ExpectError - variance( x.length, 1, x, 1, 10 ); // $ExpectError -} - -// Attached to main export is an `ndarray` method which returns a number... -{ - const x = new Float64Array( 10 ); - - variance.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number - variance.ndarray( x.length, 1, new AccessorArray( x ), 1, 0 ); // $ExpectType number -} - -// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variance.ndarray( '10', 1, x, 1, 0 ); // $ExpectError - variance.ndarray( true, 1, x, 1, 0 ); // $ExpectError - variance.ndarray( false, 1, x, 1, 0 ); // $ExpectError - variance.ndarray( null, 1, x, 1, 0 ); // $ExpectError - variance.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError - variance.ndarray( [], 1, x, 1, 0 ); // $ExpectError - variance.ndarray( {}, 1, x, 1, 0 ); // $ExpectError - variance.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variance.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError - variance.ndarray( x.length, true, x, 1, 0 ); // $ExpectError - variance.ndarray( x.length, false, x, 1, 0 ); // $ExpectError - variance.ndarray( x.length, null, x, 1, 0 ); // $ExpectError - variance.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError - variance.ndarray( x.length, [], x, 1, 0 ); // $ExpectError - variance.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError - variance.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... -{ - const x = new Float64Array( 10 ); - - variance.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError - variance.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError - variance.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError - variance.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError - variance.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError - variance.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError - variance.ndarray( x.length, 1, [ '1' ], 1, 0 ); // $ExpectError - variance.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError - variance.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variance.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError - variance.ndarray( x.length, 1, x, true, 0 ); // $ExpectError - variance.ndarray( x.length, 1, x, false, 0 ); // $ExpectError - variance.ndarray( x.length, 1, x, null, 0 ); // $ExpectError - variance.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError - variance.ndarray( x.length, 1, x, [], 0 ); // $ExpectError - variance.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError - variance.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... -{ - const x = new Float64Array( 10 ); - - variance.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError - variance.ndarray( x.length, 1, x, 1, true ); // $ExpectError - variance.ndarray( x.length, 1, x, 1, false ); // $ExpectError - variance.ndarray( x.length, 1, x, 1, null ); // $ExpectError - variance.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError - variance.ndarray( x.length, 1, x, 1, [] ); // $ExpectError - variance.ndarray( x.length, 1, x, 1, {} ); // $ExpectError - variance.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - - variance.ndarray(); // $ExpectError - variance.ndarray( x.length ); // $ExpectError - variance.ndarray( x.length, 1 ); // $ExpectError - variance.ndarray( x.length, 1, x ); // $ExpectError - variance.ndarray( x.length, 1, x, 1 ); // $ExpectError - variance.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/stats/base/variance/examples/index.js b/lib/node_modules/@stdlib/stats/base/variance/examples/index.js deleted file mode 100644 index ccf70cf0735d..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/examples/index.js +++ /dev/null @@ -1,30 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var variance = require( './../lib' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); -console.log( x ); - -var v = variance( x.length, 1, x, 1 ); -console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/variance/lib/index.js b/lib/node_modules/@stdlib/stats/base/variance/lib/index.js deleted file mode 100644 index 6c3febfc6bec..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/lib/index.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 the variance of a strided array. -* -* @module @stdlib/stats/base/variance -* -* @example -* var variance = require( '@stdlib/stats/base/variance' ); -* -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variance( x.length, 1, x, 1 ); -* // returns ~4.3333 -* -* @example -* var variance = require( '@stdlib/stats/base/variance' ); -* -* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* -* var v = variance.ndarray( 4, 1, x, 2, 1 ); -* // returns 6.25 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/base/variance/lib/main.js b/lib/node_modules/@stdlib/stats/base/variance/lib/main.js deleted file mode 100644 index d7ff74d08f57..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/lib/main.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var variance = require( './variance.js' ); -var ndarray = require( './ndarray.js' ); - - -// MAIN // - -setReadOnly( variance, 'ndarray', ndarray ); - - -// EXPORTS // - -module.exports = variance; diff --git a/lib/node_modules/@stdlib/stats/base/variance/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/variance/lib/ndarray.js deleted file mode 100644 index 1cd7667fb326..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/lib/ndarray.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 variancepn = require( '@stdlib/stats/strided/variancepn' ).ndarray; - - -// MAIN // - -/** -* Computes the variance of a strided array. -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index -* @returns {number} variance -* -* @example -* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* -* var v = variance( 4, 1, x, 2, 1 ); -* // returns 6.25 -*/ -function variance( N, correction, x, strideX, offsetX ) { - return variancepn( N, correction, x, strideX, offsetX ); -} - - -// EXPORTS // - -module.exports = variance; diff --git a/lib/node_modules/@stdlib/stats/base/variance/lib/variance.js b/lib/node_modules/@stdlib/stats/base/variance/lib/variance.js deleted file mode 100644 index 90873fa2cf62..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/lib/variance.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 variancepn = require( '@stdlib/stats/strided/variancepn' ); - - -// MAIN // - -/** -* Computes the variance of a strided array. -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array -* @param {integer} strideX - stride length -* @returns {number} variance -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = variance( x.length, 1, x, 1 ); -* // returns ~4.3333 -*/ -function variance( N, correction, x, strideX ) { - return variancepn( N, correction, x, strideX ); -} - - -// EXPORTS // - -module.exports = variance; diff --git a/lib/node_modules/@stdlib/stats/base/variance/package.json b/lib/node_modules/@stdlib/stats/base/variance/package.json deleted file mode 100644 index e720addb6b3d..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/package.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "name": "@stdlib/stats/base/variance", - "version": "0.0.0", - "description": "Calculate the variance of a strided array.", - "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", - "var", - "deviation", - "dispersion", - "sample variance", - "unbiased", - "stdev", - "std", - "standard deviation", - "strided", - "strided array", - "typed", - "array" - ], - "__stdlib__": {} -} diff --git a/lib/node_modules/@stdlib/stats/base/variance/test/test.js b/lib/node_modules/@stdlib/stats/base/variance/test/test.js deleted file mode 100644 index af6863992aaf..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/test/test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 variance = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variance, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { - t.strictEqual( typeof variance.ndarray, 'function', 'method is a function' ); - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/variance/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/variance/test/test.ndarray.js deleted file mode 100644 index 9fe2c9e1bfc2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/test/test.ndarray.js +++ /dev/null @@ -1,350 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -var variance = require( './../lib/ndarray.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variance, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( variance.length, 5, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variance( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variance( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variance( x.length, 0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variance( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variance( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variance( x.length, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variance( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variance( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variance( x.length, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variance( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variance( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variance( x.length, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( 0, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variance( -1, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( 0, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variance( -1, 1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( 1, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( 1, 0, toAccessorArray( x ), 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variance( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( x.length, x.length, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variance( x.length, x.length+1, toAccessorArray( x ), 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variance( 4, 1, x, 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variance( 4, 1, toAccessorArray( x ), 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variance( 4, 1, x, -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variance( 4, 1, toAccessorArray( x ), -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( x.length, 1, x, 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( x.length, 1, toAccessorArray( x ), 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter', function test( t ) { - var x; - var v; - - x = [ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]; - - v = variance( 4, 1, x, 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]; - - v = variance( 4, 1, toAccessorArray( x ), 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/variance/test/test.variance.js b/lib/node_modules/@stdlib/stats/base/variance/test/test.variance.js deleted file mode 100644 index 6c76484c1a9c..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variance/test/test.variance.js +++ /dev/null @@ -1,359 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var Float64Array = require( '@stdlib/array/float64' ); -var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -var variance = require( './../lib/variance.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof variance, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( variance.length, 4, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variance( x.length, 0, x, 1 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variance( x.length, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variance( x.length, 0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variance( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 53.5/x.length, 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variance( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variance( x.length, 0, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variance( x.length, 1, x, 1 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variance( x.length, 1, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variance( x.length, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = variance( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); - - x = [ -4.0, -4.0 ]; - v = variance( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = [ NaN, 4.0 ]; - v = variance( x.length, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( 0, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variance( -1, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( 0, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variance( -1, 1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( 1, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( 1, 0, toAccessorArray( x ), 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variance( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( x.length, x.length, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = variance( x.length, x.length+1, toAccessorArray( x ), 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variance( 4, 1, x, 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]; - - v = variance( 4, 1, toAccessorArray( x ), 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variance( 4, 1, x, -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = variance( 4, 1, toAccessorArray( x ), -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( x.length, 1, x, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = variance( x.length, 1, toAccessorArray( x ), 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float64Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = variance( 4, 1, x1, 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets (accessors)', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float64Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = variance( 4, 1, toAccessorArray( x1 ), 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); From ae34cce2706107d6738b4830d43e4130ff7399e4 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 1 Jul 2025 09:30:41 -0500 Subject: [PATCH 30/32] fix: update `caxpy` manifest to include missing dependencies for Mac builds --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/base/caxpy/manifest.json | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/manifest.json b/lib/node_modules/@stdlib/blas/base/caxpy/manifest.json index b49aaf1f1f53..440871cf3483 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/caxpy/manifest.json @@ -191,13 +191,16 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/blas/base/scabs1", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", - "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex64array", "@stdlib/napi/argv-complex64", - "@stdlib/complex/float32/ctor" + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/base/add", + "@stdlib/complex/float32/base/mul" ] }, { @@ -218,14 +221,9 @@ "@stdlib/blas/base/shared", "@stdlib/blas/base/scabs1", "@stdlib/strided/base/stride2offset", - "@stdlib/napi/export", - "@stdlib/napi/argv", - "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-complex64array", - "@stdlib/napi/argv-complex64", - "@stdlib/complex/float32/ctor", "@stdlib/complex/float32/base/add", - "@stdlib/complex/float32/base/mul" + "@stdlib/complex/float32/base/mul", + "@stdlib/complex/float32/ctor" ] }, { From 83af59de17b7e0db3d95fb5959ec0f38cf63c88e Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 1 Jul 2025 10:49:08 -0500 Subject: [PATCH 31/32] test: increase needed tolerances for tests to pass --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/base/dists/betaprime/logpdf/test/test.native.js | 2 +- .../stats/base/dists/kumaraswamy/stdev/test/test.native.js | 2 +- .../base/dists/kumaraswamy/variance/test/test.native.js | 2 +- .../stats/base/dists/laplace/quantile/test/test.native.js | 6 +++--- .../base/dists/pareto-type1/logpdf/test/test.native.js | 6 +++--- .../base/dists/triangular/skewness/test/test.native.js | 4 +++- .../stats/base/dists/triangular/stdev/test/test.native.js | 4 +++- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/betaprime/logpdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/betaprime/logpdf/test/test.native.js index 31d44939c6fa..b7e92007b612 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/betaprime/logpdf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/betaprime/logpdf/test/test.native.js @@ -146,7 +146,7 @@ tape( 'the function evaluates the logpdf for `x` given large `alpha` and `beta`' t.equal( y, expected[i], 'x: '+x[i]+', alpha: '+alpha[i]+', beta: '+beta[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[ i ] ); - tol = 22000.0 * EPS * abs( expected[ i ] ); + tol = 23500.0 * EPS * abs( expected[ i ] ); t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. alpha: '+alpha[i]+'. beta: '+beta[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/stdev/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/stdev/test/test.native.js index 2c39fbb76974..90136128e055 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/stdev/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/stdev/test/test.native.js @@ -140,7 +140,7 @@ tape( 'the function returns the standard deviation of a Kumaraswamy\'s double bo * - Subtraction precision loss when m₂ ≈ m₁² * - Square root operation amplifying small errors */ - tol = 10000 * EPS * abs( expected[ i ] ); + tol = 18500 * EPS * abs( expected[ i ] ); t.ok( delta <= tol, 'within tolerance. a: '+a[i]+'. b: '+b[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/variance/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/variance/test/test.native.js index b85c2e527d5b..ab075ae705d5 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/variance/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/variance/test/test.native.js @@ -133,7 +133,7 @@ tape( 'the function returns the variance of a Kumaraswamy\'s double bounded dist t.equal( y, expected[i], 'a: '+a[i]+', b: '+b[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[ i ] ); - tol = 15000.0 * EPS * abs( expected[ i ] ); + tol = 17500.0 * EPS * abs( expected[ i ] ); t.ok( delta <= tol, 'within tolerance. a: '+a[i]+'. b: '+b[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/laplace/quantile/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/laplace/quantile/test/test.native.js index cb0acd4f9237..aab39314937b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/laplace/quantile/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/laplace/quantile/test/test.native.js @@ -122,7 +122,7 @@ tape( 'the function evaluates the quantile function at `p` given positive `mu`', t.equal( y, expected[i], 'p: '+p[i]+', mu:'+mu[i]+', b: '+b[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[ i ] ); - tol = 1.0 * EPS * abs( expected[ i ] ); + tol = 500.0 * EPS * abs( expected[ i ] ); t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. mu: '+mu[i]+'. b: '+b[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); } } @@ -151,7 +151,7 @@ tape( 'the function evaluates the quantile function at `p` given negative `mu`', t.equal( y, expected[i], 'p: '+p[i]+', mu:'+mu[i]+', b: '+b[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[ i ] ); - tol = 1.0 * EPS * abs( expected[ i ] ); + tol = 500.0 * EPS * abs( expected[ i ] ); t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. mu: '+mu[i]+'. b: '+b[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); } } @@ -180,7 +180,7 @@ tape( 'the function evaluates the quantile function at `p` given large variance t.equal( y, expected[i], 'p: '+p[i]+', mu:'+mu[i]+', b: '+b[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[ i ] ); - tol = 1.0 * EPS * abs( expected[ i ] ); + tol = 500.0 * EPS * abs( expected[ i ] ); t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. mu: '+mu[i]+'. b: '+b[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/pareto-type1/logpdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/pareto-type1/logpdf/test/test.native.js index 2be8d2d27f43..9f7dccd42f49 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/pareto-type1/logpdf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/pareto-type1/logpdf/test/test.native.js @@ -150,7 +150,7 @@ tape( 'the function evaluates the logpdf for `x` given large `alpha` and `beta`' t.equal( y, expected[i], 'x: '+x[i]+', alpha: '+alpha[i]+', beta: '+beta[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[ i ] ); - tol = 40.0 * EPS * abs( expected[ i ] ); + tol = 5000.0 * EPS * abs( expected[ i ] ); t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. alpha: '+alpha[i]+'. beta: '+beta[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); } } @@ -177,7 +177,7 @@ tape( 'the function evaluates the logpdf for `x` given large parameter `alpha`', t.equal( y, expected[i], 'x: '+x[i]+', alpha: '+alpha[i]+', beta: '+beta[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[ i ] ); - tol = 40.0 * EPS * abs( expected[ i ] ); + tol = 5000.0 * EPS * abs( expected[ i ] ); t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. alpha: '+alpha[i]+'. beta: '+beta[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); } } @@ -204,7 +204,7 @@ tape( 'the function evaluates the logpdf for `x` given large parameter `beta`', t.equal( y, expected[i], 'x: '+x[i]+', alpha: '+alpha[i]+', beta: '+beta[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[ i ] ); - tol = 20.0 * EPS * abs( expected[ i ] ); + tol = 5000.0 * EPS * abs( expected[ i ] ); t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. alpha: '+alpha[i]+'. beta: '+beta[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/skewness/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/triangular/skewness/test/test.native.js index d42df8a5d728..1d6c222c5b42 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/skewness/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/skewness/test/test.native.js @@ -100,7 +100,9 @@ tape( 'the function returns the skewness of a triangular distribution', opts, fu t.equal( y, expected[i], 'a: '+a[i]+', b: '+b[i]+', c: '+c[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[ i ] ); - tol = 1.0 * EPS * abs( expected[ i ] ); + + // Note: large tolerance needed due to FMA (fused multiply-add) operations. With CFLAGS="-ffp-contract=off", tolerance can be 1.0 * EPS. + tol = 48000.0 * EPS * abs( expected[ i ] ); t.ok( delta <= tol, 'within tolerance. a: '+a[i]+'. b: '+b[i]+'. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/stdev/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/triangular/stdev/test/test.native.js index f6e20c60d449..10bc22ce25c3 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/stdev/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/stdev/test/test.native.js @@ -100,7 +100,9 @@ tape( 'the function returns the standard deviation of a triangular distribution' t.equal( y, expected[i], 'a: '+a[i]+', b: '+b[i]+', c: '+c[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[ i ] ); - tol = 1.0 * EPS * abs( expected[ i ] ); + + // Note: large tolerance needed due to FMA (fused multiply-add) operations. With CFLAGS="-ffp-contract=off", tolerance can be 1.0 * EPS. + tol = 32000.0 * EPS * abs( expected[ i ] ); t.ok( delta <= tol, 'within tolerance. a: '+a[i]+'. b: '+b[i]+'. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); } } From e588c9ad63a7b8a5d5c1f3c246a24aac438ac158 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Tue, 1 Jul 2025 23:32:36 +0500 Subject: [PATCH 32/32] feat: add `blas/ext/base/ndarray/dindex-of` PR-URL: https://github.com/stdlib-js/stdlib/pull/7539 Ref: https://github.com/stdlib-js/stdlib/issues/2656 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../blas/ext/base/ndarray/dindex-of/README.md | 159 ++++++++++++++++++ .../ndarray/dindex-of/benchmark/benchmark.js | 112 ++++++++++++ .../ext/base/ndarray/dindex-of/docs/repl.txt | 40 +++++ .../ndarray/dindex-of/docs/types/index.d.ts | 56 ++++++ .../base/ndarray/dindex-of/docs/types/test.ts | 70 ++++++++ .../base/ndarray/dindex-of/examples/index.js | 45 +++++ .../ext/base/ndarray/dindex-of/lib/index.js | 54 ++++++ .../ext/base/ndarray/dindex-of/lib/main.js | 96 +++++++++++ .../ext/base/ndarray/dindex-of/package.json | 65 +++++++ .../ext/base/ndarray/dindex-of/test/test.js | 158 +++++++++++++++++ 10 files changed, 855 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/README.md new file mode 100644 index 000000000000..82f2319cecab --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/README.md @@ -0,0 +1,159 @@ + + +# dindexOf + +> Return the first index of a search element in a one-dimensional double-precision floating-point ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var dindexOf = require( '@stdlib/blas/ext/base/ndarray/dindex-of' ); +``` + +#### dindexOf( arrays ) + +Returns the first index of a specified search element in a one-dimensional double-precision floating-point ndarray. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = new Float64Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float64' +}); + +var fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' +}); + +var idx = dindexOf( [ x, searchElement, fromIndex ] ); +// returns 3 +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the search element. + - a zero-dimensional ndarray containing the index from which to begin searching. + +If the function is unable to find a search element, the function returns `-1`. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = new Float64Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var searchElement = scalar2ndarray( 10.0, { + 'dtype': 'float64' +}); + +var fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' +}); + +var idx = dindexOf( [ x, searchElement, fromIndex ] ); +// returns -1 +``` + +
+ + + +
+ +## Notes + +- If a specified starting search index is negative, the function resolves the starting search index by counting backward from the last element (where `-1` refers to the last element). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var dindexOf = require( '@stdlib/blas/ext/base/ndarray/dindex-of' ); + +var xbuf = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); +var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var searchElement = scalar2ndarray( 80.0, { + 'dtype': 'float64' +}); +console.log( 'Search Element:', ndarraylike2scalar( searchElement ) ); + +var fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' +}); +console.log( 'From Index:', ndarraylike2scalar( fromIndex ) ); + +var idx = dindexOf( [ x, searchElement, fromIndex ] ); +console.log( idx ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/benchmark/benchmark.js new file mode 100644 index 000000000000..0a4cb167826a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/benchmark/benchmark.js @@ -0,0 +1,112 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var pkg = require( './../package.json' ).name; +var dindexOf = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var searchElement; + var fromIndex; + var xbuf; + var x; + + xbuf = uniform( len, 0.0, 100.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + searchElement = scalar2ndarray( -10.0, { + 'dtype': 'float64' + }); + fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = dindexOf( [ x, searchElement, fromIndex ] ); + if ( out !== out ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/docs/repl.txt new file mode 100644 index 000000000000..0f728a158998 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/docs/repl.txt @@ -0,0 +1,40 @@ + +{{alias}}( arrays ) + Returns the first index of a search element in a one-dimensional double- + precision floating-point ndarray. + + If a specified starting search index is negative, the function resolves the + starting search index by counting backward from the last element (where `-1` + refers to the last element). + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the search element. + - a zero-dimensional ndarray containing the index from which to begin + searching. + + Returns + ------- + out: integer + Index. + + Examples + -------- + > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0 ] ); + > var dt = 'float64'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > var v = {{alias:@stdlib/ndarray/from-scalar}}( 2.0, { 'dtype': dt } ); + > var i = {{alias:@stdlib/ndarray/from-scalar}}( 0, { 'dtype': 'generic' } ); + > {{alias}}( [ x, v, i ] ) + 1 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/docs/types/index.d.ts new file mode 100644 index 000000000000..e6f229dd2f0e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/docs/types/index.d.ts @@ -0,0 +1,56 @@ +/* +* @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 + +/// + +import { float64ndarray, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Returns the first index of a search element in a one-dimensional double-precision floating-point ndarray. +* +* @param arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element, and a zero-dimensional ndarray containing the index from which to begin searching +* @returns index +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var dindexOf = require( '@stdlib/blas/ext/base/ndarray/dindex-of' ); +* +* var xbuf = new Float64Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var searchElement = scalar2ndarray( 2.0, { +* 'dtype': 'float64' +* }); +* +* var fromIndex = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var v = dindexOf( [ x, searchElement, fromIndex ] ); +* // returns 3 +*/ +declare function dindexOf( arrays: [ float64ndarray, typedndarray, typedndarray ] ): number; + + +// EXPORTS // + +export = dindexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/docs/types/test.ts new file mode 100644 index 000000000000..a40884be31a6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/docs/types/test.ts @@ -0,0 +1,70 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import dindexOf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + const searchElement = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + const fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + + dindexOf( [ x, searchElement, fromIndex ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + dindexOf( '10' ); // $ExpectError + dindexOf( 10 ); // $ExpectError + dindexOf( true ); // $ExpectError + dindexOf( false ); // $ExpectError + dindexOf( null ); // $ExpectError + dindexOf( undefined ); // $ExpectError + dindexOf( [] ); // $ExpectError + dindexOf( {} ); // $ExpectError + dindexOf( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + const searchElement = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + const fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + + dindexOf(); // $ExpectError + dindexOf( [ x, searchElement, fromIndex ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/examples/index.js new file mode 100644 index 000000000000..bfb556486c6b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/examples/index.js @@ -0,0 +1,45 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var dindexOf = require( './../lib' ); + +var xbuf = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); +var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var searchElement = scalar2ndarray( 80.0, { + 'dtype': 'float64' +}); +console.log( 'Search Element:', ndarraylike2scalar( searchElement ) ); + +var fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' +}); +console.log( 'From Index:', ndarraylike2scalar( fromIndex ) ); + +var idx = dindexOf( [ x, searchElement, fromIndex ] ); +console.log( idx ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/lib/index.js new file mode 100644 index 000000000000..5f6941a38928 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/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'; + +/** +* Return the first index of a search element in a one-dimensional double-precision floating-point ndarray. +* +* @module @stdlib/blas/ext/base/ndarray/dindex-of +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var dindexOf = require( '@stdlib/blas/ext/base/ndarray/dindex-of' ); +* +* var xbuf = new Float64Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var searchElement = scalar2ndarray( 2.0, { +* 'dtype': 'float64' +* }); +* +* var fromIndex = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var v = dindexOf( [ x, searchElement, fromIndex ] ); +* // returns 3 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/lib/main.js new file mode 100644 index 000000000000..48c2ec2265cc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/lib/main.js @@ -0,0 +1,96 @@ + +/** +* @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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/blas/ext/base/dindex-of' ).ndarray; +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); + + +// MAIN // + +/** +* Returns the first index of a search element in a one-dimensional double-precision floating-point ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element, and a zero-dimensional ndarray containing the index from which to begin searching +* @returns {integer} index +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var dindexOf = require( '@stdlib/blas/ext/base/ndarray/dindex-of' ); +* +* var xbuf = new Float64Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var searchElement = scalar2ndarray( 2.0, { +* 'dtype': 'float64' +* }); +* +* var fromIndex = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var v = dindexOf( [ x, searchElement, fromIndex ] ); +* // returns 3 +*/ +function dindexOf( arrays ) { + var searchElement; + var fromIndex; + var stride; + var offset; + var idx; + var N; + var x; + + x = arrays[ 0 ]; + N = numelDimension( x, 0 ); + searchElement = ndarraylike2scalar( arrays[ 1 ] ); + fromIndex = ndarraylike2scalar( arrays[ 2 ] ); + + if ( fromIndex < 0 ) { + fromIndex += N; + if ( fromIndex < 0 ) { + fromIndex = 0; + } + } else if ( fromIndex >= N ) { + return -1; + } + N -= fromIndex; + stride = getStride( x, 0 ); + offset = getOffset( x ) + ( stride*fromIndex ); + + idx = strided( N, searchElement, getData( x ), stride, offset ); + if ( idx >= 0 ) { + idx += fromIndex; + } + return idx; +} + + +// EXPORTS // + +module.exports = dindexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/package.json new file mode 100644 index 000000000000..39d578d7e2fd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/dindex-of", + "version": "0.0.0", + "description": "Return the first index of a specified search element in a one-dimensional double-precision floating-point ndarray.", + "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", + "mathematics", + "math", + "blas", + "extended", + "array", + "index", + "search", + "get", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/test/test.js new file mode 100644 index 000000000000..63d4103e5ab1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dindex-of/test/test.js @@ -0,0 +1,158 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var dindexOf = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Float64Array} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'float64', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dindexOf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns the first index of an element which equals a provided search element', function test( t ) { + var searchElement; + var fromIndex; + var actual; + var x; + + x = vector( new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ), 6, 1, 0 ); + + // Nonnegative fromIndex... + searchElement = scalar2ndarray( 1.0, { + 'dtype': 'float64' + }); + fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + actual = dindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 0, 'returns expected value' ); + + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float64' + }); + fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + actual = dindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 2, 'returns expected value' ); + + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float64' + }); + fromIndex = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + actual = dindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 3, 'returns expected value' ); + + searchElement = scalar2ndarray( 4.0, { + 'dtype': 'float64' + }); + fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + actual = dindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, -1, 'returns expected value' ); + + // Negative fromIndex... + searchElement = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + fromIndex = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + actual = dindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 5, 'returns expected value' ); + + searchElement = scalar2ndarray( 3.0, { + 'dtype': 'float64' + }); + fromIndex = scalar2ndarray( -2, { + 'dtype': 'generic' + }); + actual = dindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 4, 'returns expected value' ); + + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float64' + }); + fromIndex = scalar2ndarray( -3, { + 'dtype': 'generic' + }); + actual = dindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 3, 'returns expected value' ); + + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float64' + }); + fromIndex = scalar2ndarray( -7, { + 'dtype': 'generic' + }); + actual = dindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided a starting search index which is greater than or equal to number of elements in the input ndarray', function test( t ) { + var searchElement; + var fromIndex; + var actual; + var x; + + x = vector( new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ), 6, 1, 0 ); + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float64' + }); + fromIndex = scalar2ndarray( 7, { + 'dtype': 'generic' + }); + + actual = dindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +});