From fab188631640576b8506c3dd8354b095876f64e8 Mon Sep 17 00:00:00 2001 From: hans Date: Wed, 19 Mar 2025 15:16:47 -0400 Subject: [PATCH 1/4] feat(stats): add nanmda 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/nanmda/README.md | 175 ++++++++++++++++++ .../stats/incr/nanmda/benchmark/benchmark.js | 69 +++++++ .../equation_mean_directional_accuracy.svg | 115 ++++++++++++ .../@stdlib/stats/incr/nanmda/docs/repl.txt | 34 ++++ .../stats/incr/nanmda/docs/types/index.d.ts | 64 +++++++ .../stats/incr/nanmda/docs/types/test.ts | 69 +++++++ .../stats/incr/nanmda/examples/index.js | 49 +++++ .../@stdlib/stats/incr/nanmda/lib/index.js | 54 ++++++ .../@stdlib/stats/incr/nanmda/lib/main.js | 78 ++++++++ .../@stdlib/stats/incr/nanmda/package.json | 76 ++++++++ .../@stdlib/stats/incr/nanmda/test/test.js | 110 +++++++++++ 11 files changed, 893 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmda/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmda/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmda/docs/img/equation_mean_directional_accuracy.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmda/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmda/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmda/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmda/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmda/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmda/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/README.md b/lib/node_modules/@stdlib/stats/incr/nanmda/README.md new file mode 100644 index 000000000000..0a0cdb8b7812 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/README.md @@ -0,0 +1,175 @@ + + +# incrnanmda + +> Compute the [mean directional accuracy][mean-directional-accuracy] (MDA) incrementally, ignoring `NaN` value. + +
+ +The [mean directional accuracy][mean-directional-accuracy] is defined as + + + +```math +\mathop{\mathrm{MDA}} = \begin{cases} 1 & \textrm{if}\ N = 1 \\\frac{1}{N} \sum_{i=1}^{N} \delta_{\mathop{\mathrm{sgn}}(\Delta f_{i,i-1}),\ \mathop{\mathrm{sgn}}(\Delta a_{i,i-1})} & \textrm{if}\ N > 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 incrnanmda = require( '@stdlib/stats/incr/nanmda' ); +``` + +#### incrnanmda() + +Returns an accumulator `function` which incrementally computes the [mean directional accuracy][mean-directional-accuracy], ignoring `NaN` value. + +```javascript +var accumulator = incrnanmda(); +``` + +#### 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 = incrnanmda(); + +var m = accumulator( 2.0, 3.0 ); +// returns 1.0 + +m = accumulator( -1.0, 4.0 ); +// returns 0.5 + +m = accumulator( NaN, 4.0 ); +// returns 0.5 + +m = accumulator( -3.0, -2.0 ); +// returns ~0.67 + +m = accumulator(); +// returns ~0.67 +``` + +
+ + + +
+ +## Notes + +- Input values are type checked. If provided a NaN or a non-numeric value, the update is skipped and the accumulator returns the previously computed mean directional accuracy. If non-numeric inputs are possible, you are advised to type check and handle accordingly before passing the value to the accumulator function. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanmda = require( '@stdlib/stats/incr/nanmda' ); + +var accumulator; +var v1; +var v2; +var i; + +// Initialize an accumulator: +accumulator = incrnanmda(); + +// For each simulated datum, update the mean directional accuracy... +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v1 = NaN; + } else { + v1 = ( randu()*100.0 ) - 50.0; + } + if ( randu() < 0.2 ) { + v2 = NaN; + } else { + v2 = ( randu()*100.0 ) - 50.0; + } + accumulator( v1, v2 ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmda/benchmark/benchmark.js new file mode 100644 index 000000000000..7431dee67118 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/benchmark/benchmark.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 incrnanmda = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmda(); + 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 = incrnanmda(); + + 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/nanmda/docs/img/equation_mean_directional_accuracy.svg b/lib/node_modules/@stdlib/stats/incr/nanmda/docs/img/equation_mean_directional_accuracy.svg new file mode 100644 index 000000000000..c289bdf791d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/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 N equals 1 2nd Row 1st Column StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 1 Overscript upper N 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 N greater-than 1 EndLayout + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmda/docs/repl.txt new file mode 100644 index 000000000000..252cee57075e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/docs/repl.txt @@ -0,0 +1,34 @@ + +{{alias}}() + Returns an accumulator function which incrementally computes the mean + directional accuracy (MDA). + + If provided input values, the accumulator function returns an updated mean + directional accuracy. If not provided input values, the accumulator function + returns the current mean directional accuracy. + + If provided `NaN` or a value which, when used in computations, results in + `NaN`, the accumulated value is `NaN` for all future invocations. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var m = accumulator() + null + > m = accumulator( 2.0, 3.0 ) + 1.0 + > m = accumulator( -5.0, 4.0 ) + 0.5 + > m = accumulator( NaN, 4.0 ) + 0.5 + > m = accumulator() + 0.5 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/index.d.ts new file mode 100644 index 000000000000..12c417526d70 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/index.d.ts @@ -0,0 +1,64 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 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, 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 `NaN` for all future invocations. +* +* @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 the mean directional accuracy, ignoring `NaN` value. +* +* @returns accumulator function +* +* @example +* var accumulator = incrnanmda(); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* m = accumulator( -5.0, 4.0 ); +* // returns 0.5 +* +* m = accumulator( NaN, 4.0 ); +* // returns 0.5 +* +* m = accumulator(); +* // returns 0.5 +*/ +declare function incrnanmda(): accumulator; + + +// EXPORTS // + +export = incrnanmda; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/test.ts new file mode 100644 index 000000000000..1b46dd51eeef --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/test.ts @@ -0,0 +1,69 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 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 innancrmda = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + innancrmda(); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided arguments... +{ + innancrmda( '5' ); // $ExpectError + innancrmda( 5 ); // $ExpectError + innancrmda( true ); // $ExpectError + innancrmda( false ); // $ExpectError + innancrmda( null ); // $ExpectError + innancrmda( undefined ); // $ExpectError + innancrmda( [] ); // $ExpectError + innancrmda( {} ); // $ExpectError + innancrmda( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = innancrmda(); + + acc(); // $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 = innancrmda(); + + 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/nanmda/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmda/examples/index.js new file mode 100644 index 000000000000..e39cea6eeb62 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/examples/index.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 randu = require( '@stdlib/random/base/randu' ); +var incrnanmda = require( './../lib' ); + +var accumulator; +var v2; +var v1; +var m; +var i; + +// Initialize an accumulator: +accumulator = incrnanmda(); + +// For each simulated datum, update the mean directional accuracy... +console.log( '\nValue\tValue\tMDA\n' ); +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v1 = NaN; + } else { + v1 = ( randu()*100.0 ) - 50.0; + } + if ( randu() < 0.2 ) { + v2 = NaN; + } else { + v2 = ( randu()*100.0 ) - 50.0; + } + m = accumulator( v1, v2 ); + console.log( '%d\t%d\t%d', v1.toFixed( 3 ), v2.toFixed( 3 ), m.toFixed( 3 ) ); +} +console.log( '\nFinal MDA: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmda/lib/index.js new file mode 100644 index 000000000000..83f6eb326be1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/lib/index.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 mean directional accuracy (MDA) incrementally, ignoring `NaN` value. +* +* @module @stdlib/stats/incr/nanmda +* +* @example +* var incrnanmda = require( '@stdlib/stats/incr/nanmda' ); +* +* var accumulator = incrnanmda(); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* m = accumulator( -5.0, 4.0 ); +* // returns 0.5 +* +* m = accumulator( NaN, 4.0 ); +* // returns 0.5 +* +* m = accumulator(); +* // returns 0.5 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmda/lib/main.js new file mode 100644 index 000000000000..873c8164899e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/lib/main.js @@ -0,0 +1,78 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 incrmda = require( '@stdlib/stats/incr/mda' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes the mean directional accuracy, ignoring `NaN` value. +* +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanmda(); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* m = accumulator( -5.0, 4.0 ); +* // returns 0.5 +* +* m = accumulator( NaN, 4.0 ); +* // returns 0.5 +* +* m = accumulator(); +* // returns 0.5 +*/ +function incrnanmda() { + var mda; + + mda = incrmda(); + return accumulator; + + /** + * If provided a value, the accumulator function returns an updated mean directional accuracy. If not provided a value, the accumulator function returns the current mean directional accuracy. + * + * @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 || isnan( f ) || isnan( a ) || !isNumber( f ) || !isNumber( a )) { + return mda(); + } + return mda( f, a ); + } +} + + +// EXPORTS // + +module.exports = incrnanmda; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/package.json b/lib/node_modules/@stdlib/stats/incr/nanmda/package.json new file mode 100644 index 000000000000..1c934378fe82 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/package.json @@ -0,0 +1,76 @@ +{ + "name": "@stdlib/stats/incr/nanmda", + "version": "0.0.0", + "description": "Compute the mean directional accuracy (MDA) incrementally.", + "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", + "time series", + "timeseries", + "demand", + "forecasting", + "forecast", + "economics", + "econ", + "finance" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmda/test/test.js new file mode 100644 index 000000000000..fac5dd0bf479 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/test/test.js @@ -0,0 +1,110 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 incrnanmda = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmda, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanmda(), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the initial accumulated value is `null`', function test( t ) { + var acc = incrnanmda(); + t.equal( acc(), null, 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes the mean directional accuracy', 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 ], // +,+ + [ NaN, 1.0 ], // +,+ + [ 2.0, 5.0 ], // -,+ + [ 4.0, -4.0 ], // +,- + [ -3.0, -1.0 ], // -,+ + [ 4.0, 5.0 ] // +,- + ]; + N = data.length; + + expected = [ + 1.0, + 2.0/2.0, + 2.0/2.0, + 2.0/3.0, + 2.0/4.0, + 2.0/5.0, + 3.0/6.0 + ]; + + acc = incrnanmda(); + 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 = [ + [ 2.0, -3.0 ], // +,+ + [ NaN, -3.0 ], // +,+ + [ -3.0, 5.0 ], // -,+ + [ -1.0, 14.0 ] // +,+ + ]; + acc = incrnanmda(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ][ 0 ], data[ i ][ 1 ] ); + } + t.equal( acc(), 2.0/3.0, 'returns expected value' ); + t.end(); +}); From 08c953f56c9302d33a2696da4ca6a42dbec8ebd7 Mon Sep 17 00:00:00 2001 From: hans Date: Wed, 19 Mar 2025 17:53:46 -0400 Subject: [PATCH 2/4] fix(license): year update --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: 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 --- --- lib/node_modules/@stdlib/stats/incr/nanmda/README.md | 2 +- .../@stdlib/stats/incr/nanmda/benchmark/benchmark.js | 2 +- .../@stdlib/stats/incr/nanmda/docs/types/index.d.ts | 2 +- lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/stats/incr/nanmda/examples/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmda/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmda/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmda/test/test.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/README.md b/lib/node_modules/@stdlib/stats/incr/nanmda/README.md index 0a0cdb8b7812..7029ed5f4660 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmda/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2018 The Stdlib Authors. +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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmda/benchmark/benchmark.js index 7431dee67118..37dc07703143 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmda/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/index.d.ts index 12c417526d70..1560e2cc9ed3 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/test.ts index 1b46dd51eeef..12aa31807feb 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmda/examples/index.js index e39cea6eeb62..f184066c4443 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmda/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmda/lib/index.js index 83f6eb326be1..dec2415dff35 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmda/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmda/lib/main.js index 873c8164899e..68a7e8483342 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmda/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmda/test/test.js index fac5dd0bf479..8cb75517c35b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmda/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. From 800647e9801e5d52ce2ee69889f64ac7e76fefe0 Mon Sep 17 00:00:00 2001 From: hans Date: Wed, 19 Mar 2025 17:56:44 -0400 Subject: [PATCH 3/4] fix(license): year update --- 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: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/stats/incr/nanmda/examples/index.js | 4 ++-- lib/node_modules/@stdlib/stats/incr/nanmda/lib/main.js | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmda/examples/index.js index f184066c4443..176d4b68da0c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmda/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/examples/index.js @@ -33,12 +33,12 @@ accumulator = incrnanmda(); // For each simulated datum, update the mean directional accuracy... console.log( '\nValue\tValue\tMDA\n' ); for ( i = 0; i < 100; i++ ) { - if ( randu() < 0.2 ) { + if ( randu() < 0.1 ) { v1 = NaN; } else { v1 = ( randu()*100.0 ) - 50.0; } - if ( randu() < 0.2 ) { + if ( randu() < 0.1 ) { v2 = NaN; } else { v2 = ( randu()*100.0 ) - 50.0; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmda/lib/main.js index 68a7e8483342..ccd52031a7e0 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmda/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/lib/main.js @@ -51,9 +51,7 @@ var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; * // returns 0.5 */ function incrnanmda() { - var mda; - - mda = incrmda(); + var mda = incrmda(); return accumulator; /** From f6cb0b01c640390973811fd26839dc8f7ad9452c Mon Sep 17 00:00:00 2001 From: hans Date: Sat, 22 Mar 2025 11:16:40 -0400 Subject: [PATCH 4/4] fix(stats): update repl.txt --- 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: passed - 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/nanmda/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmda/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmda/docs/repl.txt index 252cee57075e..d9576e8203d4 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmda/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanmda/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}() Returns an accumulator function which incrementally computes the mean - directional accuracy (MDA). + directional accuracy (MDA), ignoring `NaN` value. If provided input values, the accumulator function returns an updated mean directional accuracy. If not provided input values, the accumulator function