From 18cd22c058f2e06ec0e51f5644b610cee4a5baa7 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Tue, 3 Mar 2026 09:51:59 -0800 Subject: [PATCH 1/5] feat: add stats/incr/mkurtosis --- 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/mkurtosis/README.md | 228 ++++++++++++ .../incr/mkurtosis/benchmark/benchmark.js | 91 +++++ .../stats/incr/mkurtosis/docs/repl.txt | 50 +++ .../incr/mkurtosis/docs/types/index.d.ts | 74 ++++ .../stats/incr/mkurtosis/docs/types/test.ts | 65 ++++ .../stats/incr/mkurtosis/examples/index.js | 43 +++ .../@stdlib/stats/incr/mkurtosis/lib/index.js | 54 +++ .../@stdlib/stats/incr/mkurtosis/lib/main.js | 312 ++++++++++++++++ .../@stdlib/stats/incr/mkurtosis/package.json | 79 ++++ .../@stdlib/stats/incr/mkurtosis/test/test.js | 350 ++++++++++++++++++ 10 files changed, 1346 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/mkurtosis/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/mkurtosis/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/mkurtosis/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/mkurtosis/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/README.md b/lib/node_modules/@stdlib/stats/incr/mkurtosis/README.md new file mode 100644 index 000000000000..701dc25ba35f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/README.md @@ -0,0 +1,228 @@ + + +# incrmkurtosis + +> Compute a moving [corrected sample excess kurtosis][sample-excess-kurtosis] incrementally. + +
+ +The [kurtosis][sample-excess-kurtosis] for a random variable `X` is defined as + + + +```math +\mathop{\mathrm{Kurtosis}}[X] = \mathrm{E}\biggl[ \biggl( \frac{X - \mu}{\sigma} \biggr)^4 \biggr] +``` + + + +Using a univariate normal distribution as the standard of comparison, the [excess kurtosis][sample-excess-kurtosis] is the kurtosis minus `3`. + +For a window of `W` values, the [sample excess kurtosis][sample-excess-kurtosis] is + + + +```math +g_2 = \frac{m_4}{m_2^2} - 3 = \frac{\frac{1}{W} \displaystyle\sum_{i=0}^{W-1} (x_i - \bar{x})^4}{\biggl(\frac{1}{W} \displaystyle\sum_{i=0}^{W-1} (x_i - \bar{x})^2\biggr)^2} +``` + + + +The corrected (unbiased under normality) sample excess kurtosis is + + + +```math +G_2 = \frac{(n+1)n}{(n-1)(n-2)(n-3)} \frac{\displaystyle\sum_{i=0}^{n-1} (x_i - \bar{x})^4}{\biggl(\displaystyle\sum_{i=0}^{n-1} (x_i - \bar{x})^2\biggr)^2} - 3 \frac{(n-1)^2}{(n-2)(n-3)} +``` + + + +where `n` is the number of values currently in the window (grows from 1 to `W` during the fill phase, then stays at `W`). + +
+ + + +
+ +## Usage + +```javascript +var incrmkurtosis = require( '@stdlib/stats/incr/mkurtosis' ); +``` + +#### incrmkurtosis( W ) + +Returns an accumulator `function` which incrementally computes a moving [corrected sample excess kurtosis][sample-excess-kurtosis] over a sliding window of size `W`. + +```javascript +var accumulator = incrmkurtosis( 4 ); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated moving [corrected sample excess kurtosis][sample-excess-kurtosis]. If not provided an input value `x`, the accumulator function returns the current moving [corrected sample excess kurtosis][sample-excess-kurtosis]. + +```javascript +var accumulator = incrmkurtosis( 4 ); + +var kurtosis = accumulator( 2.0 ); +// returns null + +kurtosis = accumulator( 2.0 ); +// returns null + +kurtosis = accumulator( -4.0 ); +// returns null + +kurtosis = accumulator( -4.0 ); +// returns -6.0 + +kurtosis = accumulator( 3.0 ); +// returns -5.652200677131425 + +kurtosis = accumulator(); +// returns -5.652200677131425 +``` + +
+ + + +
+ +## Notes + +- The `W` parameter defines the **window size**: only the `W` most recently provided values are used when computing the kurtosis. During the initial fill phase (fewer than `W` values have been provided), the kurtosis is computed over however many values are available. + +- The corrected sample excess kurtosis is only defined for **4 or more** values. If fewer than 4 values have been provided, the accumulator returns `null`. + +- **Algorithm** — The implementation avoids a full O(W) recomputation at each step by maintaining running central moment accumulators `M2`, `M3`, and `M4` (à la Welford). When the window is full, adding a new value `x` and discarding the oldest value `xo` is handled in two O(1) operations: + + 1. **Downdate** — algebraically reverse the Welford update that originally incorporated `xo`, recovering the moments as though `xo` were never in the window. + 2. **Update** — apply the standard Welford update for `x`. + + The downdate formulas, derived by inverting the Welford recurrence, are: + + ```text + mean_new = (W·mean - xo) / (W - 1) + delta = xo - mean_new + deltaN = delta / W + term1 = delta · deltaN · (W - 1) + M2_new = M2 - term1 + M3_new = M3 - term1·deltaN·(W-2) + 3·deltaN·M2_new + M4_new = M4 - term1·deltaN²·(W²-3W+3) - 6·deltaN²·M2_new + 4·deltaN·M3_new + ``` + +- **NaN handling** — Input values are **not** type-checked. If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for, at most, `W` future invocations. Once the `NaN` value leaves the sliding window, the moments are **recomputed from scratch** from the circular buffer and the accumulator recovers. This differs from `@stdlib/stats/incr/kurtosis`, where a `NaN` permanently corrupts all future results. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrmkurtosis = require( '@stdlib/stats/incr/mkurtosis' ); + +var accumulator; +var v; +var i; + +// Initialize a moving kurtosis accumulator with a window size of 20: +accumulator = incrmkurtosis( 20 ); + +// For each simulated datum, update the moving corrected sample excess kurtosis: +for ( i = 0; i < 100; i++ ) { + v = randu() * 100.0; + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + +* * * + +
+ +## References + +- Joanes, D. N., and C. A. Gill. 1998. "Comparing measures of sample skewness and kurtosis." _Journal of the Royal Statistical Society: Series D (The Statistician)_ 47 (1). Blackwell Publishers Ltd: 183–89. doi:[10.1111/1467-9884.00122][@joanes:1998]. +- Pébay, Philippe. 2008. "Formulas for Robust, One-Pass Parallel Computation of Covariances and Arbitrary-Order Statistical Moments." _Technical Report_ SAND2008-6212. Sandia National Laboratories. . +- Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3): 419–20. doi:[10.1080/00401706.1962.10490022][@welford:1962]. + +[@joanes:1998]: http://dx.doi.org/10.1111/1467-9884.00122 +[@welford:1962]: https://doi.org/10.1080/00401706.1962.10490022 + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js new file mode 100644 index 000000000000..98ae9ae5f878 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js @@ -0,0 +1,91 @@ +/** +* @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 incrmkurtosis = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrmkurtosis( 20 ); + 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,window=20', function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrmkurtosis( 20 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu() ); + if ( v !== v && v !== null ) { + b.fail( 'unexpected NaN' ); + } + } + b.toc(); + if ( v !== v && v !== null ) { + b.fail( 'unexpected NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::accumulator,window=100', function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrmkurtosis( 100 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu() ); + if ( v !== v && v !== null ) { + b.fail( 'unexpected NaN' ); + } + } + b.toc(); + if ( v !== v && v !== null ) { + b.fail( 'unexpected NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/repl.txt new file mode 100644 index 000000000000..67e88ed04fec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/repl.txt @@ -0,0 +1,50 @@ + +{{alias}}( W ) + Returns an accumulator function which incrementally computes a moving + corrected sample excess kurtosis. + + The `W` parameter defines the number of values over which to compute the + moving corrected sample excess kurtosis. + + If provided a value, the accumulator function returns an updated moving + corrected sample excess kurtosis. If not provided a value, the accumulator + function returns the current moving corrected sample excess kurtosis. + + As `W` values 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 the kurtosis of all values provided thus + far. + + For fewer than 4 values, the accumulator returns `null`. + + If provided `NaN` or a value which, when used in computations, results in + `NaN`, the accumulated value is `NaN` for, at most, `W` future invocations. + Once the `NaN` value leaves the sliding window, the accumulator recovers. + + Parameters + ---------- + W: integer + Window size. Must be a positive integer. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}( 4 ); + > var v = accumulator( 2.0 ) + null + > v = accumulator( 2.0 ) + null + > v = accumulator( -4.0 ) + null + > v = accumulator( -4.0 ) + -6.0 + > v = accumulator( 3.0 ) + -5.652200677131425 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/index.d.ts new file mode 100644 index 000000000000..8892f603601d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/index.d.ts @@ -0,0 +1,74 @@ +/* +* @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, returns an updated moving corrected sample excess +* kurtosis; otherwise, returns the current moving corrected sample excess +* kurtosis. +* +* ## Notes +* +* - If provided `NaN` or a value which, when used in computations, results +* in `NaN`, the accumulated value is `NaN` for, at most, `W` future +* invocations. Once the `NaN` value leaves the window, the accumulator +* recovers. +* +* @param x - value +* @returns moving corrected sample excess kurtosis or null +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a moving +* corrected sample excess kurtosis. +* +* @param W - window size +* @throws must provide a positive integer +* @returns accumulator function +* +* @example +* var accumulator = incrmkurtosis( 4 ); +* +* var kurtosis = accumulator(); +* // returns null +* +* kurtosis = accumulator( 2.0 ); +* // returns null +* +* kurtosis = accumulator( 2.0 ); +* // returns null +* +* kurtosis = accumulator( -4.0 ); +* // returns null +* +* kurtosis = accumulator( -4.0 ); +* // returns -6.0 +* +* kurtosis = accumulator( 3.0 ); +* // returns -5.652200677131425 +*/ +declare function incrmkurtosis( W: number ): accumulator; + + +// EXPORTS // + +export = incrmkurtosis; diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/test.ts new file mode 100644 index 000000000000..760a2e77cf89 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/test.ts @@ -0,0 +1,65 @@ +/* +* @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 incrmkurtosis = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrmkurtosis( 4 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided a non-number argument... +{ + incrmkurtosis( '5' ); // $ExpectError + incrmkurtosis( true ); // $ExpectError + incrmkurtosis( false ); // $ExpectError + incrmkurtosis( null ); // $ExpectError + incrmkurtosis( undefined ); // $ExpectError + incrmkurtosis( [] ); // $ExpectError + incrmkurtosis( {} ); // $ExpectError + incrmkurtosis( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is not provided any arguments... +{ + incrmkurtosis(); // $ExpectError +} + +// The function returns an accumulator which returns a number or null... +{ + const acc = incrmkurtosis( 4 ); + + acc(); // $ExpectType number | null + acc( 3.14 ); // $ExpectType number | null +} + +// The compiler throws an error if the accumulator is provided invalid arguments... +{ + const acc = incrmkurtosis( 4 ); + + acc( '5' ); // $ExpectError + acc( true ); // $ExpectError + acc( false ); // $ExpectError + acc( null ); // $ExpectError + acc( [] ); // $ExpectError + acc( {} ); // $ExpectError + acc( ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/examples/index.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/examples/index.js new file mode 100644 index 000000000000..5fa33369636b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/examples/index.js @@ -0,0 +1,43 @@ +/** +* @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 incrmkurtosis = require( './../lib' ); + +var accumulator; +var kurtosis; +var v; +var i; + +// Initialize a moving kurtosis accumulator with a window of 20: +accumulator = incrmkurtosis( 20 ); + +// For each simulated datum, update the moving corrected sample excess kurtosis: +console.log( '\nValue\tKurtosis\n' ); +for ( i = 0; i < 100; i++ ) { + v = randu() * 100.0; + kurtosis = accumulator( v ); + if ( kurtosis === null ) { + console.log( '%d\t%s', v.toFixed( 4 ), kurtosis ); + } else { + console.log( '%d\t%d', v.toFixed( 4 ), kurtosis.toFixed( 4 ) ); + } +} +console.log( '\nFinal moving kurtosis: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/index.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/index.js new file mode 100644 index 000000000000..41ce5378e585 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/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 a moving corrected sample excess kurtosis incrementally. +* +* @module @stdlib/stats/incr/mkurtosis +* +* @example +* var incrmkurtosis = require( '@stdlib/stats/incr/mkurtosis' ); +* +* var accumulator = incrmkurtosis( 4 ); +* +* var kurtosis = accumulator( 2.0 ); +* // returns null +* +* kurtosis = accumulator( 2.0 ); +* // returns null +* +* kurtosis = accumulator( -4.0 ); +* // returns null +* +* kurtosis = accumulator( -4.0 ); +* // returns -6.0 +* +* kurtosis = accumulator( 3.0 ); +* // returns -5.652200677131425 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js new file mode 100644 index 000000000000..ee26793dcb60 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js @@ -0,0 +1,312 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var Float64Array = require( '@stdlib/array/float64' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a moving corrected sample excess kurtosis. +* +* ## Method +* +* The algorithm maintains running central moment accumulators `M2`, `M3`, +* and `M4` using Welford's online algorithm. When the window is full, each +* new datum triggers an O(1) downdate (removing the oldest value) followed +* by an O(1) update (adding the newest value). +* +* ### Welford update (adding value `x`, going from `n-1` to `n` values) +* +* ```text +* delta = x - mean_prev +* deltaN = delta / n +* term1 = delta * deltaN * (n - 1) +* M4 += term1 * deltaN^2 * (n^2 - 3n + 3) + 6*deltaN^2*M2 - 4*deltaN*M3 +* M3 += term1 * deltaN * (n - 2) - 3*deltaN*M2 +* M2 += term1 +* mean += deltaN +* ``` +* +* ### Welford downdate (removing value `xo`, going from `n` to `n-1` values) +* +* ```text +* mean_new = (n*mean - xo) / (n - 1) +* delta = xo - mean_new +* deltaN = delta / n +* term1 = delta * deltaN * (n - 1) +* M2_new = M2 - term1 +* M3_new = M3 - term1*deltaN*(n-2) + 3*deltaN*M2_new +* M4_new = M4 - term1*deltaN^2*(n^2-3n+3) - 6*deltaN^2*M2_new + 4*deltaN*M3_new +* ``` +* +* The corrected sample excess kurtosis is +* +* ```text +* G_2 = (n-1)/((n-2)*(n-3)) * ((n+1)*g2 + 6) +* ``` +* +* where `g2 = n*M4/M2^2 - 3`. +* +* ## Notes +* +* - The kurtosis is only defined for a window containing at least 4 values. +* For fewer values the accumulator returns `null`. +* +* - Input values are **not** type-checked. If a `NaN` enters the window, +* the accumulator returns `NaN` until the `NaN` leaves the window, at +* which point the central moments are recomputed from the circular buffer. +* +* ## References +* +* - Joanes, D. N., and C. A. Gill. 1998. "Comparing measures of sample +* skewness and kurtosis." _Journal of the Royal Statistical Society: +* Series D (The Statistician)_ 47 (1). Blackwell Publishers Ltd: 183-89. +* doi:[10.1111/1467-9884.00122][@joanes:1998]. +* +* [@joanes:1998]: http://dx.doi.org/10.1111/1467-9884.00122 +* +* @param {PositiveInteger} W - window size +* @throws {TypeError} must provide a positive integer +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrmkurtosis( 4 ); +* +* var kurtosis = accumulator(); +* // returns null +* +* kurtosis = accumulator( 2.0 ); +* // returns null +* +* kurtosis = accumulator( 2.0 ); +* // returns null +* +* kurtosis = accumulator( -4.0 ); +* // returns null +* +* kurtosis = accumulator( -4.0 ); +* // returns -6.0 +* +* kurtosis = accumulator( 3.0 ); +* // returns -5.652200677131425 +*/ +function incrmkurtosis( W ) { + var deltaN2; + var deltaN; + var delta; + var term1; + var mean; + var nans; + var buf; + var M2; + var M3; + var M4; + var g2; + var N; + var n; + var i; + + if ( !isPositiveInteger( W ) ) { + throw new TypeError( format( 'invalid argument. Must provide a positive integer. Value: `%s`.', W ) ); + } + + buf = new Float64Array( W ); + mean = 0.0; + M2 = 0.0; + M3 = 0.0; + M4 = 0.0; + N = 0; + i = -1; + nans = 0; + + return accumulator; + + /** + * If provided a value, returns an updated moving corrected sample excess kurtosis; otherwise, returns the current moving corrected sample excess kurtosis. + * + * @private + * @param {number} [x] - new value + * @returns {(number|null)} corrected sample excess kurtosis or null + */ + function accumulator( x ) { + var xo; + + if ( arguments.length === 0 ) { + if ( nans > 0 ) { + return NaN; + } + n = ( N < W ) ? N : W; + if ( n < 4 ) { + return null; + } + g2 = ( n * M4 / ( M2 * M2 ) ) - 3.0; + return ( (n-1) / ( (n-2)*(n-3) ) ) * ( ( (n+1)*g2 ) + 6.0 ); + } + + // Advance the circular buffer index: + i = ( i + 1 ) % W; + + if ( N < W ) { + // Fill phase: window is not yet full. + buf[ i ] = x; + N += 1; + if ( isnan( x ) ) { + nans += 1; + } + if ( nans > 0 ) { + return NaN; + } + + // Welford update (add x, going from N-1 to N): + n = N; + delta = x - mean; + deltaN = delta / n; + deltaN2 = deltaN * deltaN; + term1 = delta * deltaN * ( n - 1 ); + + M4 += term1 * deltaN2 * ( ( n*n ) - ( 3*n ) + 3 ); + M4 += 6.0 * deltaN2 * M2; + M4 -= 4.0 * deltaN * M3; + + M3 += term1 * deltaN * ( n - 2 ); + M3 -= 3.0 * deltaN * M2; + + M2 += term1; + mean += deltaN; + + if ( n < 4 ) { + return null; + } + g2 = ( n * M4 / ( M2 * M2 ) ) - 3.0; + return ( (n-1) / ( (n-2)*(n-3) ) ) * ( ( (n+1)*g2 ) + 6.0 ); + } + + // Slide phase: window is full (N >= W). + xo = buf[ i ]; + buf[ i ] = x; + + // Track NaN count changes: + if ( isnan( xo ) ) { + nans -= 1; + } + if ( isnan( x ) ) { + nans += 1; + } + + // If a NaN just left the window and none remain, recompute from scratch + // because NaN corrupted the running moment state: + if ( nans === 0 && isnan( xo ) ) { + recompute(); + } else if ( nans > 0 ) { + // NaN still present or just entered; skip moment update: + return NaN; + } else { + // Normal case: downdate xo, then update x. + n = W; + + // Downdate: remove xo from (n, mean, M2, M3, M4). + mean = ( ( n * mean ) - xo ) / ( n - 1 ); + + // Recover delta/deltaN as they were when xo was originally added: + delta = xo - mean; + deltaN = delta / n; + deltaN2 = deltaN * deltaN; + term1 = delta * deltaN * ( n - 1 ); + + M2 -= term1; + M3 -= term1 * deltaN * ( n - 2 ); + M3 += 3.0 * deltaN * M2; + M4 -= term1 * deltaN2 * ( ( n*n ) - ( 3*n ) + 3 ); + M4 -= 6.0 * deltaN2 * M2; + M4 += 4.0 * deltaN * M3; + + // Update: add x to (n-1) values to recover a full window of n: + delta = x - mean; + deltaN = delta / n; + deltaN2 = deltaN * deltaN; + term1 = delta * deltaN * ( n - 1 ); + + M4 += term1 * deltaN2 * ( ( n*n ) - ( 3*n ) + 3 ); + M4 += 6.0 * deltaN2 * M2; + M4 -= 4.0 * deltaN * M3; + + M3 += term1 * deltaN * ( n - 2 ); + M3 -= 3.0 * deltaN * M2; + + M2 += term1; + mean += deltaN; + } + + n = W; + if ( n < 4 ) { + return null; + } + g2 = ( n * M4 / ( M2 * M2 ) ) - 3.0; + return ( (n-1) / ( (n-2)*(n-3) ) ) * ( ( (n+1)*g2 ) + 6.0 ); + } + + /** + * Recomputes central moments M2, M3, M4 and the mean from the circular buffer. + * + * @private + */ + function recompute() { + var v; + var k; + + mean = 0.0; + M2 = 0.0; + M3 = 0.0; + M4 = 0.0; + + // Iterate over buffer from oldest (index (i+1)%W) to newest (index i): + for ( k = 1; k <= W; k++ ) { + v = buf[ ( i + k ) % W ]; + + // Welford update for position k (1-indexed): + n = k; + delta = v - mean; + deltaN = delta / n; + deltaN2 = deltaN * deltaN; + term1 = delta * deltaN * ( n - 1 ); + + M4 += term1 * deltaN2 * ( ( n*n ) - ( 3*n ) + 3 ); + M4 += 6.0 * deltaN2 * M2; + M4 -= 4.0 * deltaN * M3; + + M3 += term1 * deltaN * ( n - 2 ); + M3 -= 3.0 * deltaN * M2; + + M2 += term1; + mean += deltaN; + } + } +} + + +// EXPORTS // + +module.exports = incrmkurtosis; diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/package.json b/lib/node_modules/@stdlib/stats/incr/mkurtosis/package.json new file mode 100644 index 000000000000..175032dd67ef --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/package.json @@ -0,0 +1,79 @@ +{ + "name": "@stdlib/stats/incr/mkurtosis", + "version": "0.0.0", + "description": "Compute a moving corrected sample excess kurtosis 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": { + "@stdlib/array/float64": "^0.0.x", + "@stdlib/assert/is-positive-integer": "^0.0.x", + "@stdlib/math/base/assert/is-nan": "^0.0.x", + "@stdlib/string/format": "^0.0.x" + }, + "devDependencies": { + "@stdlib/constants/float64/eps": "^0.0.x", + "@stdlib/math/base/special/abs": "^0.0.x", + "@stdlib/math/base/special/max": "^0.0.x", + "@stdlib/random/base/randu": "^0.0.x" + }, + "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", + "kurtosis", + "sample kurtosis", + "moving", + "window", + "sliding", + "shape", + "kurt", + "corrected", + "incremental", + "accumulator" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/test/test.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/test/test.js new file mode 100644 index 000000000000..cd1216c8c10c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/test/test.js @@ -0,0 +1,350 @@ +/** +* @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 max = require( '@stdlib/math/base/special/max' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrmkurtosis = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Computes the corrected sample excess kurtosis for an array. +* +* @private +* @param {Array} arr - array of numbers +* @returns {number|null} kurtosis or null +*/ +function naiveKurtosis( arr ) { + var deltaN2; + var deltaN; + var delta; + var term1; + var mean; + var n1; + var M2; + var M3; + var M4; + var g2; + var n; + var i; + + n = arr.length; + if ( n < 4 ) { + return null; + } + mean = 0.0; + M2 = 0.0; + M3 = 0.0; + M4 = 0.0; + for ( i = 0; i < n; i++ ) { + n1 = i + 1; + delta = arr[ i ] - mean; + deltaN = delta / n1; + deltaN2 = deltaN * deltaN; + term1 = delta * deltaN * i; + M4 += term1 * deltaN2 * ( ( n1*n1 ) - ( 3*n1 ) + 3 ); + M4 += 6.0 * deltaN2 * M2; + M4 -= 4.0 * deltaN * M3; + M3 += term1 * deltaN * ( n1 - 2 ); + M3 -= 3.0 * deltaN * M2; + M2 += term1; + mean += deltaN; + } + g2 = ( n * M4 / ( M2 * M2 ) ) - 3.0; + return ( (n-1) / ( (n-2)*(n-3) ) ) * ( ( (n+1)*g2 ) + 6.0 ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrmkurtosis, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws if not provided a positive integer for the window size', function test( t ) { + var values; + var i; + + values = [ + '5', + -5, + 0, + 3.14, + true, + false, + null, + void 0, + NaN, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + incrmkurtosis( value ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.strictEqual( typeof incrmkurtosis( 4 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current moving corrected sample excess kurtosis', function test( t ) { + var data; + var acc; + var i; + + data = [ -10.0, -10.0, 10.0, 10.0 ]; + acc = incrmkurtosis( 4 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.strictEqual( acc(), -6.0, 'returns current kurtosis without advancing state' ); + t.end(); +}); + +tape( 'the accumulator returns `null` until at least 4 datums have been provided', function test( t ) { + var acc; + var out; + + acc = incrmkurtosis( 6 ); + + out = acc(); + t.strictEqual( out, null, 'returns null (0 values)' ); + + out = acc( 2.0 ); + t.strictEqual( out, null, 'returns null (1 value)' ); + + out = acc( 8.0 ); + t.strictEqual( out, null, 'returns null (2 values)' ); + + out = acc( -4.0 ); + t.strictEqual( out, null, 'returns null (3 values)' ); + + out = acc( 3.0 ); + t.notEqual( out, null, 'does not return null (4 values)' ); + + t.end(); +}); + +tape( 'the accumulator returns `null` for all invocations when window size is less than 4', function test( t ) { + var acc; + var out; + var i; + + // W = 3: kurtosis is always undefined. + acc = incrmkurtosis( 3 ); + for ( i = 0; i < 10; i++ ) { + out = acc( i * 1.0 ); + t.strictEqual( out, null, 'returns null for W=3 (iteration '+i+')' ); + } + t.end(); +}); + +tape( 'the accumulator function incrementally computes a moving corrected sample excess kurtosis (window: 4, matches incrkurtosis for first window)', function test( t ) { + var expected; + var actual; + var delta; + var data; + var tol; + var acc; + var i; + + // Using window=4: the first 4 results should match incrkurtosis exactly. + data = [ 2.0, 2.0, -4.0, -4.0 ]; + expected = [ + null, + null, + null, + -6.0 + ]; + + acc = incrmkurtosis( 4 ); + for ( i = 0; i < data.length; i++ ) { + actual = acc( data[ i ] ); + if ( expected[ i ] === null ) { + t.strictEqual( actual, null, 'returns null' ); + } else { + delta = abs( actual - expected[ i ] ); + tol = 2.0 * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol ); + } + } + t.end(); +}); + +tape( 'the accumulator correctly slides the window (W=4)', function test( t ) { + var expected; + var actual; + var delta; + var data; + var tol; + var acc; + var i; + + data = [ 2.0, 2.0, -4.0, -4.0, 1.5, -10.0, 5.0, 3.5, -1.0 ]; + acc = incrmkurtosis( 4 ); + + for ( i = 0; i < data.length; i++ ) { + actual = acc( data[ i ] ); + + if ( i < 3 ) { + t.strictEqual( actual, null, 'returns null for i='+i ); + } else { + // Expected: kurtosis of the last 4 values. + expected = naiveKurtosis( data.slice( max( 0, i-3 ), i+1 ) ); + delta = abs( actual - expected ); + tol = ( 2.0 * EPS * abs( expected ) ) + 1.0e-10; + t.ok( delta <= tol, 'i='+i+' actual: '+actual+' expected: '+expected+' Δ: '+delta+' tol: '+tol ); + } + } + t.end(); +}); + +tape( 'the accumulator correctly slides the window (W=6)', function test( t ) { + var expected; + var actual; + var delta; + var data; + var tol; + var acc; + var i; + + data = [ 3.0, -1.0, 7.0, 2.5, -4.0, 6.0, 1.0, -2.0, 8.0, 5.0 ]; + acc = incrmkurtosis( 6 ); + + for ( i = 0; i < data.length; i++ ) { + actual = acc( data[ i ] ); + if ( i < 3 ) { + t.strictEqual( actual, null, 'returns null for i='+i ); + } else if ( i < 6 ) { + // Window not full yet; compute over first i+1 values: + expected = naiveKurtosis( data.slice( 0, i+1 ) ); + if ( expected === null ) { + t.strictEqual( actual, null, 'returns null for i='+i ); + } else { + delta = abs( actual - expected ); + tol = ( 2.0 * EPS * abs( expected ) ) + 1.0e-10; + t.ok( delta <= tol, 'i='+i+' actual: '+actual+' expected: '+expected+' Δ: '+delta+' tol: '+tol ); + } + } else { + // Window full — last 6 values: + expected = naiveKurtosis( data.slice( i-5, i+1 ) ); + delta = abs( actual - expected ); + tol = ( 2.0 * EPS * abs( expected ) ) + 1.0e-10; + t.ok( delta <= tol, 'i='+i+' actual: '+actual+' expected: '+expected+' Δ: '+delta+' tol: '+tol ); + } + } + t.end(); +}); + +tape( 'the accumulator returns `NaN` when a NaN is in the window', function test( t ) { + var data; + var acc; + var v; + var i; + + // NaN at position 2 (0-indexed), window=4. + data = [ 1.0, 2.0, NaN, -2.0, -3.0, 4.0, 5.0 ]; + acc = incrmkurtosis( 4 ); + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + if ( i >= 3 && i <= 5 ) { + // NaN in the window: positions 2-5. + t.ok( isnan( v ), 'returns NaN while NaN is in the window (i='+i+')' ); + } + } + t.end(); +}); + +tape( 'the accumulator recovers after a NaN exits the window', function test( t ) { + var data; + var acc; + var v; + var i; + + // W=4: NaN at index 0 leaves after 4 slides. + data = [ NaN, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]; + acc = incrmkurtosis( 4 ); + + // Consume NaN and 3 good values: + for ( i = 0; i < 4; i++ ) { + v = acc( data[ i ] ); + + // Returns NaN or null while NaN is present or data is insufficient: + t.ok( isnan( v ) || v === null, 'returns NaN or null (i='+i+')' ); + } + + // Fifth value pushes NaN out of the window: + v = acc( data[ 4 ] ); + t.ok( !isnan( v ), 'recovered from NaN (i=4), got: ' + v ); + t.notEqual( v, null, 'does not return null after recovery' ); + + t.end(); +}); + +tape( 'the accumulator handles a window entirely filled with identical values (kurtosis undefined: M2=0)', function test( t ) { + var acc; + var v; + var i; + + acc = incrmkurtosis( 4 ); + for ( i = 0; i < 8; i++ ) { + v = acc( 5.0 ); + if ( i < 3 ) { + t.strictEqual( v, null, 'returns null for i='+i ); + } else { + // M2=0 leads to division by zero; null, NaN, or Infinity are all acceptable. + t.ok( v === null || isnan( v ) || !isFinite( v ), 'returns null, NaN, or Infinity for degenerate window (i='+i+')' ); + } + } + t.end(); +}); + +tape( 'the accumulator works with window size W=4 and exactly 4 values', function test( t ) { + var acc; + var v; + + acc = incrmkurtosis( 4 ); + + acc( -10.0 ); + acc( -10.0 ); + acc( 10.0 ); + v = acc( 10.0 ); + + t.strictEqual( v, -6.0, 'returns -6.0 for symmetric data' ); + t.end(); +}); From c7d325a98cdb400881357c79ba9975606855db9f Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Tue, 3 Mar 2026 18:31:47 +0000 Subject: [PATCH 2/5] chore: update copyright years --- lib/node_modules/@stdlib/stats/incr/mkurtosis/README.md | 2 +- .../@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js | 2 +- .../@stdlib/stats/incr/mkurtosis/docs/types/index.d.ts | 2 +- .../@stdlib/stats/incr/mkurtosis/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/stats/incr/mkurtosis/examples/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/incr/mkurtosis/test/test.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/README.md b/lib/node_modules/@stdlib/stats/incr/mkurtosis/README.md index 701dc25ba35f..1ce25594334d 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/README.md +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2018 The Stdlib Authors. +Copyright (c) 2026 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/mkurtosis/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js index 98ae9ae5f878..36cab3f03005 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2026 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/mkurtosis/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/index.d.ts index 8892f603601d..74aa4958225d 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2026 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/mkurtosis/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/test.ts index 760a2e77cf89..03b9223d6b2f 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2026 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/mkurtosis/examples/index.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/examples/index.js index 5fa33369636b..aad6df6c4621 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2026 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/mkurtosis/lib/index.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/index.js index 41ce5378e585..72492ae4d5b3 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2026 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/mkurtosis/lib/main.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js index ee26793dcb60..60843c92202a 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2026 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/mkurtosis/test/test.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/test/test.js index cd1216c8c10c..6a43e656a592 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2026 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 b8cab34643b74bfe221b40aa186929e5ab76bd32 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Tue, 3 Mar 2026 11:02:53 -0800 Subject: [PATCH 3/5] feat: add stats/incr/mkurtosis --- 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 --- --- .../@stdlib/stats/incr/mkurtosis/README.md | 14 +++++----- .../incr/mkurtosis/benchmark/benchmark.js | 8 +++--- .../incr/mkurtosis/docs/types/index.d.ts | 6 ++-- .../stats/incr/mkurtosis/docs/types/test.ts | 26 ++++++++--------- .../stats/incr/mkurtosis/examples/index.js | 4 +-- .../@stdlib/stats/incr/mkurtosis/lib/index.js | 4 +-- .../@stdlib/stats/incr/mkurtosis/lib/main.js | 6 ++-- .../@stdlib/stats/incr/mkurtosis/test/test.js | 28 +++++++++---------- 8 files changed, 48 insertions(+), 48 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/README.md b/lib/node_modules/@stdlib/stats/incr/mkurtosis/README.md index 1ce25594334d..21158ccf1f5f 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/README.md +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# incrmkurtosis +# mkurtosis > Compute a moving [corrected sample excess kurtosis][sample-excess-kurtosis] incrementally. @@ -67,15 +67,15 @@ where `n` is the number of values currently in the window (grows from 1 to `W` d ## Usage ```javascript -var incrmkurtosis = require( '@stdlib/stats/incr/mkurtosis' ); +var mkurtosis = require( '@stdlib/stats/incr/mkurtosis' ); ``` -#### incrmkurtosis( W ) +#### mkurtosis( W ) Returns an accumulator `function` which incrementally computes a moving [corrected sample excess kurtosis][sample-excess-kurtosis] over a sliding window of size `W`. ```javascript -var accumulator = incrmkurtosis( 4 ); +var accumulator = mkurtosis( 4 ); ``` #### accumulator( \[x] ) @@ -83,7 +83,7 @@ var accumulator = incrmkurtosis( 4 ); If provided an input value `x`, the accumulator function returns an updated moving [corrected sample excess kurtosis][sample-excess-kurtosis]. If not provided an input value `x`, the accumulator function returns the current moving [corrected sample excess kurtosis][sample-excess-kurtosis]. ```javascript -var accumulator = incrmkurtosis( 4 ); +var accumulator = mkurtosis( 4 ); var kurtosis = accumulator( 2.0 ); // returns null @@ -147,14 +147,14 @@ kurtosis = accumulator(); ```javascript var randu = require( '@stdlib/random/base/randu' ); -var incrmkurtosis = require( '@stdlib/stats/incr/mkurtosis' ); +var mkurtosis = require( '@stdlib/stats/incr/mkurtosis' ); var accumulator; var v; var i; // Initialize a moving kurtosis accumulator with a window size of 20: -accumulator = incrmkurtosis( 20 ); +accumulator = mkurtosis( 20 ); // For each simulated datum, update the moving corrected sample excess kurtosis: for ( i = 0; i < 100; i++ ) { diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js index 36cab3f03005..fa8db9c338a7 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js @@ -23,7 +23,7 @@ var bench = require( '@stdlib/bench' ); var randu = require( '@stdlib/random/base/randu' ); var pkg = require( './../package.json' ).name; -var incrmkurtosis = require( './../lib' ); +var mkurtosis = require( './../lib' ); // MAIN // @@ -33,7 +33,7 @@ bench( pkg, function benchmark( b ) { var i; b.tic(); for ( i = 0; i < b.iterations; i++ ) { - f = incrmkurtosis( 20 ); + f = mkurtosis( 20 ); if ( typeof f !== 'function' ) { b.fail( 'should return a function' ); } @@ -51,7 +51,7 @@ bench( pkg+'::accumulator,window=20', function benchmark( b ) { var v; var i; - acc = incrmkurtosis( 20 ); + acc = mkurtosis( 20 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -73,7 +73,7 @@ bench( pkg+'::accumulator,window=100', function benchmark( b ) { var v; var i; - acc = incrmkurtosis( 100 ); + acc = mkurtosis( 100 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/index.d.ts index 74aa4958225d..b56a6ba2aeaa 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/index.d.ts @@ -46,7 +46,7 @@ type accumulator = ( x?: number ) => number | null; * @returns accumulator function * * @example -* var accumulator = incrmkurtosis( 4 ); +* var accumulator = mkurtosis( 4 ); * * var kurtosis = accumulator(); * // returns null @@ -66,9 +66,9 @@ type accumulator = ( x?: number ) => number | null; * kurtosis = accumulator( 3.0 ); * // returns -5.652200677131425 */ -declare function incrmkurtosis( W: number ): accumulator; +declare function mkurtosis( W: number ): accumulator; // EXPORTS // -export = incrmkurtosis; +export = mkurtosis; diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/test.ts index 03b9223d6b2f..4b163c97ed58 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/docs/types/test.ts @@ -16,36 +16,36 @@ * limitations under the License. */ -import incrmkurtosis = require( './index' ); +import mkurtosis = require( './index' ); // TESTS // // The function returns an accumulator function... { - incrmkurtosis( 4 ); // $ExpectType accumulator + mkurtosis( 4 ); // $ExpectType accumulator } // The compiler throws an error if the function is provided a non-number argument... { - incrmkurtosis( '5' ); // $ExpectError - incrmkurtosis( true ); // $ExpectError - incrmkurtosis( false ); // $ExpectError - incrmkurtosis( null ); // $ExpectError - incrmkurtosis( undefined ); // $ExpectError - incrmkurtosis( [] ); // $ExpectError - incrmkurtosis( {} ); // $ExpectError - incrmkurtosis( ( x: number ): number => x ); // $ExpectError + mkurtosis( '5' ); // $ExpectError + mkurtosis( true ); // $ExpectError + mkurtosis( false ); // $ExpectError + mkurtosis( null ); // $ExpectError + mkurtosis( undefined ); // $ExpectError + mkurtosis( [] ); // $ExpectError + mkurtosis( {} ); // $ExpectError + mkurtosis( ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is not provided any arguments... { - incrmkurtosis(); // $ExpectError + mkurtosis(); // $ExpectError } // The function returns an accumulator which returns a number or null... { - const acc = incrmkurtosis( 4 ); + const acc = mkurtosis( 4 ); acc(); // $ExpectType number | null acc( 3.14 ); // $ExpectType number | null @@ -53,7 +53,7 @@ import incrmkurtosis = require( './index' ); // The compiler throws an error if the accumulator is provided invalid arguments... { - const acc = incrmkurtosis( 4 ); + const acc = mkurtosis( 4 ); acc( '5' ); // $ExpectError acc( true ); // $ExpectError diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/examples/index.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/examples/index.js index aad6df6c4621..6e14f1effa97 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/examples/index.js @@ -19,7 +19,7 @@ 'use strict'; var randu = require( '@stdlib/random/base/randu' ); -var incrmkurtosis = require( './../lib' ); +var mkurtosis = require( './../lib' ); var accumulator; var kurtosis; @@ -27,7 +27,7 @@ var v; var i; // Initialize a moving kurtosis accumulator with a window of 20: -accumulator = incrmkurtosis( 20 ); +accumulator = mkurtosis( 20 ); // For each simulated datum, update the moving corrected sample excess kurtosis: console.log( '\nValue\tKurtosis\n' ); diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/index.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/index.js index 72492ae4d5b3..c4b689385e93 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/index.js @@ -24,9 +24,9 @@ * @module @stdlib/stats/incr/mkurtosis * * @example -* var incrmkurtosis = require( '@stdlib/stats/incr/mkurtosis' ); +* var mkurtosis = require( '@stdlib/stats/incr/mkurtosis' ); * -* var accumulator = incrmkurtosis( 4 ); +* var accumulator = mkurtosis( 4 ); * * var kurtosis = accumulator( 2.0 ); * // returns null diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js index 60843c92202a..f03dea4051e6 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js @@ -93,7 +93,7 @@ var format = require( '@stdlib/string/format' ); * @returns {Function} accumulator function * * @example -* var accumulator = incrmkurtosis( 4 ); +* var accumulator = mkurtosis( 4 ); * * var kurtosis = accumulator(); * // returns null @@ -113,7 +113,7 @@ var format = require( '@stdlib/string/format' ); * kurtosis = accumulator( 3.0 ); * // returns -5.652200677131425 */ -function incrmkurtosis( W ) { +function mkurtosis( W ) { var deltaN2; var deltaN; var delta; @@ -309,4 +309,4 @@ function incrmkurtosis( W ) { // EXPORTS // -module.exports = incrmkurtosis; +module.exports = mkurtosis; diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/test/test.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/test/test.js index 6a43e656a592..022c3ba981e2 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/test/test.js @@ -25,7 +25,7 @@ var abs = require( '@stdlib/math/base/special/abs' ); var max = require( '@stdlib/math/base/special/max' ); var EPS = require( '@stdlib/constants/float64/eps' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var incrmkurtosis = require( './../lib' ); +var mkurtosis = require( './../lib' ); // FUNCTIONS // @@ -82,7 +82,7 @@ function naiveKurtosis( arr ) { tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof incrmkurtosis, 'function', 'main export is a function' ); + t.strictEqual( typeof mkurtosis, 'function', 'main export is a function' ); t.end(); }); @@ -112,13 +112,13 @@ tape( 'the function throws if not provided a positive integer for the window siz function badValue( value ) { return function badValue() { - incrmkurtosis( value ); + mkurtosis( value ); }; } }); tape( 'the function returns an accumulator function', function test( t ) { - t.strictEqual( typeof incrmkurtosis( 4 ), 'function', 'returns a function' ); + t.strictEqual( typeof mkurtosis( 4 ), 'function', 'returns a function' ); t.end(); }); @@ -128,7 +128,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr var i; data = [ -10.0, -10.0, 10.0, 10.0 ]; - acc = incrmkurtosis( 4 ); + acc = mkurtosis( 4 ); for ( i = 0; i < data.length; i++ ) { acc( data[ i ] ); } @@ -140,7 +140,7 @@ tape( 'the accumulator returns `null` until at least 4 datums have been provided var acc; var out; - acc = incrmkurtosis( 6 ); + acc = mkurtosis( 6 ); out = acc(); t.strictEqual( out, null, 'returns null (0 values)' ); @@ -166,7 +166,7 @@ tape( 'the accumulator returns `null` for all invocations when window size is le var i; // W = 3: kurtosis is always undefined. - acc = incrmkurtosis( 3 ); + acc = mkurtosis( 3 ); for ( i = 0; i < 10; i++ ) { out = acc( i * 1.0 ); t.strictEqual( out, null, 'returns null for W=3 (iteration '+i+')' ); @@ -192,7 +192,7 @@ tape( 'the accumulator function incrementally computes a moving corrected sample -6.0 ]; - acc = incrmkurtosis( 4 ); + acc = mkurtosis( 4 ); for ( i = 0; i < data.length; i++ ) { actual = acc( data[ i ] ); if ( expected[ i ] === null ) { @@ -216,7 +216,7 @@ tape( 'the accumulator correctly slides the window (W=4)', function test( t ) { var i; data = [ 2.0, 2.0, -4.0, -4.0, 1.5, -10.0, 5.0, 3.5, -1.0 ]; - acc = incrmkurtosis( 4 ); + acc = mkurtosis( 4 ); for ( i = 0; i < data.length; i++ ) { actual = acc( data[ i ] ); @@ -244,7 +244,7 @@ tape( 'the accumulator correctly slides the window (W=6)', function test( t ) { var i; data = [ 3.0, -1.0, 7.0, 2.5, -4.0, 6.0, 1.0, -2.0, 8.0, 5.0 ]; - acc = incrmkurtosis( 6 ); + acc = mkurtosis( 6 ); for ( i = 0; i < data.length; i++ ) { actual = acc( data[ i ] ); @@ -279,7 +279,7 @@ tape( 'the accumulator returns `NaN` when a NaN is in the window', function test // NaN at position 2 (0-indexed), window=4. data = [ 1.0, 2.0, NaN, -2.0, -3.0, 4.0, 5.0 ]; - acc = incrmkurtosis( 4 ); + acc = mkurtosis( 4 ); for ( i = 0; i < data.length; i++ ) { v = acc( data[ i ] ); if ( i >= 3 && i <= 5 ) { @@ -298,7 +298,7 @@ tape( 'the accumulator recovers after a NaN exits the window', function test( t // W=4: NaN at index 0 leaves after 4 slides. data = [ NaN, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]; - acc = incrmkurtosis( 4 ); + acc = mkurtosis( 4 ); // Consume NaN and 3 good values: for ( i = 0; i < 4; i++ ) { @@ -321,7 +321,7 @@ tape( 'the accumulator handles a window entirely filled with identical values (k var v; var i; - acc = incrmkurtosis( 4 ); + acc = mkurtosis( 4 ); for ( i = 0; i < 8; i++ ) { v = acc( 5.0 ); if ( i < 3 ) { @@ -338,7 +338,7 @@ tape( 'the accumulator works with window size W=4 and exactly 4 values', functio var acc; var v; - acc = incrmkurtosis( 4 ); + acc = mkurtosis( 4 ); acc( -10.0 ); acc( -10.0 ); From c71a1b099ab86103da350645c99e732f1cfaaabd Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Tue, 3 Mar 2026 12:06:39 -0800 Subject: [PATCH 4/5] feat: add stats/incr/mkurtosis --- 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: 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 --- --- .../@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js | 7 ++++--- lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js index fa8db9c338a7..f4b78131091b 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 The Stdlib Authors. +* 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. @@ -22,6 +22,7 @@ var bench = require( '@stdlib/bench' ); var randu = require( '@stdlib/random/base/randu' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var mkurtosis = require( './../lib' ); @@ -46,7 +47,7 @@ bench( pkg, function benchmark( b ) { b.end(); }); -bench( pkg+'::accumulator,window=20', function benchmark( b ) { +bench( format( '%s::accumulator,window=20', pkg ), function benchmark( b ) { var acc; var v; var i; @@ -68,7 +69,7 @@ bench( pkg+'::accumulator,window=20', function benchmark( b ) { b.end(); }); -bench( pkg+'::accumulator,window=100', function benchmark( b ) { +bench( format( '%s::accumulator,window=100', pkg ), function benchmark( b ) { var acc; var v; var i; diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js index f03dea4051e6..de7670a4a10e 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/lib/main.js @@ -217,7 +217,7 @@ function mkurtosis( W ) { } // If a NaN just left the window and none remain, recompute from scratch - // because NaN corrupted the running moment state: + // Because NaN corrupted the running moment state: if ( nans === 0 && isnan( xo ) ) { recompute(); } else if ( nans > 0 ) { From 6012aebb17fa37cac049b6f4ac4f35439cd780b0 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Tue, 3 Mar 2026 12:11:01 -0800 Subject: [PATCH 5/5] fix: copyright year --- 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js index f4b78131091b..e27e181f42a7 100644 --- a/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/mkurtosis/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2026 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.