From 02ef1d6adf10671647f2d95c05a331b1877b32e2 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Fri, 19 Dec 2025 15:34:18 +0530 Subject: [PATCH 01/26] feat/add-stats-base-ndarray-stdev --- .../stats/base/ndarray/stdev/README.md | 189 ++++++++++++++ .../base/ndarray/stdev/benchmark/benchmark.js | 106 ++++++++ .../stdev/docs/img/equation_sample_mean.svg | 43 ++++ .../stats/base/ndarray/stdev/docs/repl.txt | 55 +++++ .../base/ndarray/stdev/docs/types/index.d.ts | 52 ++++ .../base/ndarray/stdev/docs/types/test.ts | 61 +++++ .../base/ndarray/stdev/examples/index.js | 39 +++ .../stats/base/ndarray/stdev/lib/index.js | 54 ++++ .../stats/base/ndarray/stdev/lib/main.js | 69 ++++++ .../stats/base/ndarray/stdev/package.json | 65 +++++ .../stats/base/ndarray/stdev/test/test.js | 231 ++++++++++++++++++ 11 files changed, 964 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/stdev/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/img/equation_sample_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/stdev/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md new file mode 100644 index 000000000000..5b34d5885440 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md @@ -0,0 +1,189 @@ + + +# stdev + +> Calculate the [standard deviation][standard-deviation] of a one-dimensional ndarray. + +
+ +The population [standard deviation][standard-deviation] of a finite size population of size `N` is given by + + + +```math +\sigma = \sqrt{\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 [standard deviation][standard-deviation] 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 [standard deviation][standard-deviation], the result is biased and yields an **uncorrected sample standard deviation**. To compute a **corrected sample standard deviation** for a sample of size `n`, + + + +```math +s = \sqrt{\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 standard deviation and population standard deviation. 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 stdev = require( '@stdlib/stats/base/ndarray/stdev' ); +``` + +#### stdev( arrays ) + +Computes the [standard deviation][standard-deviation] of a one-dimensional ndarray. + +```javascript +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + +var opts = { + 'dtype': 'float64' +}; + +var xbuf = [ 1.0, -2.0, 2.0 ]; +var x = new ndarray( opts.dtype, xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +var correction = scalar2ndarray( 1.0, opts ); + +var v = stdev( [ x, correction ] ); +// returns ~2.0817 +``` + +The function has the following parameters: + +- **arrays**: array-like object containing two elements: a one-dimensional input ndarray and a zero-dimensional ndarray (or ndarray-like object) specifying the degrees of freedom adjustment. Setting the correction value to a value other than `0` has the effect of adjusting the divisor during the calculation of the [standard deviation][standard-deviation] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [standard deviation][standard-deviation] 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 corrected sample [standard deviation][standard-deviation], 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). + +
+ + + +
+ +## Notes + +- If provided an empty one-dimensional ndarray, the function returns `NaN`. +- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), the function returns `NaN`. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var stdev = require( '@stdlib/stats/base/ndarray/stdev' ); + +var opts = { + 'dtype': 'float64' +}; + +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +var x = new ndarray( opts.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var correction = scalar2ndarray( 1.0, opts ); +var v = stdev( [ x, correction ] ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/benchmark/benchmark.js new file mode 100644 index 000000000000..3d13e9bb2571 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/benchmark/benchmark.js @@ -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. +*/ + +'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 ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var pkg = require( './../package.json' ).name; +var stdev = 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 correction; + var xbuf; + var x; + + xbuf = uniform( len, -10.0, 10.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + correction = scalar2ndarray( 1.0, options ); + + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = stdev( [ x, correction ] ); + 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/ndarray/stdev/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/img/equation_sample_mean.svg new file mode 100644 index 000000000000..aea7a5f6687a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/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/base/ndarray/stdev/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt new file mode 100644 index 000000000000..9429c64a3589 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt @@ -0,0 +1,55 @@ +{{alias}}( arrays ) + Computes the standard deviation of a one-dimensional ndarray. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing two elements: a one-dimensional input + ndarray and a zero-dimensional ndarray (or ndarray-like object) + specifying the degrees of freedom adjustment. Setting the correction + value to a value other than `0` has the effect of adjusting the divisor + during the calculation of the standard deviation according to `N - c` + where `c` corresponds to the provided degrees of freedom adjustment. + When computing the standard deviation 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 + corrected sample standard deviation, 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). + + Returns + ------- + out: number + The standard deviation. + + Examples + -------- + // Create input ndarray: + > var xbuf = [ 1.0, -2.0, 2.0 ]; + > var dt = 'generic'; + > var sh = [ xbuf.length ]; + > var st = [ 1 ]; + > var oo = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, st, oo, ord ); + + // Create correction ndarray: + > var opts = { 'dtype': 'float64' }; + > var correction = {{alias:@stdlib/ndarray/from-scalar}}( 1.0, opts ); + + // Compute the standard deviation: + > {{alias}}( [ x, correction ] ) + ~2.0817 + + // Using Float64Array buffer: + > xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > dt = 'float64'; + > sh = [ xbuf.length ]; + > x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, st, oo, ord ); + > {{alias}}( [ x, correction ] ) + ~2.3381 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts new file mode 100644 index 000000000000..5ad1e6581ad9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts @@ -0,0 +1,52 @@ +/* +* @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 { ndarray } from '@stdlib/types/ndarray'; + +/** +* Computes the standard deviation of a one-dimensional ndarray. +* +* @param arrays - array-like object containing an input ndarray and a correction ndarray +* @returns standard deviation +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var opts = { +* 'dtype': 'float64' +* }; +* +* var xbuf = [ 1.0, -2.0, 2.0 ]; +* var x = new ndarray( opts.dtype, xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* var correction = scalar2ndarray( 1.0, opts ); +* +* var v = stdev( [ x, correction ] ); +* // returns ~2.0817 +*/ +declare function stdev( arrays: [ T, ndarray ] ): number; + + +// EXPORTS // + +export = stdev; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/test.ts new file mode 100644 index 000000000000..462bb954c489 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/test.ts @@ -0,0 +1,61 @@ +/* +* @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 stdev = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + const correction = scalar2ndarray( 1.0, { 'dtype': 'float64' } ); + + stdev( [ x, correction ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + stdev( '10' ); // $ExpectError + stdev( 10 ); // $ExpectError + stdev( true ); // $ExpectError + stdev( false ); // $ExpectError + stdev( null ); // $ExpectError + stdev( undefined ); // $ExpectError + stdev( [] ); // $ExpectError + stdev( {} ); // $ExpectError + stdev( ( 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 correction = scalar2ndarray( 1.0, { 'dtype': 'float64' } ); + + stdev(); // $ExpectError + stdev( [ x, correction ], 10 ); // $ExpectError +} + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js new file mode 100644 index 000000000000..ed5e99cc06b4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var stdev = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; + +var xbuf = discreteUniform( 10, -50, 50, opts ); +var x = new ndarray( opts.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + +var correction = scalar2ndarray( 1.0, opts ); + +console.log( ndarray2array( x ) ); + +var v = stdev( [ x, correction ] ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/index.js new file mode 100644 index 000000000000..cd8db8b44229 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/index.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute the standard deviation of a one-dimensional ndarray. +* +* @module @stdlib/stats/base/ndarray/stdev +* +* @example +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var stdev = require( '@stdlib/stats/base/ndarray/stdev' ); +* +* var opts = { +* 'dtype': 'float64' +* }; +* +* // Define a one-dimensional input ndarray: +* var xbuf = [ 1.0, -2.0, 2.0 ]; +* var x = new ndarray( opts.dtype, xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* // Specify the degrees of freedom adjustment: +* var correction = scalar2ndarray( 1.0, opts ); +* +* // Compute the standard deviation: +* var v = stdev( [ x, correction ] ); +* // returns ~2.0817 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js new file mode 100644 index 000000000000..8abc87f4c4f8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js @@ -0,0 +1,69 @@ +/** +* @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 ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var strided = require( '@stdlib/stats/strided/stdev' ).ndarray; + + +// MAIN // + +/** +* Computes the standard deviation of a one-dimensional ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {number} standard deviation +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var opts = { +* 'dtype': 'float64' +* }; +* +* var xbuf = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +* var x = new ndarray( opts.dtype, xbuf, [ 4 ], [ 2 ], 1, 'row-major' ); +* +* var correction = scalar2ndarray( 1.0, opts ); +* +* var v = stdev( [ x, correction ] ); +* // returns 2.5 +*/ +function stdev( arrays ) { + var correction; + var x; + + x = arrays[ 0 ]; + correction = ndarraylike2scalar( arrays[ 1 ] ); + + return strided( numelDimension( x, 0 ), correction, getData( x ), getStride( x, 0 ), getOffset( x ) ); +} + + +// EXPORTS // + +module.exports = stdev; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/package.json new file mode 100644 index 000000000000..bcf8a35f7408 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/stats/base/ndarray/stdev", + "version": "0.0.0", + "description": "Compute the standard deviation of one-dimensional ndarrays.", + "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", + "standard deviation", + "deviation", + "hypothesis", + "normality", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js new file mode 100644 index 000000000000..44af6c240cef --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js @@ -0,0 +1,231 @@ +/** +* @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 max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var stdev = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} 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 stdev, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( stdev.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the standard deviation of a one-dimensional ndarray', function test( t ) { + var correction; + var expected; + var opts; + var x; + var v; + + opts = { + 'dtype': 'float64' + }; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + correction = scalar2ndarray( 1.0, opts ); + + v = stdev( [ vector( x, x.length, 1, 0 ), correction ] ); + expected = sqrt( 53.5/(x.length-1) ); + t.strictEqual( v, expected, 'returns expected value' ); + + x = new Float64Array( [ -4.0, -5.0 ] ); + correction = scalar2ndarray( 1.0, opts ); + + v = stdev( [ vector( x, x.length, 1, 0 ), correction ] ); + expected = sqrt( 0.5 ); + t.strictEqual( v, expected, 'returns expected value' ); + + x = new Float64Array( [ NaN ] ); + correction = scalar2ndarray( 1.0, opts ); + + v = stdev( [ vector( x, x.length, 1, 0 ), correction ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ NaN, NaN ] ); + correction = scalar2ndarray( 1.0, opts ); + + v = stdev( [ vector( x, x.length, 1, 0 ), correction ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty ndarray, the function returns `NaN`', function test( t ) { + var correction; + var opts; + var x; + var v; + + opts = { + 'dtype': 'float64' + }; + + x = new Float64Array( [] ); + correction = scalar2ndarray( 1.0, opts ); + + v = stdev( [ vector( x, 0, 1, 0 ), correction ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a correction value yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var correction; + var opts; + var x; + var v; + + opts = { + 'dtype': 'float64' + }; + + x = new Float64Array( [ 1.0 ] ); + correction = scalar2ndarray( 1.0, opts ); + + v = stdev( [ vector( x, 1, 1, 0 ), correction ] ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { + var correction; + var expected; + var opts; + var x; + var v; + + opts = { + 'dtype': 'float64' + }; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + correction = scalar2ndarray( 1.0, opts ); + + v = stdev( [ vector( x, 4, 2, 0 ), correction ] ); + expected = 2.5; + t.strictEqual( v, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { + var correction; + var expected; + var opts; + var x; + var v; + + opts = { + 'dtype': 'float64' + }; + + x = new Float64Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + correction = scalar2ndarray( 1.0, opts ); + + v = stdev( [ vector( x, 4, -2, 6 ), correction ] ); + expected = 2.5; + t.strictEqual( v, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { + var correction; + var expected; + var opts; + var x; + var v; + + opts = { + 'dtype': 'float64' + }; + + x = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]); + correction = scalar2ndarray( 1.0, opts ); + + v = stdev( [ vector( x, 4, 2, 1 ), correction ] ); + expected = 2.5; + t.strictEqual( v, expected, 'returns expected value' ); + + t.end(); +}); + From d86bc9d8d54c6221d1bc9c72af1682664273436e Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Fri, 19 Dec 2025 15:42:48 +0530 Subject: [PATCH 02/26] fix: lint --- .../@stdlib/stats/base/ndarray/stdev/docs/repl.txt | 2 +- lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js | 4 +++- .../@stdlib/stats/base/ndarray/stdev/test/test.js | 3 --- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt index 9429c64a3589..16264fbe8c14 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt @@ -48,7 +48,7 @@ > sh = [ xbuf.length ]; > x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, st, oo, ord ); > {{alias}}( [ x, correction ] ) - ~2.3381 + ~2.5820 See Also -------- diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js index 8abc87f4c4f8..c1a2acdd069f 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js @@ -56,11 +56,13 @@ var strided = require( '@stdlib/stats/strided/stdev' ).ndarray; function stdev( arrays ) { var correction; var x; + var N; x = arrays[ 0 ]; correction = ndarraylike2scalar( arrays[ 1 ] ); - return strided( numelDimension( x, 0 ), correction, getData( x ), getStride( x, 0 ), getOffset( x ) ); + N = numelDimension( x, 0 ); + return strided( N, correction, getData( x ), getStride( x, 0 ), getOffset( x ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js index 44af6c240cef..9eb22f41d07d 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js @@ -16,8 +16,6 @@ * limitations under the License. */ -/* eslint-disable max-len */ - 'use strict'; // MODULES // @@ -228,4 +226,3 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', t.end(); }); - From 0e5577f657ae4e27b11de809a02488887c034c98 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Fri, 19 Dec 2025 15:49:12 +0530 Subject: [PATCH 03/26] Added format import --- .../@stdlib/stats/base/ndarray/stdev/benchmark/benchmark.js | 4 ++-- lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/benchmark/benchmark.js index 3d13e9bb2571..3b44d2a6b39c 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/benchmark/benchmark.js @@ -26,6 +26,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var stdev = require( './../lib' ); @@ -98,9 +99,8 @@ function main() { for ( i = min; i <= max; i++ ) { len = pow( 10, i ); f = createBenchmark( len ); - bench( pkg+':len='+len, f ); + bench( format( '%s::len=%d', pkg, len ), f ); } } main(); - diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js index c1a2acdd069f..12561841cf93 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js @@ -55,6 +55,7 @@ var strided = require( '@stdlib/stats/strided/stdev' ).ndarray; */ function stdev( arrays ) { var correction; + var stride; var x; var N; @@ -62,7 +63,8 @@ function stdev( arrays ) { correction = ndarraylike2scalar( arrays[ 1 ] ); N = numelDimension( x, 0 ); - return strided( N, correction, getData( x ), getStride( x, 0 ), getOffset( x ) ); + stride = getStride( x, 0 ); + return strided( N, correction, getData( x ), stride, getOffset( x ) ); } From b8040625923e09e40d90f811a3b516abe46a5d45 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 20 Dec 2025 02:39:38 -0800 Subject: [PATCH 04/26] docs: update description Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md index 5b34d5885440..40e09c53c413 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md @@ -120,7 +120,7 @@ var v = stdev( [ x, correction ] ); The function has the following parameters: -- **arrays**: array-like object containing two elements: a one-dimensional input ndarray and a zero-dimensional ndarray (or ndarray-like object) specifying the degrees of freedom adjustment. Setting the correction value to a value other than `0` has the effect of adjusting the divisor during the calculation of the [standard deviation][standard-deviation] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [standard deviation][standard-deviation] 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 corrected sample [standard deviation][standard-deviation], 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). +- **arrays**: array-like object containing two elements: a one-dimensional input ndarray and a zero-dimensional ndarray specifying the degrees of freedom adjustment. Setting the correction value to a value other than `0` has the effect of adjusting the divisor during the calculation of the [standard deviation][standard-deviation] according to `N-c` where `N` is the number of elements in the input ndarray and `c` corresponds to the provided degrees of freedom adjustment. When computing the [standard deviation][standard-deviation] 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 corrected sample [standard deviation][standard-deviation], 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). From ade747d2d60eae01016decba400b47573213cdcf Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 20 Dec 2025 02:41:45 -0800 Subject: [PATCH 05/26] docs: update copy Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md index 40e09c53c413..a629b8d74cca 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md @@ -120,7 +120,7 @@ var v = stdev( [ x, correction ] ); The function has the following parameters: -- **arrays**: array-like object containing two elements: a one-dimensional input ndarray and a zero-dimensional ndarray specifying the degrees of freedom adjustment. Setting the correction value to a value other than `0` has the effect of adjusting the divisor during the calculation of the [standard deviation][standard-deviation] according to `N-c` where `N` is the number of elements in the input ndarray and `c` corresponds to the provided degrees of freedom adjustment. When computing the [standard deviation][standard-deviation] 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 corrected sample [standard deviation][standard-deviation], 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). +- **arrays**: array-like object containing two elements: a one-dimensional input ndarray and a zero-dimensional ndarray specifying the degrees of freedom adjustment. Providing a non-zero degrees of freedom adjustment has the effect of adjusting the divisor during the calculation of the [standard deviation][standard-deviation] according to `N-c` where `N` is the number of elements in the input ndarray and `c` corresponds to the provided degrees of freedom adjustment. When computing the [standard deviation][standard-deviation] 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 corrected sample [standard deviation][standard-deviation], 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). From 15d166c20842d52dae2704bee8504c05033a8174 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 20 Dec 2025 02:42:53 -0800 Subject: [PATCH 06/26] docs: update note Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md index a629b8d74cca..0e8be7e77b98 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md @@ -131,7 +131,7 @@ The function has the following parameters: ## Notes - If provided an empty one-dimensional ndarray, the function returns `NaN`. -- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), the function returns `NaN`. +- If `N - c` is less than or equal to `0` (where `N` corresponds to the number of elements in the input ndarray and `c` corresponds to the provided degrees of freedom adjustment), the function returns `NaN`. From 84fad5bb89ab8d9c04edf5de14e62613eab591fc Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 20 Dec 2025 02:44:44 -0800 Subject: [PATCH 07/26] style: add missing empty line Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt index 16264fbe8c14..f7a0fbced25f 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt @@ -1,3 +1,4 @@ + {{alias}}( arrays ) Computes the standard deviation of a one-dimensional ndarray. From fcf6bd9881f8577fc8c2041c2b9f613742983ec6 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 20 Dec 2025 02:46:44 -0800 Subject: [PATCH 08/26] docs: update example Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/stdev/docs/repl.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt index f7a0fbced25f..3cbc6785de49 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt @@ -43,14 +43,6 @@ > {{alias}}( [ x, correction ] ) ~2.0817 - // Using Float64Array buffer: - > xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > dt = 'float64'; - > sh = [ xbuf.length ]; - > x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, st, oo, ord ); - > {{alias}}( [ x, correction ] ) - ~2.5820 - See Also -------- From 585baf7debd13557efe3f0a6d2595763bacf2fb0 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 20 Dec 2025 02:47:24 -0800 Subject: [PATCH 09/26] docs: update example Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt index 3cbc6785de49..3de32880b7cf 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt @@ -36,7 +36,7 @@ > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, st, oo, ord ); // Create correction ndarray: - > var opts = { 'dtype': 'float64' }; + > var opts = { 'dtype': dt }; > var correction = {{alias:@stdlib/ndarray/from-scalar}}( 1.0, opts ); // Compute the standard deviation: From 3ca9f5463a87d46a6bdcc029930242e13a81299c Mon Sep 17 00:00:00 2001 From: Pratik Date: Sat, 20 Dec 2025 23:56:52 +0530 Subject: [PATCH 10/26] Update lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt Co-authored-by: Athan Signed-off-by: Pratik --- lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt index 3de32880b7cf..84385a14891b 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt @@ -2,6 +2,8 @@ {{alias}}( arrays ) Computes the standard deviation of a one-dimensional ndarray. + If provided an empty ndarray, the function returns `NaN`. + Parameters ---------- arrays: ArrayLikeObject From 158caa3eef197e70dd7dc9fda9ad9c7847b2f31c Mon Sep 17 00:00:00 2001 From: Pratik Date: Tue, 23 Dec 2025 00:57:06 +0530 Subject: [PATCH 11/26] Update lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts Co-authored-by: Athan Signed-off-by: Pratik --- .../@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts index 5ad1e6581ad9..39b48ad40c5e 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts @@ -25,7 +25,7 @@ import { ndarray } from '@stdlib/types/ndarray'; /** * Computes the standard deviation of a one-dimensional ndarray. * -* @param arrays - array-like object containing an input ndarray and a correction ndarray +* @param arrays - array-like object containing a one-dimensional input ndarray and a zero-dimensional ndarray specifying a degrees of freedom adjustment * @returns standard deviation * * @example From dd184596bd3b834daf069d20b0a0073055739707 Mon Sep 17 00:00:00 2001 From: Pratik Date: Tue, 23 Dec 2025 00:57:47 +0530 Subject: [PATCH 12/26] Update lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts Co-authored-by: Athan Signed-off-by: Pratik --- .../@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts index 39b48ad40c5e..aadeba405f04 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts @@ -20,7 +20,7 @@ /// -import { ndarray } from '@stdlib/types/ndarray'; +import { typedndarray } from '@stdlib/types/ndarray'; /** * Computes the standard deviation of a one-dimensional ndarray. From b4966cea21ae70845f8025554657e44868b8c765 Mon Sep 17 00:00:00 2001 From: Pratik Date: Tue, 23 Dec 2025 00:58:04 +0530 Subject: [PATCH 13/26] Update lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts Co-authored-by: Athan Signed-off-by: Pratik --- .../@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts index aadeba405f04..19080c1774d9 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts @@ -44,7 +44,7 @@ import { typedndarray } from '@stdlib/types/ndarray'; * var v = stdev( [ x, correction ] ); * // returns ~2.0817 */ -declare function stdev( arrays: [ T, ndarray ] ): number; +declare function stdev( arrays: [ T, T ] ): number; // EXPORTS // From 5ddcd6625c26f962f13776037ea1e00d342eb31a Mon Sep 17 00:00:00 2001 From: Pratik Date: Tue, 23 Dec 2025 00:58:40 +0530 Subject: [PATCH 14/26] Update lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/index.js Co-authored-by: Athan Signed-off-by: Pratik --- lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/index.js index cd8db8b44229..f1ad07aeea60 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/index.js @@ -29,7 +29,7 @@ * var stdev = require( '@stdlib/stats/base/ndarray/stdev' ); * * var opts = { -* 'dtype': 'float64' +* 'dtype': 'generic' * }; * * // Define a one-dimensional input ndarray: From 756ddbf099b8b1c7920c886dd99e05c9b12bb58c Mon Sep 17 00:00:00 2001 From: Pratik Date: Tue, 23 Dec 2025 00:58:55 +0530 Subject: [PATCH 15/26] Update lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js Co-authored-by: Athan Signed-off-by: Pratik --- lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js index 12561841cf93..41ef6f8104cc 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js @@ -33,7 +33,7 @@ var strided = require( '@stdlib/stats/strided/stdev' ).ndarray; /** * Computes the standard deviation of a one-dimensional ndarray. * -* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @param {ArrayLikeObject} arrays - array-like object containing a one-dimensional input ndarray and a zero-dimensional ndarray specifying a degrees of freedom adjustment * @returns {number} standard deviation * * @example From fdbbdd1bc67005b7c16f15e5e617137dd4ec0d47 Mon Sep 17 00:00:00 2001 From: Pratik Date: Tue, 23 Dec 2025 00:59:13 +0530 Subject: [PATCH 16/26] Update lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js Co-authored-by: Athan Signed-off-by: Pratik --- .../@stdlib/stats/base/ndarray/stdev/lib/main.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js index 41ef6f8104cc..9f70b69947b1 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js @@ -57,14 +57,11 @@ function stdev( arrays ) { var correction; var stride; var x; - var N; x = arrays[ 0 ]; correction = ndarraylike2scalar( arrays[ 1 ] ); - N = numelDimension( x, 0 ); - stride = getStride( x, 0 ); - return strided( N, correction, getData( x ), stride, getOffset( x ) ); + return strided( numelDimension( x, 0 ), correction, getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len } From dccd86db683531319413c07fcc946451d3fe15a1 Mon Sep 17 00:00:00 2001 From: Pratik Date: Tue, 23 Dec 2025 00:59:27 +0530 Subject: [PATCH 17/26] Update lib/node_modules/@stdlib/stats/base/ndarray/stdev/package.json Co-authored-by: Athan Signed-off-by: Pratik --- lib/node_modules/@stdlib/stats/base/ndarray/stdev/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/package.json index bcf8a35f7408..681b2c7cbd6b 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/stats/base/ndarray/stdev", "version": "0.0.0", - "description": "Compute the standard deviation of one-dimensional ndarrays.", + "description": "Compute the standard deviation of a one-dimensional ndarray.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From 04d76402edcce578acc9613cba3fa4e8e0caee89 Mon Sep 17 00:00:00 2001 From: Pratik Date: Tue, 23 Dec 2025 01:49:59 +0530 Subject: [PATCH 18/26] Update lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js Co-authored-by: Athan Signed-off-by: Pratik --- .../@stdlib/stats/base/ndarray/stdev/examples/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js index ed5e99cc06b4..fb9c460fe13e 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js @@ -30,10 +30,8 @@ var opts = { var xbuf = discreteUniform( 10, -50, 50, opts ); var x = new ndarray( opts.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); - -var correction = scalar2ndarray( 1.0, opts ); - console.log( ndarray2array( x ) ); +var correction = scalar2ndarray( 1.0, opts ); var v = stdev( [ x, correction ] ); console.log( v ); From 20ab82c6d5c60667c0ae0653b7d4215eb732725f Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Tue, 23 Dec 2025 02:03:14 +0530 Subject: [PATCH 19/26] suggested changes --- .../stats/base/ndarray/stdev/docs/repl.txt | 28 +++++++++++-------- .../base/ndarray/stdev/examples/index.js | 4 ++- .../stats/base/ndarray/stdev/lib/main.js | 1 - .../stats/base/ndarray/stdev/package.json | 14 ++++++++-- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt index 84385a14891b..fd8fa9142c90 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt @@ -2,23 +2,27 @@ {{alias}}( arrays ) Computes the standard deviation of a one-dimensional ndarray. - If provided an empty ndarray, the function returns `NaN`. + If provided an empty one-dimensional ndarray, the function returns `NaN`. + + If `N - c` is less than or equal to `0` (where `N` corresponds to the + number of elements in the input ndarray and `c` corresponds to the provided + degrees of freedom adjustment), the function returns `NaN`. Parameters ---------- arrays: ArrayLikeObject Array-like object containing two elements: a one-dimensional input - ndarray and a zero-dimensional ndarray (or ndarray-like object) - specifying the degrees of freedom adjustment. Setting the correction - value to a value other than `0` has the effect of adjusting the divisor - during the calculation of the standard deviation according to `N - c` - where `c` corresponds to the provided degrees of freedom adjustment. - When computing the standard deviation 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 - corrected sample standard deviation, 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 + ndarray and a zero-dimensional ndarray specifying the degrees of freedom + adjustment. Providing a non-zero degrees of freedom adjustment has the + effect of adjusting the divisor during the calculation of the standard + deviation according to `N-c` where `N` is the number of elements in the + input ndarray and `c` corresponds to the provided degrees of freedom + adjustment. When computing the standard deviation 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 corrected sample standard deviation, 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). Returns diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js index fb9c460fe13e..654116afdb00 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js @@ -28,7 +28,9 @@ var opts = { 'dtype': 'float64' }; -var xbuf = discreteUniform( 10, -50, 50, opts ); +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); var x = new ndarray( opts.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js index 9f70b69947b1..04440f69d42a 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/lib/main.js @@ -55,7 +55,6 @@ var strided = require( '@stdlib/stats/strided/stdev' ).ndarray; */ function stdev( arrays ) { var correction; - var stride; var x; x = arrays[ 0 ]; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/package.json index 681b2c7cbd6b..2fb9b5b9bd63 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/package.json @@ -56,10 +56,18 @@ "mathematics", "math", "standard deviation", + "variance", + "var", "deviation", - "hypothesis", - "normality", - "ndarray" + "dispersion", + "spread", + "sample standard deviation", + "unbiased", + "stdev", + "std", + "ndarray", + "typed", + "array" ], "__stdlib__": {} } From f6efd1de304b2f799a7db20658adf37f2205ced9 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 23 Dec 2025 00:55:19 -0800 Subject: [PATCH 20/26] style: fix line wrapping Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/stdev/docs/repl.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt index fd8fa9142c90..9d15154900c2 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/repl.txt @@ -4,9 +4,9 @@ If provided an empty one-dimensional ndarray, the function returns `NaN`. - If `N - c` is less than or equal to `0` (where `N` corresponds to the - number of elements in the input ndarray and `c` corresponds to the provided - degrees of freedom adjustment), the function returns `NaN`. + If `N - c` is less than or equal to `0` (where `N` corresponds to the number + of elements in the input ndarray and `c` corresponds to the provided degrees + of freedom adjustment), the function returns `NaN`. Parameters ---------- From 0b016ecf8c7ced73320a1c830780d5452a9937bc Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 23 Dec 2025 00:57:16 -0800 Subject: [PATCH 21/26] docs: fix example Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts index 19080c1774d9..6a63498b4c6a 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts @@ -34,7 +34,7 @@ import { typedndarray } from '@stdlib/types/ndarray'; * var Float64Array = require( '@stdlib/array/float64' ); * * var opts = { -* 'dtype': 'float64' +* 'dtype': 'generic' * }; * * var xbuf = [ 1.0, -2.0, 2.0 ]; From e0c461186fa924e3af15feebe361025e21e8b9a1 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 23 Dec 2025 00:58:10 -0800 Subject: [PATCH 22/26] docs: fix example Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts index 6a63498b4c6a..cd7df0d31ca3 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/docs/types/index.d.ts @@ -34,10 +34,10 @@ import { typedndarray } from '@stdlib/types/ndarray'; * var Float64Array = require( '@stdlib/array/float64' ); * * var opts = { -* 'dtype': 'generic' +* 'dtype': 'float64' * }; * -* var xbuf = [ 1.0, -2.0, 2.0 ]; +* var xbuf = new Float64Array( [ 1.0, -2.0, 2.0 ] ); * var x = new ndarray( opts.dtype, xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); * var correction = scalar2ndarray( 1.0, opts ); * From 9774d4e0da3f8c276ee2ce5bfd2dacf8fc9ed527 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 23 Dec 2025 00:58:59 -0800 Subject: [PATCH 23/26] docs: update example Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/stdev/examples/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js index 654116afdb00..fb9c460fe13e 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/examples/index.js @@ -28,9 +28,7 @@ var opts = { 'dtype': 'float64' }; -var xbuf = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); +var xbuf = discreteUniform( 10, -50, 50, opts ); var x = new ndarray( opts.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); From 1078bbd2cdc0d29577714197a3a362fcce0941de Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 23 Dec 2025 00:59:29 -0800 Subject: [PATCH 24/26] docs: update example Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md index 0e8be7e77b98..cf884a81587d 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/README.md @@ -155,9 +155,7 @@ var opts = { 'dtype': 'float64' }; -var xbuf = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); +var xbuf = discreteUniform( 10, -50, 50, opts ); var x = new ndarray( opts.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); From 7673e4cb891c22877343ba948cfb2f63716a7431 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 23 Dec 2025 01:02:13 -0800 Subject: [PATCH 25/26] test: update description Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js index 9eb22f41d07d..e97bf2c75ee9 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js @@ -118,7 +118,7 @@ tape( 'if provided an empty ndarray, the function returns `NaN`', function test( t.end(); }); -tape( 'if provided a correction value yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { +tape( 'if provided a correction argument yields `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { var correction; var opts; var x; From 17396ad4a5aba743bf842957041ca682bf8ce17c Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 23 Dec 2025 01:03:11 -0800 Subject: [PATCH 26/26] test: update description Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js index e97bf2c75ee9..6d9c7b70575b 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/stdev/test/test.js @@ -118,7 +118,7 @@ tape( 'if provided an empty ndarray, the function returns `NaN`', function test( t.end(); }); -tape( 'if provided a correction argument yields `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { +tape( 'if provided a correction argument yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { var correction; var opts; var x;