From 6ce2b7d33dcfaf827399269f8dd504be6e68a924 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Fri, 18 Jul 2025 13:20:05 +0000 Subject: [PATCH 1/6] feat: add `stats/base/ndarray/dcovarmtk` --- 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/base/ndarray/dcovarmtk/README.md | 216 +++++++++++++++ .../ndarray/dcovarmtk/benchmark/benchmark.js | 115 ++++++++ .../base/ndarray/dcovarmtk/docs/repl.txt | 64 +++++ .../ndarray/dcovarmtk/docs/types/index.d.ts | 68 +++++ .../base/ndarray/dcovarmtk/docs/types/test.ts | 57 ++++ .../base/ndarray/dcovarmtk/examples/index.js | 51 ++++ .../stats/base/ndarray/dcovarmtk/lib/index.js | 57 ++++ .../stats/base/ndarray/dcovarmtk/lib/main.js | 91 ++++++ .../stats/base/ndarray/dcovarmtk/package.json | 67 +++++ .../stats/base/ndarray/dcovarmtk/test/test.js | 262 ++++++++++++++++++ 10 files changed, 1048 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md new file mode 100644 index 000000000000..a9a4c1b19d29 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md @@ -0,0 +1,216 @@ + + +# dcovarmtk + +> Calculate the [covariance][covariance] of two one-dimensional double-precision floating-point ndarrays provided known means and using a one-pass textbook algorithm. + +
+ +The population [covariance][covariance] of two finite size populations of size `N` is given by + + + +```math +\mathop{\mathrm{cov_N}} = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu_x)(y_i - \mu_y) +``` + + + +where the population means are given by + + + +```math +\mu_x = \frac{1}{N} \sum_{i=0}^{N-1} x_i +``` + + + +and + + + +```math +\mu_y = \frac{1}{N} \sum_{i=0}^{N-1} y_i +``` + + + +Often in the analysis of data, the true population [covariance][covariance] is not known _a priori_ and must be estimated from samples drawn from population distributions. If one attempts to use the formula for the population [covariance][covariance], the result is biased and yields a **biased sample covariance**. To compute an **unbiased sample covariance** for samples of size `n`, + + + +```math +\mathop{\mathrm{cov_n}} = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x}_n)(y_i - \bar{y}_n) +``` + + + +where sample means are given by + + + +```math +\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + +and + + + +```math +\bar{y} = \frac{1}{n} \sum_{i=0}^{n-1} y_i +``` + + + +The use of the term `n-1` is commonly referred to as Bessel's correction. Depending on the characteristics of the population distributions, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. + +
+ + + +
+ +## Usage + +```javascript +var dcovarmtk = require( '@stdlib/stats/base/ndarray/dcovarmtk' ); +``` + +#### dcovarmtk( arrays ) + +Computes the covariance of two one-dimensional double-precision floating-point ndarrays provided known means and using a one-pass textbook algorithm. + +```javascript +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( [ 1.0, -2.0, 2.0 ] ); +var x = new ndarray( opts.dtype, xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + +var ybuf = new Float64Array( [ 2.0, -2.0, 1.0 ] ); +var y = new ndarray( opts.dtype, ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); + +var meanx = scalar2ndarray( 1.0/3.0, opts ); +var meany = scalar2ndarray( 1.0/3.0, opts ); +var correction = scalar2ndarray( 1.0, opts ); + +var v = dcovarmtk( [ x, y, meanx, meany, correction ] ); +// returns ~3.8333 +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays in order: + + 1. first one-dimensional input ndarray. + 2. second one-dimensional input ndarray. + 3. a zero-dimensional ndarray specifying mean of the first one-dimensional ndarray. + 4. a zero-dimensional ndarray specifying mean of the second one-dimensional ndarray. + 5. a zero-dimensional ndarray specifying 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 [covariance][covariance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the population [covariance][covariance], setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample [covariance][covariance], setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). + +
+ + + +
+ +## Notes + +- If provided an empty one-dimensional ndarray, the function returns `NaN`. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var dcovarmtk = require( '@stdlib/stats/base/ndarray/dcovarmtk' ); + +// Define array options: +var opts = { + 'dtype': 'float64' +}; + +// Create first one-dimensional ndarray containing pseudorandom integers drawn from a discrete uniform distribution: +var xbuf = discreteUniform( 10, -50, 50, opts ); +var x = new ndarray( opts.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Create second one-dimensional ndarray containing pseudorandom integers drawn from a discrete uniform distribution: +var ybuf = discreteUniform( 10, -50, 50, opts ); +var y = new ndarray( opts.dtype, ybuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( y ) ); + +// Specify the known means: +var meanx = scalar2ndarray( 0.0, opts ); +var meany = scalar2ndarray( 0.0, opts ); + +// Specify the degrees of freedom adjustment: +var correction = scalar2ndarray( 1.0, opts ); + +// Calculate the sample covariance: +var v = dcovarmtk( [ x, y, meanx, meany, correction ] ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + + +[covariance]: https://en.wikipedia.org/wiki/Covariance + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/benchmark/benchmark.js new file mode 100644 index 000000000000..378425698d85 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/benchmark/benchmark.js @@ -0,0 +1,115 @@ +/** +* @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/base/from-scalar' ); +var pkg = require( './../package.json' ).name; +var dcovarmtk = 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 meanx; + var meany; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = uniform( len, -10.0, 10.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + ybuf = uniform( len, -10.0, 10.0, options ); + y = new ndarray( options.dtype, ybuf, [ len ], [ 1 ], 0, 'row-major' ); + + meanx = scalar2ndarray( 0.0, options.dtype, 'row-major' ); + meany = scalar2ndarray( 0.0, options.dtype, 'row-major' ); + correction = scalar2ndarray( 1.0, options.dtype, 'row-major' ); + + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = dcovarmtk( [ x, y, meanx, meany, 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/dcovarmtk/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/repl.txt new file mode 100644 index 000000000000..3f67b11004d7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/repl.txt @@ -0,0 +1,64 @@ + +{{alias}}( arrays ) + Computes the covariance of two one-dimensional double-precision + floating-point ndarrays provided known means and using a one-pass textbook + algorithm. + + If provided an empty ndarray, the function returns `NaN`. + + Parameters + ---------- + arrays: ArrayLikeObject + The function expects the following ndarrays in order: + + - first one-dimensional input ndarray. + - second one-dimensional input ndarray. + - a zero-dimensional ndarray specifying mean of the first + one-dimensional ndarray. + - a zero-dimensional ndarray specifying mean of the second + one-dimensional ndarray. + - a zero-dimensional ndarray specifying 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 + covariance according to `N-c` where `c` corresponds to the provided + degrees of freedom adjustment. When computing the population + covariance, setting this parameter to `0` is the standard choice (i.e., + the provided arrays contain data constituting entire populations). When + computing the unbiased sample covariance, setting this parameter to `1` + is the standard choice (i.e., the provided arrays contain data sampled + from larger populations; this is commonly referred to as Bessel's + correction). + + Returns + ------- + out: number + The covariance. + + Examples + -------- + // Create the input ndarrays: + > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 2.0 ] ); + > var ybuf = new {{alias:@stdlib/array/float64}}( [ 2.0, -2.0, 1.0 ] ); + > var dt = 'float64'; + > 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 ); + > var y = new {{alias:@stdlib/ndarray/ctor}}( dt, ybuf, sh, st, oo, ord ); + + // Specify the known means: + > var opts = { 'dtype': dt }; + > var meanx = new {{alias:@stdlib/ndarray/from-scalar}}( 1.0/3.0, opts ); + > var meany = new {{alias:@stdlib/ndarray/from-scalar}}( 1.0/3.0, opts ); + + // Specify the degrees of freedom adjustment: + > var correction = new {{alias:@stdlib/ndarray/from-scalar}}( 1.0, opts ); + + // Calculate the sample covariance: + > {{alias}}( [ x, y, meanx, meany, correction ] ) + ~3.8333 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts new file mode 100644 index 000000000000..91feaa590a3e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts @@ -0,0 +1,68 @@ +/* +* @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 } from '@stdlib/types/ndarray'; + +/** +* Computes the covariance of two one-dimensional double-precision floating-point ndarrays provided known means and using a one-pass textbook algorithm. +* +* ## Notes +* +* - The function expects the following ndarrays in order: +* +* - first one-dimensional input ndarray. +* - second one-dimensional input ndarray. +* - a zero-dimensional ndarray specifying mean of the first one-dimensional ndarray. +* - a zero-dimensional ndarray specifying mean of the second one-dimensional ndarray. +* - a zero-dimensional ndarray specifying 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 covariance according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the population covariance, setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample covariance, setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). +* +* @param arrays - array-like object containing input ndarrays +* @returns maximum value +* +* @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( [ 1.0, -2.0, 2.0 ] ); +* var x = new ndarray( opts.dtype, xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* var ybuf = new Float64Array( [ 2.0, -2.0, 1.0 ] ); +* var y = new ndarray( opts.dtype, ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* var meanx = scalar2ndarray( 1.0/3.0, opts ); +* var meany = scalar2ndarray( 1.0/3.0, opts ); +* var correction = scalar2ndarray( 1.0, opts ); +* +* var v = dcovarmtk( [ x, y, meanx, meany, correction ] ); +* // returns ~3.8333 +*/ +declare function dcovarmtk( arrays: [ float64ndarray, float64ndarray, float64ndarray, float64ndarray, float64ndarray ] ): number; + + +// EXPORTS // + +export = dcovarmtk; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/test.ts new file mode 100644 index 000000000000..89d0b12b302f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/test.ts @@ -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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import dcovarmtk = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + + dcovarmtk( [ x, x, x, x, x ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + dcovarmtk( '10' ); // $ExpectError + dcovarmtk( 10 ); // $ExpectError + dcovarmtk( true ); // $ExpectError + dcovarmtk( false ); // $ExpectError + dcovarmtk( null ); // $ExpectError + dcovarmtk( undefined ); // $ExpectError + dcovarmtk( [] ); // $ExpectError + dcovarmtk( {} ); // $ExpectError + dcovarmtk( ( 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' + }); + + dcovarmtk(); // $ExpectError + dcovarmtk( [ x, x, x, x, x ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/examples/index.js new file mode 100644 index 000000000000..429cf23c92cc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/examples/index.js @@ -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. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var dcovarmtk = require( './../lib' ); + +// Define array options: +var opts = { + 'dtype': 'float64' +}; + +// Create first one-dimensional ndarray containing pseudorandom integers drawn from a discrete uniform distribution: +var xbuf = discreteUniform( 10, -50, 50, opts ); +var x = new ndarray( opts.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Create second one-dimensional ndarray containing pseudorandom integers drawn from a discrete uniform distribution: +var ybuf = discreteUniform( 10, -50, 50, opts ); +var y = new ndarray( opts.dtype, ybuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( y ) ); + +// Specify the known means: +var meanx = scalar2ndarray( 0.0, opts ); +var meany = scalar2ndarray( 0.0, opts ); + +// Specify the degrees of freedom adjustment: +var correction = scalar2ndarray( 1.0, opts ); + +// Calculate the sample covariance: +var v = dcovarmtk( [ x, y, meanx, meany, correction ] ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/index.js new file mode 100644 index 000000000000..438d87eca1b0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/index.js @@ -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. +*/ + +'use strict'; + +/** +* Compute the covariance of two one-dimensional double-precision floating-point ndarrays provided known means and using a one-pass textbook algorithm. +* +* @module @stdlib/stats/base/ndarray/dcovarmtk +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var dcovarmtk = require( '@stdlib/stats/base/ndarray/dcovarmtk' ); +* +* var opts = { +* 'dtype': 'float64' +* }; +* +* var xbuf = new Float64Array( [ 1.0, -2.0, 2.0 ] ); +* var x = new ndarray( opts.dtype, xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* var ybuf = new Float64Array( [ 2.0, -2.0, 1.0 ] ); +* var y = new ndarray( opts.dtype, ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* var meanx = scalar2ndarray( 1.0/3.0, opts ); +* var meany = scalar2ndarray( 1.0/3.0, opts ); +* var correction = scalar2ndarray( 1.0, opts ); +* +* var v = dcovarmtk( [ x, y, meanx, meany, correction ] ); +* // returns ~3.8333 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js new file mode 100644 index 000000000000..7341ef1fd1e0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js @@ -0,0 +1,91 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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/dcovarmtk' ).ndarray; + + +// MAIN // + +/** +* Computes the covariance of two one-dimensional double-precision floating-point ndarrays provided known means and using a one-pass textbook algorithm. +* +* ## Notes +* +* - The function expects the following ndarrays in order: +* +* - first one-dimensional input ndarray. +* - second one-dimensional input ndarray. +* - a zero-dimensional ndarray specifying mean of the first one-dimensional ndarray. +* - a zero-dimensional ndarray specifying mean of the second one-dimensional ndarray. +* - a zero-dimensional ndarray specifying 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 covariance according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the population covariance, setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample covariance, setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). +* +* @param {ArrayLikeObject} arrays - array-like object containing input ndarrays +* @returns {number} maximum value +* +* @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( [ 1.0, -2.0, 2.0 ] ); +* var x = new ndarray( opts.dtype, xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* var ybuf = new Float64Array( [ 2.0, -2.0, 1.0 ] ); +* var y = new ndarray( opts.dtype, ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* var meanx = scalar2ndarray( 1.0/3.0, opts ); +* var meany = scalar2ndarray( 1.0/3.0, opts ); +* var correction = scalar2ndarray( 1.0, opts ); +* +* var v = dcovarmtk( [ x, y, meanx, meany, correction ] ); +* // returns ~3.8333 +*/ +function dcovarmtk( arrays ) { + var correction; + var meanx; + var meany; + var x; + var y; + + x = arrays[ 0 ]; + y = arrays[ 1 ]; + + meanx = ndarraylike2scalar( arrays[ 2 ] ); + meany = ndarraylike2scalar( arrays[ 3 ] ); + correction = ndarraylike2scalar( arrays[ 4 ] ); + + return strided( numelDimension( x, 0 ), correction, meanx, getData( x ), getStride( x, 0 ), getOffset( x ), meany, getData( y ), getStride( y, 0 ), getOffset( y ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = dcovarmtk; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/package.json new file mode 100644 index 000000000000..52b0d204caa7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/base/ndarray/dcovarmtk", + "version": "0.0.0", + "description": "Computes the covariance of two one-dimensional double-precision floating-point ndarrays provided known means and 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", + "covariance", + "covar", + "sample covariance", + "unbiased", + "correlation", + "variance", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/test/test.js new file mode 100644 index 000000000000..8b8c40af84d3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/test/test.js @@ -0,0 +1,262 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var dcovarmtk = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// 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 dcovarmtk, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( dcovarmtk.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population covariance of two one-dimensional double-precision floating-point ndarrays provided known means', function test( t ) { + var correction; + var meanx; + var meany; + var x; + var y; + var v; + + correction = scalar2ndarray( 0.0, options ); + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + y = new Float64Array( [ -2.0, 1.0, 5.0, -4.0, 3.0, 0.0 ] ); + meanx = scalar2ndarray( 0.5, options ); + meany = scalar2ndarray( 0.5, options ); + v = dcovarmtk( [ vector( x, 6, 1, 0 ), vector( y, 6, 1, 0 ), meanx, meany, correction ] ); // eslint-disable-line max-len + t.strictEqual( v, -45.5/x.length, 'returns expected value' ); + + x = new Float64Array( [ -4.0, -4.0 ] ); + meanx = scalar2ndarray( -4.0, options ); + v = dcovarmtk( [ vector( x, 2, 1, 0 ), vector( x, 2, 1, 0 ), meanx, meanx, correction ] ); // eslint-disable-line max-len + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float64Array( [ NaN, 4.0 ] ); + meanx = scalar2ndarray( 4.0, options ); + v = dcovarmtk( [ vector( x, 2, 1, 0 ), vector( x, 2, 1, 0 ), meanx, meanx, correction ] ); // eslint-disable-line max-len + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample covariance of two one-dimensional double-precision floating-point ndarrays provided known means', function test( t ) { + var correction; + var meanx; + var meany; + var x; + var y; + var v; + + correction = scalar2ndarray( 1.0, options ); + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + y = new Float64Array( [ -2.0, 1.0, 5.0, -4.0, 3.0, 0.0 ] ); + meanx = scalar2ndarray( 0.5, options ); + meany = scalar2ndarray( 0.5, options ); + v = dcovarmtk( [ vector( x, 6, 1, 0 ), vector( y, 6, 1, 0 ), meanx, meany, correction ] ); // eslint-disable-line max-len + t.strictEqual( v, -45.5/(x.length-1), 'returns expected value' ); + + x = new Float64Array( [ -4.0, -4.0 ] ); + meanx = scalar2ndarray( -4.0, options ); + v = dcovarmtk( [ vector( x, 2, 1, 0 ), vector( x, 2, 1, 0 ), meanx, meanx, correction ] ); // eslint-disable-line max-len + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float64Array( [ NaN, 4.0 ] ); + meanx = scalar2ndarray( 4.0, options ); + v = dcovarmtk( [ vector( x, 2, 1, 0 ), vector( x, 2, 1, 0 ), meanx, meanx, correction ] ); // eslint-disable-line max-len + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty vector, the function returns `NaN`', function test( t ) { + var correction; + var meanx; + var x; + var v; + + x = new Float64Array( [] ); + meanx = scalar2ndarray( 0.5, options ); + correction = scalar2ndarray( 1.0, options ); + + v = dcovarmtk( [ vector( x, 0, 1, 0 ), vector( x, 0, 1, 0 ), meanx, meanx, correction ] ); // eslint-disable-line max-len + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { + var correction; + var meanx; + var meany; + var x; + var y; + var v; + + correction = scalar2ndarray( 1.0, options ); + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + meanx = scalar2ndarray( 1.25, options ); + + y = new Float64Array([ + 2.0, // 0 + 2.0, + 1.0, // 1 + -7.0, + 4.0, // 2 + 3.0, + -2.0, // 3 + 2.0 + ]); + meany = scalar2ndarray( 1.25, options ); + + v = dcovarmtk( [ vector( x, 4, 2, 0 ), vector( y, 4, 2, 0 ), meanx, meany, correction ] ); // eslint-disable-line max-len + + t.strictEqual( v, -18.25/3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { + var correction; + var meanx; + var meany; + var x; + var y; + var v; + + correction = scalar2ndarray( 1.0, options ); + + x = new Float64Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + meanx = scalar2ndarray( 1.25, options ); + + y = new Float64Array([ + 2.0, // 3 + 2.0, + 1.0, // 2 + -7.0, + 4.0, // 1 + 3.0, + -2.0, // 0 + 2.0 + ]); + meany = scalar2ndarray( 1.25, options ); + + v = dcovarmtk( [ vector( x, 4, -2, 6 ), vector( y, 4, -2, 6 ), meanx, meany, correction ] ); // eslint-disable-line max-len + + t.strictEqual( v, -18.25/3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { + var correction; + var meanx; + var meany; + var x; + var y; + var v; + + correction = scalar2ndarray( 1.0, options ); + + x = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]); + meanx = scalar2ndarray( 1.25, options ); + + y = new Float64Array([ + 2.0, + -2.0, // 0 + 2.0, + 1.0, // 1 + -2.0, + 4.0, // 2 + 3.0, + 2.0 // 3 + ]); + meany = scalar2ndarray( 1.25, options ); + + v = dcovarmtk( [ vector( x, 4, 2, 1 ), vector( y, 4, 2, 1 ), meanx, meany, correction ] ); // eslint-disable-line max-len + t.strictEqual( v, 5.75/3, 'returns expected value' ); + + t.end(); +}); From b79d0833bbdac1fabd4400c66c30119f0a2efcf8 Mon Sep 17 00:00:00 2001 From: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> Date: Fri, 18 Jul 2025 20:50:19 +0530 Subject: [PATCH 2/6] Update README.md Signed-off-by: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md index a9a4c1b19d29..1a1c57e092c4 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md @@ -174,7 +174,7 @@ console.log( ndarray2array( x ) ); // Create second one-dimensional ndarray containing pseudorandom integers drawn from a discrete uniform distribution: var ybuf = discreteUniform( 10, -50, 50, opts ); -var y = new ndarray( opts.dtype, ybuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +var y = new ndarray( opts.dtype, ybuf, [ ybuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( y ) ); // Specify the known means: From be50f23e1c1536026df117b4f374c0001259927d Mon Sep 17 00:00:00 2001 From: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> Date: Fri, 18 Jul 2025 21:26:30 +0530 Subject: [PATCH 3/6] Update main.js Signed-off-by: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> --- .../@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js index 7341ef1fd1e0..a3675d1e41c0 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js @@ -44,7 +44,7 @@ var strided = require( '@stdlib/stats/strided/dcovarmtk' ).ndarray; * - a zero-dimensional ndarray specifying 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 covariance according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the population covariance, setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample covariance, setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). * * @param {ArrayLikeObject} arrays - array-like object containing input ndarrays -* @returns {number} maximum value +* @returns {number} covariance * * @example * var Float64Array = require( '@stdlib/array/float64' ); From 0fae24724e5fa4e6c3e7e53b5aaa590d8afe96d2 Mon Sep 17 00:00:00 2001 From: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> Date: Fri, 18 Jul 2025 21:34:48 +0530 Subject: [PATCH 4/6] Update index.d.ts Signed-off-by: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> --- .../@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts index 91feaa590a3e..96f02da9535f 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts @@ -36,7 +36,7 @@ import { float64ndarray } from '@stdlib/types/ndarray'; * - a zero-dimensional ndarray specifying 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 covariance according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the population covariance, setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample covariance, setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). * * @param arrays - array-like object containing input ndarrays -* @returns maximum value +* @returns covariance * * @example * var Float64Array = require( '@stdlib/array/float64' ); From f8972d7655b6b66af100cc9c9f43662ac4a7c557 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Mon, 21 Jul 2025 08:55:56 +0000 Subject: [PATCH 5/6] refactor: update parameter order --- 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: 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: na - task: lint_license_headers status: passed --- --- .../stats/base/ndarray/dcovarmtk/README.md | 18 ++++++++--------- .../ndarray/dcovarmtk/benchmark/benchmark.js | 4 ++-- .../base/ndarray/dcovarmtk/docs/repl.txt | 18 ++++++++--------- .../ndarray/dcovarmtk/docs/types/index.d.ts | 6 +++--- .../base/ndarray/dcovarmtk/examples/index.js | 8 ++++---- .../stats/base/ndarray/dcovarmtk/lib/index.js | 4 ++-- .../stats/base/ndarray/dcovarmtk/lib/main.js | 12 +++++------ .../stats/base/ndarray/dcovarmtk/test/test.js | 20 +++++++++---------- 8 files changed, 45 insertions(+), 45 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md index 1a1c57e092c4..49e4dbde6545 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md @@ -117,11 +117,11 @@ var x = new ndarray( opts.dtype, xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); var ybuf = new Float64Array( [ 2.0, -2.0, 1.0 ] ); var y = new ndarray( opts.dtype, ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); +var correction = scalar2ndarray( 1.0, opts ); var meanx = scalar2ndarray( 1.0/3.0, opts ); var meany = scalar2ndarray( 1.0/3.0, opts ); -var correction = scalar2ndarray( 1.0, opts ); -var v = dcovarmtk( [ x, y, meanx, meany, correction ] ); +var v = dcovarmtk( [ x, y, correction, meanx, meany ] ); // returns ~3.8333 ``` @@ -131,9 +131,9 @@ The function has the following parameters: 1. first one-dimensional input ndarray. 2. second one-dimensional input ndarray. - 3. a zero-dimensional ndarray specifying mean of the first one-dimensional ndarray. - 4. a zero-dimensional ndarray specifying mean of the second one-dimensional ndarray. - 5. a zero-dimensional ndarray specifying 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 [covariance][covariance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the population [covariance][covariance], setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample [covariance][covariance], setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). + 3. a zero-dimensional ndarray specifying 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 [covariance][covariance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the population [covariance][covariance], setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample [covariance][covariance], setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). + 4. a zero-dimensional ndarray specifying mean of the first one-dimensional ndarray. + 5. a zero-dimensional ndarray specifying mean of the second one-dimensional ndarray. @@ -177,15 +177,15 @@ var ybuf = discreteUniform( 10, -50, 50, opts ); var y = new ndarray( opts.dtype, ybuf, [ ybuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( y ) ); +// Specify the degrees of freedom adjustment: +var correction = scalar2ndarray( 1.0, opts ); + // Specify the known means: var meanx = scalar2ndarray( 0.0, opts ); var meany = scalar2ndarray( 0.0, opts ); -// Specify the degrees of freedom adjustment: -var correction = scalar2ndarray( 1.0, opts ); - // Calculate the sample covariance: -var v = dcovarmtk( [ x, y, meanx, meany, correction ] ); +var v = dcovarmtk( [ x, y, correction, meanx, meany ] ); console.log( v ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/benchmark/benchmark.js index 378425698d85..b73104a7edfa 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/benchmark/benchmark.js @@ -61,9 +61,9 @@ function createBenchmark( len ) { ybuf = uniform( len, -10.0, 10.0, options ); y = new ndarray( options.dtype, ybuf, [ len ], [ 1 ], 0, 'row-major' ); + correction = scalar2ndarray( 1.0, options.dtype, 'row-major' ); meanx = scalar2ndarray( 0.0, options.dtype, 'row-major' ); meany = scalar2ndarray( 0.0, options.dtype, 'row-major' ); - correction = scalar2ndarray( 1.0, options.dtype, 'row-major' ); return benchmark; @@ -73,7 +73,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = dcovarmtk( [ x, y, meanx, meany, correction ] ); + v = dcovarmtk( [ x, y, correction, meanx, meany ] ); if ( isnan( v ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/repl.txt index 3f67b11004d7..46187dd96f4c 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/repl.txt @@ -13,10 +13,6 @@ - first one-dimensional input ndarray. - second one-dimensional input ndarray. - - a zero-dimensional ndarray specifying mean of the first - one-dimensional ndarray. - - a zero-dimensional ndarray specifying mean of the second - one-dimensional ndarray. - a zero-dimensional ndarray specifying 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 @@ -28,6 +24,10 @@ is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). + - a zero-dimensional ndarray specifying mean of the first + one-dimensional ndarray. + - a zero-dimensional ndarray specifying mean of the second + one-dimensional ndarray. Returns ------- @@ -47,16 +47,16 @@ > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, st, oo, ord ); > var y = new {{alias:@stdlib/ndarray/ctor}}( dt, ybuf, sh, st, oo, ord ); - // Specify the known means: + // Specify the degrees of freedom adjustment: > var opts = { 'dtype': dt }; + > var correction = new {{alias:@stdlib/ndarray/from-scalar}}( 1.0, opts ); + + // Specify the known means: > var meanx = new {{alias:@stdlib/ndarray/from-scalar}}( 1.0/3.0, opts ); > var meany = new {{alias:@stdlib/ndarray/from-scalar}}( 1.0/3.0, opts ); - // Specify the degrees of freedom adjustment: - > var correction = new {{alias:@stdlib/ndarray/from-scalar}}( 1.0, opts ); - // Calculate the sample covariance: - > {{alias}}( [ x, y, meanx, meany, correction ] ) + > {{alias}}( [ x, y, correction, meanx, meany ] ) ~3.8333 See Also diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts index 96f02da9535f..d71c36d3a8e9 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts @@ -31,9 +31,9 @@ import { float64ndarray } from '@stdlib/types/ndarray'; * * - first one-dimensional input ndarray. * - second one-dimensional input ndarray. +* - a zero-dimensional ndarray specifying 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 covariance according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the population covariance, setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample covariance, setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). * - a zero-dimensional ndarray specifying mean of the first one-dimensional ndarray. * - a zero-dimensional ndarray specifying mean of the second one-dimensional ndarray. -* - a zero-dimensional ndarray specifying 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 covariance according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the population covariance, setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample covariance, setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). * * @param arrays - array-like object containing input ndarrays * @returns covariance @@ -53,11 +53,11 @@ import { float64ndarray } from '@stdlib/types/ndarray'; * var ybuf = new Float64Array( [ 2.0, -2.0, 1.0 ] ); * var y = new ndarray( opts.dtype, ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); * +* var correction = scalar2ndarray( 1.0, opts ); * var meanx = scalar2ndarray( 1.0/3.0, opts ); * var meany = scalar2ndarray( 1.0/3.0, opts ); -* var correction = scalar2ndarray( 1.0, opts ); * -* var v = dcovarmtk( [ x, y, meanx, meany, correction ] ); +* var v = dcovarmtk( [ x, y, correction, meanx, meany ] ); * // returns ~3.8333 */ declare function dcovarmtk( arrays: [ float64ndarray, float64ndarray, float64ndarray, float64ndarray, float64ndarray ] ): number; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/examples/index.js index 429cf23c92cc..f348fa53f761 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/examples/index.js @@ -39,13 +39,13 @@ var ybuf = discreteUniform( 10, -50, 50, opts ); var y = new ndarray( opts.dtype, ybuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( y ) ); +// Specify the degrees of freedom adjustment: +var correction = scalar2ndarray( 1.0, opts ); + // Specify the known means: var meanx = scalar2ndarray( 0.0, opts ); var meany = scalar2ndarray( 0.0, opts ); -// Specify the degrees of freedom adjustment: -var correction = scalar2ndarray( 1.0, opts ); - // Calculate the sample covariance: -var v = dcovarmtk( [ x, y, meanx, meany, correction ] ); +var v = dcovarmtk( [ x, y, correction, meanx, meany ] ); console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/index.js index 438d87eca1b0..2d68c5efe6bf 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/index.js @@ -39,11 +39,11 @@ * var ybuf = new Float64Array( [ 2.0, -2.0, 1.0 ] ); * var y = new ndarray( opts.dtype, ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); * +* var correction = scalar2ndarray( 1.0, opts ); * var meanx = scalar2ndarray( 1.0/3.0, opts ); * var meany = scalar2ndarray( 1.0/3.0, opts ); -* var correction = scalar2ndarray( 1.0, opts ); * -* var v = dcovarmtk( [ x, y, meanx, meany, correction ] ); +* var v = dcovarmtk( [ x, y, correction, meanx, meany ] ); * // returns ~3.8333 */ diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js index a3675d1e41c0..a04d6a397486 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js @@ -39,9 +39,9 @@ var strided = require( '@stdlib/stats/strided/dcovarmtk' ).ndarray; * * - first one-dimensional input ndarray. * - second one-dimensional input ndarray. +* - a zero-dimensional ndarray specifying 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 covariance according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the population covariance, setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample covariance, setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). * - a zero-dimensional ndarray specifying mean of the first one-dimensional ndarray. * - a zero-dimensional ndarray specifying mean of the second one-dimensional ndarray. -* - a zero-dimensional ndarray specifying 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 covariance according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the population covariance, setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample covariance, setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). * * @param {ArrayLikeObject} arrays - array-like object containing input ndarrays * @returns {number} covariance @@ -61,11 +61,11 @@ var strided = require( '@stdlib/stats/strided/dcovarmtk' ).ndarray; * var ybuf = new Float64Array( [ 2.0, -2.0, 1.0 ] ); * var y = new ndarray( opts.dtype, ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); * +* var correction = scalar2ndarray( 1.0, opts ); * var meanx = scalar2ndarray( 1.0/3.0, opts ); * var meany = scalar2ndarray( 1.0/3.0, opts ); -* var correction = scalar2ndarray( 1.0, opts ); * -* var v = dcovarmtk( [ x, y, meanx, meany, correction ] ); +* var v = dcovarmtk( [ x, y, correction, meanx, meany ] ); * // returns ~3.8333 */ function dcovarmtk( arrays ) { @@ -78,9 +78,9 @@ function dcovarmtk( arrays ) { x = arrays[ 0 ]; y = arrays[ 1 ]; - meanx = ndarraylike2scalar( arrays[ 2 ] ); - meany = ndarraylike2scalar( arrays[ 3 ] ); - correction = ndarraylike2scalar( arrays[ 4 ] ); + correction = ndarraylike2scalar( arrays[ 2 ] ); + meanx = ndarraylike2scalar( arrays[ 3 ] ); + meany = ndarraylike2scalar( arrays[ 4 ] ); return strided( numelDimension( x, 0 ), correction, meanx, getData( x ), getStride( x, 0 ), getOffset( x ), meany, getData( y ), getStride( y, 0 ), getOffset( y ) ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/test/test.js index 8b8c40af84d3..dff8befd10ad 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/test/test.js @@ -79,17 +79,17 @@ tape( 'the function calculates the population covariance of two one-dimensional y = new Float64Array( [ -2.0, 1.0, 5.0, -4.0, 3.0, 0.0 ] ); meanx = scalar2ndarray( 0.5, options ); meany = scalar2ndarray( 0.5, options ); - v = dcovarmtk( [ vector( x, 6, 1, 0 ), vector( y, 6, 1, 0 ), meanx, meany, correction ] ); // eslint-disable-line max-len + v = dcovarmtk( [ vector( x, 6, 1, 0 ), vector( y, 6, 1, 0 ), correction, meanx, meany ] ); // eslint-disable-line max-len t.strictEqual( v, -45.5/x.length, 'returns expected value' ); x = new Float64Array( [ -4.0, -4.0 ] ); meanx = scalar2ndarray( -4.0, options ); - v = dcovarmtk( [ vector( x, 2, 1, 0 ), vector( x, 2, 1, 0 ), meanx, meanx, correction ] ); // eslint-disable-line max-len + v = dcovarmtk( [ vector( x, 2, 1, 0 ), vector( x, 2, 1, 0 ), correction, meanx, meanx ] ); // eslint-disable-line max-len t.strictEqual( v, 0.0, 'returns expected value' ); x = new Float64Array( [ NaN, 4.0 ] ); meanx = scalar2ndarray( 4.0, options ); - v = dcovarmtk( [ vector( x, 2, 1, 0 ), vector( x, 2, 1, 0 ), meanx, meanx, correction ] ); // eslint-disable-line max-len + v = dcovarmtk( [ vector( x, 2, 1, 0 ), vector( x, 2, 1, 0 ), correction, meanx, meanx ] ); // eslint-disable-line max-len t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -109,17 +109,17 @@ tape( 'the function calculates the sample covariance of two one-dimensional doub y = new Float64Array( [ -2.0, 1.0, 5.0, -4.0, 3.0, 0.0 ] ); meanx = scalar2ndarray( 0.5, options ); meany = scalar2ndarray( 0.5, options ); - v = dcovarmtk( [ vector( x, 6, 1, 0 ), vector( y, 6, 1, 0 ), meanx, meany, correction ] ); // eslint-disable-line max-len + v = dcovarmtk( [ vector( x, 6, 1, 0 ), vector( y, 6, 1, 0 ), correction, meanx, meany ] ); // eslint-disable-line max-len t.strictEqual( v, -45.5/(x.length-1), 'returns expected value' ); x = new Float64Array( [ -4.0, -4.0 ] ); meanx = scalar2ndarray( -4.0, options ); - v = dcovarmtk( [ vector( x, 2, 1, 0 ), vector( x, 2, 1, 0 ), meanx, meanx, correction ] ); // eslint-disable-line max-len + v = dcovarmtk( [ vector( x, 2, 1, 0 ), vector( x, 2, 1, 0 ), correction, meanx, meanx ] ); // eslint-disable-line max-len t.strictEqual( v, 0.0, 'returns expected value' ); x = new Float64Array( [ NaN, 4.0 ] ); meanx = scalar2ndarray( 4.0, options ); - v = dcovarmtk( [ vector( x, 2, 1, 0 ), vector( x, 2, 1, 0 ), meanx, meanx, correction ] ); // eslint-disable-line max-len + v = dcovarmtk( [ vector( x, 2, 1, 0 ), vector( x, 2, 1, 0 ), correction, meanx, meanx ] ); // eslint-disable-line max-len t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -135,7 +135,7 @@ tape( 'if provided an empty vector, the function returns `NaN`', function test( meanx = scalar2ndarray( 0.5, options ); correction = scalar2ndarray( 1.0, options ); - v = dcovarmtk( [ vector( x, 0, 1, 0 ), vector( x, 0, 1, 0 ), meanx, meanx, correction ] ); // eslint-disable-line max-len + v = dcovarmtk( [ vector( x, 0, 1, 0 ), vector( x, 0, 1, 0 ), correction, meanx, meanx ] ); // eslint-disable-line max-len t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -175,7 +175,7 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', ]); meany = scalar2ndarray( 1.25, options ); - v = dcovarmtk( [ vector( x, 4, 2, 0 ), vector( y, 4, 2, 0 ), meanx, meany, correction ] ); // eslint-disable-line max-len + v = dcovarmtk( [ vector( x, 4, 2, 0 ), vector( y, 4, 2, 0 ), correction, meanx, meany ] ); // eslint-disable-line max-len t.strictEqual( v, -18.25/3, 'returns expected value' ); t.end(); @@ -215,7 +215,7 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', ]); meany = scalar2ndarray( 1.25, options ); - v = dcovarmtk( [ vector( x, 4, -2, 6 ), vector( y, 4, -2, 6 ), meanx, meany, correction ] ); // eslint-disable-line max-len + v = dcovarmtk( [ vector( x, 4, -2, 6 ), vector( y, 4, -2, 6 ), correction, meanx, meany ] ); // eslint-disable-line max-len t.strictEqual( v, -18.25/3, 'returns expected value' ); t.end(); @@ -255,7 +255,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', ]); meany = scalar2ndarray( 1.25, options ); - v = dcovarmtk( [ vector( x, 4, 2, 1 ), vector( y, 4, 2, 1 ), meanx, meany, correction ] ); // eslint-disable-line max-len + v = dcovarmtk( [ vector( x, 4, 2, 1 ), vector( y, 4, 2, 1 ), correction, meanx, meany ] ); // eslint-disable-line max-len t.strictEqual( v, 5.75/3, 'returns expected value' ); t.end(); From 478c8efee733fd90e8aa68abb921429642e24731 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Sat, 26 Jul 2025 18:53:46 +0000 Subject: [PATCH 6/6] chore: clean-up --- 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: 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 --- --- .../stats/base/ndarray/dcovarmtk/README.md | 12 +++++----- .../base/ndarray/dcovarmtk/docs/repl.txt | 22 ++++++++++--------- .../ndarray/dcovarmtk/docs/types/index.d.ts | 6 ++--- .../base/ndarray/dcovarmtk/examples/index.js | 5 ++--- .../stats/base/ndarray/dcovarmtk/lib/main.js | 6 ++--- .../stats/base/ndarray/dcovarmtk/package.json | 2 +- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md index 49e4dbde6545..f9756931994e 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/README.md @@ -131,9 +131,9 @@ The function has the following parameters: 1. first one-dimensional input ndarray. 2. second one-dimensional input ndarray. - 3. a zero-dimensional ndarray specifying 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 [covariance][covariance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the population [covariance][covariance], setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample [covariance][covariance], setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). - 4. a zero-dimensional ndarray specifying mean of the first one-dimensional ndarray. - 5. a zero-dimensional ndarray specifying mean of the second one-dimensional ndarray. + 3. a zero-dimensional ndarray specifying the 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 [covariance][covariance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment and `N` corresponds to the number of elements in each input ndarray. When computing the population [covariance][covariance], setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample [covariance][covariance], setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). + 4. a zero-dimensional ndarray specifying the mean of the first one-dimensional ndarray. + 5. a zero-dimensional ndarray specifying the mean of the second one-dimensional ndarray. @@ -143,7 +143,8 @@ The function has the following parameters: ## Notes -- If provided an empty one-dimensional ndarray, the function returns `NaN`. +- Both input ndarrays should have the same number of elements. +- If provided empty one-dimensional ndarrays, the function returns `NaN`. @@ -167,12 +168,11 @@ var opts = { 'dtype': 'float64' }; -// Create first one-dimensional ndarray containing pseudorandom integers drawn from a discrete uniform distribution: +// Create one-dimensional ndarrays containing pseudorandom numbers: var xbuf = discreteUniform( 10, -50, 50, opts ); var x = new ndarray( opts.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); -// Create second one-dimensional ndarray containing pseudorandom integers drawn from a discrete uniform distribution: var ybuf = discreteUniform( 10, -50, 50, opts ); var y = new ndarray( opts.dtype, ybuf, [ ybuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/repl.txt index 46187dd96f4c..8ce72f1b7055 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/repl.txt @@ -1,10 +1,11 @@ {{alias}}( arrays ) - Computes the covariance of two one-dimensional double-precision - floating-point ndarrays provided known means and using a one-pass textbook - algorithm. + Computes the covariance of two one-dimensional double-precision floating- + point ndarrays provided known means and using a one-pass textbook algorithm. - If provided an empty ndarray, the function returns `NaN`. + Both input ndarrays should have the same number of elements. + + If provided empty one-dimensional ndarrays, the function returns `NaN`. Parameters ---------- @@ -13,21 +14,22 @@ - first one-dimensional input ndarray. - second one-dimensional input ndarray. - - a zero-dimensional ndarray specifying degrees of freedom + - a zero-dimensional ndarray specifying the 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 covariance according to `N-c` where `c` corresponds to the provided - degrees of freedom adjustment. When computing the population + degrees of freedom adjustment and `N` corresponds to the number of + elements in each input ndarray. When computing the population covariance, setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample covariance, setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). - - a zero-dimensional ndarray specifying mean of the first - one-dimensional ndarray. - - a zero-dimensional ndarray specifying mean of the second - one-dimensional ndarray. + - a zero-dimensional ndarray specifying the mean of the first one- + dimensional ndarray. + - a zero-dimensional ndarray specifying the mean of the second one- + dimensional ndarray. Returns ------- diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts index d71c36d3a8e9..eeadddfde502 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/docs/types/index.d.ts @@ -31,9 +31,9 @@ import { float64ndarray } from '@stdlib/types/ndarray'; * * - first one-dimensional input ndarray. * - second one-dimensional input ndarray. -* - a zero-dimensional ndarray specifying 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 covariance according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the population covariance, setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample covariance, setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). -* - a zero-dimensional ndarray specifying mean of the first one-dimensional ndarray. -* - a zero-dimensional ndarray specifying mean of the second one-dimensional ndarray. +* - a zero-dimensional ndarray specifying the 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 covariance according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment and `N` corresponds to the number of elements in each input ndarray. When computing the population covariance, setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample covariance, setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). +* - a zero-dimensional ndarray specifying the mean of the first one-dimensional ndarray. +* - a zero-dimensional ndarray specifying the mean of the second one-dimensional ndarray. * * @param arrays - array-like object containing input ndarrays * @returns covariance diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/examples/index.js index f348fa53f761..c06e5bc0572c 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/examples/index.js @@ -29,14 +29,13 @@ var opts = { 'dtype': 'float64' }; -// Create first one-dimensional ndarray containing pseudorandom integers drawn from a discrete uniform distribution: +// Create one-dimensional ndarrays containing pseudorandom numbers: var xbuf = discreteUniform( 10, -50, 50, opts ); var x = new ndarray( opts.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); -// Create second one-dimensional ndarray containing pseudorandom integers drawn from a discrete uniform distribution: var ybuf = discreteUniform( 10, -50, 50, opts ); -var y = new ndarray( opts.dtype, ybuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +var y = new ndarray( opts.dtype, ybuf, [ ybuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( y ) ); // Specify the degrees of freedom adjustment: diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js index a04d6a397486..66f89996c544 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/lib/main.js @@ -39,9 +39,9 @@ var strided = require( '@stdlib/stats/strided/dcovarmtk' ).ndarray; * * - first one-dimensional input ndarray. * - second one-dimensional input ndarray. -* - a zero-dimensional ndarray specifying 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 covariance according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the population covariance, setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample covariance, setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). -* - a zero-dimensional ndarray specifying mean of the first one-dimensional ndarray. -* - a zero-dimensional ndarray specifying mean of the second one-dimensional ndarray. +* - a zero-dimensional ndarray specifying the 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 covariance according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment and `N` corresponds to the number of elements in each input ndarray. When computing the population covariance, setting this parameter to `0` is the standard choice (i.e., the provided arrays contain data constituting entire populations). When computing the unbiased sample covariance, setting this parameter to `1` is the standard choice (i.e., the provided arrays contain data sampled from larger populations; this is commonly referred to as Bessel's correction). +* - a zero-dimensional ndarray specifying the mean of the first one-dimensional ndarray. +* - a zero-dimensional ndarray specifying the mean of the second one-dimensional ndarray. * * @param {ArrayLikeObject} arrays - array-like object containing input ndarrays * @returns {number} covariance diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/package.json index 52b0d204caa7..32030201d611 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dcovarmtk/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/stats/base/ndarray/dcovarmtk", "version": "0.0.0", - "description": "Computes the covariance of two one-dimensional double-precision floating-point ndarrays provided known means and using a one-pass textbook algorithm.", + "description": "Compute the covariance of two one-dimensional double-precision floating-point ndarrays provided known means and using a one-pass textbook algorithm.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors",