From 071523081e63bae776b90f3102753ccaada55929 Mon Sep 17 00:00:00 2001 From: nasarobot Date: Sun, 30 Mar 2025 19:06:50 +0530 Subject: [PATCH 1/5] feat(stats): add package --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanmmda/README.md | 186 ++++++++++++++++++ .../stats/incr/nanmmda/benchmark/benchmark.js | 69 +++++++ .../equation_mean_directional_accuracy.svg | 115 +++++++++++ .../@stdlib/stats/incr/nanmmda/docs/repl.txt | 50 +++++ .../stats/incr/nanmmda/docs/types/index.d.ts | 83 ++++++++ .../stats/incr/nanmmda/docs/types/test.ts | 75 +++++++ .../stats/incr/nanmmda/examples/index.js | 45 +++++ .../@stdlib/stats/incr/nanmmda/lib/index.js | 66 +++++++ .../@stdlib/stats/incr/nanmmda/lib/main.js | 89 +++++++++ .../@stdlib/stats/incr/nanmmda/package.json | 82 ++++++++ .../@stdlib/stats/incr/nanmmda/test/test.js | 152 ++++++++++++++ 11 files changed, 1012 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmda/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmda/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmda/docs/img/equation_mean_directional_accuracy.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmda/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmda/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmda/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmda/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmda/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmda/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmda/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmda/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmda/README.md new file mode 100644 index 000000000000..d4b34e1622a5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/README.md @@ -0,0 +1,186 @@ + + +# incrnanmmda + +> Compute a moving [mean directional accuracy][mean-directional-accuracy] (MDA) incrementally, ignoring `NaN` values. + +
+ +For a window of size `W`, the [mean directional accuracy][mean-directional-accuracy] is defined as + + + +```math +\mathop{\mathrm{MDA}} = \begin{cases} 1 & \textrm{if}\ W = 1 \\ \frac{1}{W} \sum_{i=1}^{W} \delta_{\mathop{\mathrm{sgn}}(\Delta f_{i,i-1}),\ \mathop{\mathrm{sgn}}(\Delta a_{i,i-1})} & \textrm{if}\ W > 1 \end{cases} +``` + + + + + +where `f_i` is the forecast value, `a_i` is the actual value, `sgn(x)` is the [signum][@stdlib/math/base/special/signum] function, and `δ` is the [Kronecker delta][@stdlib/math/base/special/kronecker-delta]. + +
+ + + +
+ +## Usage + +```javascript +var incrnanmmda = require( '@stdlib/stats/incr/nanmmda' ); +``` + +#### incrnanmmda( window ) + +Returns an accumulator `function` which incrementally computes a moving [mean directional accuracy][mean-directional-accuracy], ignoring `NaN` values. The `window` parameter defines the number of values over which to compute the moving [mean directional accuracy][mean-directional-accuracy]. + +```javascript +var accumulator = incrnanmmda( 3 ); +``` + +#### accumulator( \[f, a] ) + +If provided input values `f` and `a`, the accumulator function returns an updated [mean directional accuracy][mean-directional-accuracy]. If not provided input values `f` and `a`, the accumulator function returns the current [mean directional accuracy][mean-directional-accuracy]. + +```javascript +var accumulator = incrnanmmda( 3 ); + +var m = accumulator(); +// returns null + +m = accumulator( NaN, 4.0 ); +// returns null + +// Fill the window... +m = accumulator( 2.0, 3.0 ); // [(+,+)] +// returns 1.0 + +m = accumulator( 1.0, 4.0 ); // [(+,+), (-,+)] +// returns 0.5 + +m = accumulator( 3.0, NaN ); // [(+,+), (-,+)] +// returns 0.5 + +m = accumulator( 3.0, 9.0 ); // [(+,+), (-,+), (+,+)] +// returns ~0.67 + +// Window begins sliding... +m = accumulator( 7.0, 3.0 ); // [(-,+), (+,+), (+,-)] +// returns ~0.33 + +m = accumulator( NaN, NaN ); // [(-,+), (+,+), (+,-)] +// returns -0.33 + +m = accumulator( 5.0, 3.0 ); // [(+,+), (+,-), (-,0)] +// returns ~0.33 + +m = accumulator(); +// returns ~0.33 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is **not** changed and the current input values get **ignored**. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. +- As `W` (f,a) pairs are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values. + +
+ + + +
+ +## Examples + + + +```javascript +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var randu = require( '@stdlib/random/base/randu' ); +var incrnanmmda = require( '@stdlib/stats/incr/nanmmda' ); + +var accumulator; +var v1; +var v2; +var i; + +// Initialize an accumulator: +accumulator = incrnanmmda( 5 ); + +// For each simulated datum, update the moving mean directional accuracy... +for ( i = 0; i < 100; i++ ) { + v1 = ( bernoulli( 0.1 ) ) ? NaN : ( randu()*100.0 ) - 50.0; + v2 = ( bernoulli( 0.1 ) ) ? NaN : ( randu()*100.0 ) - 50.0; + accumulator( v1, v2 ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmmda/benchmark/benchmark.js new file mode 100644 index 000000000000..ee0adb5abb10 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/benchmark/benchmark.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 bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var pkg = require( './../package.json' ).name; +var incrnanmmda = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmmda( (i%5)+1 ); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::accumulator', function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnanmmda( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu()-0.5, randu()-0.5 ); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/docs/img/equation_mean_directional_accuracy.svg b/lib/node_modules/@stdlib/stats/incr/nanmmda/docs/img/equation_mean_directional_accuracy.svg new file mode 100644 index 000000000000..266057954f27 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/docs/img/equation_mean_directional_accuracy.svg @@ -0,0 +1,115 @@ + +upper M upper D upper A equals StartLayout Enlarged left-brace 1st Row 1st Column 1 2nd Column if upper W equals 1 2nd Row 1st Column StartFraction 1 Over upper W EndFraction sigma-summation Underscript i equals 1 Overscript upper W Endscripts delta Subscript s g n left-parenthesis normal upper Delta f Sub Subscript i comma i minus 1 Subscript right-parenthesis comma s g n left-parenthesis normal upper Delta a Sub Subscript i comma i minus 1 Subscript right-parenthesis Baseline 2nd Column if upper W greater-than 1 EndLayout + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmmda/docs/repl.txt new file mode 100644 index 000000000000..1639f016da83 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/docs/repl.txt @@ -0,0 +1,50 @@ + +{{alias}}( W ) + Returns an accumulator function which incrementally computes a moving + mean directional accuracy (MDA), ignoring `NaN` values. + + The `W` parameter defines the number of values over which to compute the + moving mean directional accuracy. + + If provided input values, the accumulator function returns an updated moving + mean directional accuracy. If not provided input values or if either of the + provided values is `NaN`, the accumulator function returns the current + moving mean directional accuracy. + + As `W` (f,a) pairs are needed to fill the window buffer, the first `W-1` + returned values are calculated from smaller sample sizes. Until the window + is full, each returned value is calculated from all provided values. + + Parameters + ---------- + W: integer + Window size. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}( 3 ); + > var m = accumulator() + null + > m = accumulator( 2.0, 3.0 ) + 1.0 + > m = accumulator( 5.0, 2.0 ) + 0.5 + > m = accumulator( NaN, NaN ) + 0.5 + > m = accumulator( 3.0, 2.0 ) + ~0.33 + > m = accumulator( 4.0, NaN ) + ~0.33 + > m = accumulator( 4.0, 5.0 ) + ~0.33 + > m = accumulator() + ~0.33 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmmda/docs/types/index.d.ts new file mode 100644 index 000000000000..68f915220995 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/docs/types/index.d.ts @@ -0,0 +1,83 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +/** +* If provided a value, the accumulator function returns an updated mean directional accuracy. If not provided a value or if either of the provided values is `NaN`, the accumulator function returns the current mean directional accuracy. +* +* ## Notes +* +* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is not updated and the current value is returned. +* +* @param f - forecast value +* @param a - actual value +* @returns mean directional accuracy or null +*/ +type accumulator = ( f?: number, a?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a moving mean directional accuracy, ignoring `NaN` values. +* +* ## Notes +* +* - The `W` parameter defines the number of values over which to compute the moving mean directional accuracy. +* - As `W` (f,a) pairs are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values. +* +* @param W - window size +* @throws must provide a positive integer +* @returns accumulator function +* +* @example +* var accumulator = incrnanmmda( 3 ); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( NaN, 4.0 ); +* // returns null +* +* m = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* m = accumulator( 5.0, 2.0 ); +* // returns 0.5 +* +* m = accumulator( NaN, NaN ); +* // returns 0.5 +* +* m = accumulator( 3.0, 2.0 ); +* // returns ~0.33 +* +* m = accumulator( 4.0, NaN ); +* // returns ~0.33 +* +* m = accumulator( 4.0, 5.0 ); +* // returns ~0.33 +* +* m = accumulator(); +* // returns ~0.33 +*/ +declare function incrnanmmda( W: number ): accumulator; + + +// EXPORTS // + +export = incrnanmmda; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmmda/docs/types/test.ts new file mode 100644 index 000000000000..11ee6f2de0d8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/docs/types/test.ts @@ -0,0 +1,75 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import incrnanmmda = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmmda( 3 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided an argument that is not a number... +{ + incrnanmmda( '5' ); // $ExpectError + incrnanmmda( true ); // $ExpectError + incrnanmmda( false ); // $ExpectError + incrnanmmda( null ); // $ExpectError + incrnanmmda( undefined ); // $ExpectError + incrnanmmda( [] ); // $ExpectError + incrnanmmda( {} ); // $ExpectError + incrnanmmda( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + incrnanmmda(); // $ExpectError + incrnanmmda( 3, 2 ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmmda( 3 ); + + acc(); // $ExpectType number | null + acc( NaN, 2.0 ); // $ExpectType number | null + acc( 3.14, 2.0 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrnanmmda( 3 ); + + acc( '5', 2.0 ); // $ExpectError + acc( true, 2.0 ); // $ExpectError + acc( false, 2.0 ); // $ExpectError + acc( null, 2.0 ); // $ExpectError + acc( [], 2.0 ); // $ExpectError + acc( {}, 2.0 ); // $ExpectError + acc( ( x: number ): number => x, 2.0 ); // $ExpectError + + acc( 3.14, '5' ); // $ExpectError + acc( 3.14, true ); // $ExpectError + acc( 3.14, false ); // $ExpectError + acc( 3.14, null ); // $ExpectError + acc( 3.14, [] ); // $ExpectError + acc( 3.14, {} ); // $ExpectError + acc( 3.14, ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmda/examples/index.js new file mode 100644 index 000000000000..fbcb9e9fdd2f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var randu = require( '@stdlib/random/base/randu' ); +var incrnanmmda = require( './../lib' ); + +var accumulator; +var v1; +var v2; +var m; +var i; + +// Initialize an accumulator: +accumulator = incrnanmmda( 5 ); + +// For each simulated datum, update the moving mean directional accuracy... +console.log( '\nValue\tValue\tMDA\n' ); +for ( i = 0; i < 100; i++ ) { + v1 = ( bernoulli( 0.1 ) ) ? NaN : ( randu()*100.0 ) - 50.0; + v2 = ( bernoulli( 0.1 ) ) ? NaN : ( randu()*100.0 ) - 50.0; + m = accumulator( v1, v2 ); + if ( m === null ) { + console.log( '%d\t%d\t%s', v1.toFixed( 3 ), v2.toFixed( 3 ), m ); + } else { + console.log( '%d\t%d\t%d', v1.toFixed( 3 ), v2.toFixed( 3 ), m.toFixed( 3 ) ); + } +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmda/lib/index.js new file mode 100644 index 000000000000..b3e1fc5cac18 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/lib/index.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute a moving mean directional accuracy incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanmmda +* +* @example +* var incrnanmmda = require( '@stdlib/stats/incr/nanmmda' ); +* +* var accumulator = incrnanmmda( 3 ); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( NaN, 4.0 ); +* // returns null +* +* m = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* m = accumulator( 5.0, 2.0 ); +* // returns 0.5 +* +* m = accumulator( NaN, NaN ); +* // returns 0.5 +* +* m = accumulator( 3.0, 2.0 ); +* // returns ~0.33 +* +* m = accumulator( 4.0, NaN ); +* // returns ~0.33 +* +* m = accumulator( 4.0, 5.0 ); +* // returns ~0.33 +* +* m = accumulator(); +* // returns ~0.33 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmda/lib/main.js new file mode 100644 index 000000000000..54b7d5e4c203 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/lib/main.js @@ -0,0 +1,89 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrmmda = require( '@stdlib/stats/incr/mmda' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a moving mean directional accuracy, ignoring `NaN` values. +* +* @param {PositiveInteger} W - window size +* @throws {TypeError} must provide a positive integer +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanmmda( 3 ); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* m = accumulator( 5.0, 2.0 ); +* // returns 0.5 +* +* m = accumulator( NaN, NaN ); +* // returns 0.5 +* +* m = accumulator( 3.0, 2.0 ); +* // returns ~0.33 +* +* m = accumulator( 4.0, NaN ); +* // returns ~0.33 +* +* m = accumulator( 4.0, 5.0 ); +* // returns ~0.33 +* +* m = accumulator(); +* // returns ~0.33 +*/ +function incrnanmmda( W ) { + var mmda = incrmmda( W ); + return accumulator; + + /** + * If provided input values, the accumulator function returns an updated mean directional accuracy. If not provided input values or if either of the values provided is NaN, the accumulator function returns the current mean directional. + * + * @private + * @param {number} [f] - forecast value + * @param {number} [a] - actual value + * @returns {(number|null)} mean directional accuracy or null + */ + function accumulator( f, a ) { + if ( arguments.length === 0 ) { + return mmda(); + } + if ( isnan( f ) || isnan( a ) ) { + return mmda(); + } + return mmda( f, a ); + } +} + + +// EXPORTS // + +module.exports = incrnanmmda; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/package.json b/lib/node_modules/@stdlib/stats/incr/nanmmda/package.json new file mode 100644 index 000000000000..cf4ea7537fa8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/package.json @@ -0,0 +1,82 @@ +{ + "name": "@stdlib/stats/incr/nanmmda", + "version": "0.0.0", + "description": "Compute a moving mean directional accuracy (MDA) incrementally, ignoring `NaN` values.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "average", + "avg", + "mean", + "direction", + "directional", + "accuracy", + "trend", + "incremental", + "accumulator", + "moving mean", + "moving average", + "sliding window", + "sliding", + "window", + "moving", + "time series", + "timeseries", + "demand", + "forecasting", + "forecast", + "economics", + "econ", + "finance" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmmda/test/test.js new file mode 100644 index 000000000000..79b97d93a537 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/test/test.js @@ -0,0 +1,152 @@ +/** +* @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 abs = require( '@stdlib/math/base/special/abs' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var incrnanmmda = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmmda, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided a positive integer', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + 3.14, + true, + null, + void 0, + NaN, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + incrnanmmda( value ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanmmda( 3 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the accumulator function computes a moving mean directional accuracy incrementally', function test( t ) { + var expected; + var actual; + var delta; + var data; + var acc; + var tol; + var N; + var i; + + data = [ + [ 2.0, 3.0 ], // +,+ + [ 3.0, 1.0 ], // +,- + [ 5.0, 2.0 ], // +,+ + [ NaN, 2.0 ], // 0,0 + [ 4.0, 4.0 ], // -,+ + [ -3.0, 10.0 ], // -,+ + [ 3.0, NaN ], // 0,0 + [ 4.0, -5.0 ], // +,- + [ NaN, NaN ], // 0,0 + [ 4.0, -5.0 ], // 0,0 + [ -4.0, -6.0 ] // -,- + ]; + N = data.length; + + acc = incrnanmmda( 3 ); + + // Note: manually computed + expected = [ + 1.0, + 1.0/2.0, + 2.0/3.0, + 2.0/3.0, + 1.0/3.0, + 1.0/3.0, + 1.0/3.0, + 0.0/3.0, + 0.0/3.0, + 1.0/3.0, + 2.0/3.0 + ]; + for ( i = 0; i < N; i++ ) { + actual = acc( data[i][0], data[i][1] ); + if ( actual === expected[i] ) { + t.equal( actual, expected[i], 'returns expected value' ); + } else { + delta = abs( expected[i] - actual ); + tol = 1.0 * EPS * abs( expected[i] ); + t.equal( delta <= tol, true, 'within tolerance. Actual: '+actual+'. Expected: '+expected[i]+'. Delta: '+delta+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current mean directional accuracy', function test( t ) { + var data; + var acc; + var i; + + data = [ + [ NaN, NaN ], // 0,0 + [ 2.0, 3.0 ], // +,+ + [ 3.0, 5.0 ], // +,+ + [ NaN, 2.0 ], // 0,0 + [ 1.0, 10.0 ] // -,+ + ]; + acc = incrnanmmda( 2 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[i][0], data[i][1] ); + } + t.equal( acc(), 0.5, 'returns expected value' ); + t.end(); +}); + +tape( 'if data has yet to be provided, the accumulator function returns `null`', function test( t ) { + var acc = incrnanmmda( 3 ); + t.equal( acc(), null, 'returns null' ); + acc( NaN, 1.0 ); + t.equal( acc(), null, 'returns null' ); + t.end(); +}); From 24c8a3020d4047634c50b2235fd40009c4661db9 Mon Sep 17 00:00:00 2001 From: nasarobot Date: Mon, 31 Mar 2025 13:36:50 +0530 Subject: [PATCH 2/5] style: fix lint error --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/stats/incr/nanmmda/lib/main.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmda/lib/main.js index 54b7d5e4c203..e8e4991d9f13 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmda/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/lib/main.js @@ -73,10 +73,7 @@ function incrnanmmda( W ) { * @returns {(number|null)} mean directional accuracy or null */ function accumulator( f, a ) { - if ( arguments.length === 0 ) { - return mmda(); - } - if ( isnan( f ) || isnan( a ) ) { + if ( arguments.length === 0 || isnan( f ) || isnan( a ) ) { return mmda(); } return mmda( f, a ); From b36a88aad61ae2e09d4dd745f9ef032fe2b767f1 Mon Sep 17 00:00:00 2001 From: nasarobot Date: Mon, 31 Mar 2025 13:38:28 +0530 Subject: [PATCH 3/5] chore: refactor two if statements to one if statement --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanmmda/benchmark/benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmmda/benchmark/benchmark.js index ee0adb5abb10..fc41818e7716 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmda/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/benchmark/benchmark.js @@ -33,7 +33,7 @@ bench( pkg, function benchmark( b ) { var i; b.tic(); for ( i = 0; i < b.iterations; i++ ) { - f = incrnanmmda( (i%5)+1 ); + f = incrnanmmda( ( i%5 ) + 1 ); if ( typeof f !== 'function' ) { b.fail( 'should return a function' ); } From 50088f181f6c763d689339d4080b525e07d26e65 Mon Sep 17 00:00:00 2001 From: nasarobot Date: Mon, 31 Mar 2025 13:41:41 +0530 Subject: [PATCH 4/5] docs: remove related links from README.md to let stdlib-bot regenerate --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanmmda/README.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmda/README.md index d4b34e1622a5..3fe336d8ff1b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmda/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/README.md @@ -152,12 +152,6 @@ console.log( accumulator() ); @@ -173,14 +167,6 @@ console.log( accumulator() ); [@stdlib/math/base/special/kronecker-delta]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/kronecker-delta - - -[@stdlib/stats/incr/mda]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mda - -[@stdlib/stats/incr/mmape]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mmape - - - From 119b34aaaa816d1b2f77479dad4db2debf48fbd2 Mon Sep 17 00:00:00 2001 From: nasarobot Date: Mon, 31 Mar 2025 20:08:32 +0530 Subject: [PATCH 5/5] docs: fix 2 new lines instead of 1 before links section ending tag --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/stats/incr/nanmmda/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmda/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmda/README.md index 3fe336d8ff1b..a7a60097576b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmda/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmmda/README.md @@ -167,6 +167,7 @@ console.log( accumulator() ); [@stdlib/math/base/special/kronecker-delta]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/kronecker-delta +