@stdlib/stats-incr-nangmean 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +177 -0
- package/NOTICE +1 -0
- package/README.md +235 -0
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +7 -0
- package/docs/img/equation_geometric_mean.svg +68 -0
- package/docs/types/index.d.ts +59 -0
- package/lib/index.js +54 -0
- package/lib/main.js +74 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
package/NOTICE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025 The Stdlib Authors.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
-->
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
<details>
|
|
23
|
+
<summary>
|
|
24
|
+
About stdlib...
|
|
25
|
+
</summary>
|
|
26
|
+
<p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
|
|
27
|
+
<p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
|
|
28
|
+
<p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
|
|
29
|
+
<p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
|
|
30
|
+
</details>
|
|
31
|
+
|
|
32
|
+
# incrnangmean
|
|
33
|
+
|
|
34
|
+
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
35
|
+
|
|
36
|
+
> Compute a [geometric mean][geometric-mean] incrementally, ignoring `NaN` values.
|
|
37
|
+
|
|
38
|
+
<section class="intro">
|
|
39
|
+
|
|
40
|
+
The [geometric mean][geometric-mean] is defined as the nth root of a product of _n_ numbers.
|
|
41
|
+
|
|
42
|
+
<!-- <equation class="equation" label="eq:geometric_mean" align="center" raw="\biggl( \prod_{i=0}^{n-1} x_i \biggr)^{\frac{1}{n}} = \sqrt[n]{x_0 x_1 \cdots x_{n-1}}" alt="Equation for the geometric mean."> -->
|
|
43
|
+
|
|
44
|
+
<!-- </equation> -->
|
|
45
|
+
|
|
46
|
+
</section>
|
|
47
|
+
|
|
48
|
+
<!-- /.intro -->
|
|
49
|
+
|
|
50
|
+
<section class="installation">
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm install @stdlib/stats-incr-nangmean
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
</section>
|
|
59
|
+
|
|
60
|
+
<section class="usage">
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
var incrnangmean = require( '@stdlib/stats-incr-nangmean' );
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### incrnangmean()
|
|
69
|
+
|
|
70
|
+
Returns an accumulator `function` which incrementally computes a [geometric mean][geometric-mean], ignoring `NaN` values.
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
var accumulator = incrnangmean();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### accumulator( \[x] )
|
|
77
|
+
|
|
78
|
+
If provided an input value `x`, the accumulator function returns an updated [geometric mean][geometric-mean]. If not provided an input value `x`, the accumulator function returns the current [geometric mean][geometric-mean].
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
var accumulator = incrnangmean();
|
|
82
|
+
|
|
83
|
+
var prod = accumulator( 2.0 );
|
|
84
|
+
// returns 2.0
|
|
85
|
+
|
|
86
|
+
prod = accumulator( 1.0 );
|
|
87
|
+
// returns ~1.414
|
|
88
|
+
|
|
89
|
+
prod = accumulator( NaN );
|
|
90
|
+
// returns ~1.414
|
|
91
|
+
|
|
92
|
+
prod = accumulator( 3.0 );
|
|
93
|
+
// returns ~1.817
|
|
94
|
+
|
|
95
|
+
prod = accumulator();
|
|
96
|
+
// returns ~1.817
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
</section>
|
|
100
|
+
|
|
101
|
+
<!-- /.usage -->
|
|
102
|
+
|
|
103
|
+
<section class="notes">
|
|
104
|
+
|
|
105
|
+
## Notes
|
|
106
|
+
|
|
107
|
+
- Input values are **not** type checked. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function.
|
|
108
|
+
|
|
109
|
+
</section>
|
|
110
|
+
|
|
111
|
+
<!-- /.notes -->
|
|
112
|
+
|
|
113
|
+
<section class="examples">
|
|
114
|
+
|
|
115
|
+
## Examples
|
|
116
|
+
|
|
117
|
+
<!-- eslint no-undef: "error" -->
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
var bernoulli = require( '@stdlib/random-base-bernoulli' );
|
|
121
|
+
var uniform = require( '@stdlib/random-base-uniform' );
|
|
122
|
+
var incrnangmean = require( '@stdlib/stats-incr-nangmean' );
|
|
123
|
+
|
|
124
|
+
var accumulator;
|
|
125
|
+
var v;
|
|
126
|
+
var i;
|
|
127
|
+
|
|
128
|
+
// Initialize an accumulator:
|
|
129
|
+
accumulator = incrnangmean();
|
|
130
|
+
|
|
131
|
+
// For each simulated value, update the geometric mean...
|
|
132
|
+
for ( i = 0; i < 100; i++ ) {
|
|
133
|
+
if ( bernoulli( 0.2 ) ) {
|
|
134
|
+
v = NaN;
|
|
135
|
+
} else {
|
|
136
|
+
v = uniform( 0.0, 100.0 );
|
|
137
|
+
}
|
|
138
|
+
accumulator( v );
|
|
139
|
+
}
|
|
140
|
+
console.log( accumulator() );
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
</section>
|
|
144
|
+
|
|
145
|
+
<!-- /.examples -->
|
|
146
|
+
|
|
147
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
148
|
+
|
|
149
|
+
<section class="related">
|
|
150
|
+
|
|
151
|
+
</section>
|
|
152
|
+
|
|
153
|
+
<!-- /.related -->
|
|
154
|
+
|
|
155
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
<section class="main-repo" >
|
|
159
|
+
|
|
160
|
+
* * *
|
|
161
|
+
|
|
162
|
+
## Notice
|
|
163
|
+
|
|
164
|
+
This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
|
|
165
|
+
|
|
166
|
+
For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
|
|
167
|
+
|
|
168
|
+
#### Community
|
|
169
|
+
|
|
170
|
+
[![Chat][chat-image]][chat-url]
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## License
|
|
175
|
+
|
|
176
|
+
See [LICENSE][stdlib-license].
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
## Copyright
|
|
180
|
+
|
|
181
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
182
|
+
|
|
183
|
+
</section>
|
|
184
|
+
|
|
185
|
+
<!-- /.stdlib -->
|
|
186
|
+
|
|
187
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
188
|
+
|
|
189
|
+
<section class="links">
|
|
190
|
+
|
|
191
|
+
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-incr-nangmean.svg
|
|
192
|
+
[npm-url]: https://npmjs.org/package/@stdlib/stats-incr-nangmean
|
|
193
|
+
|
|
194
|
+
[test-image]: https://github.com/stdlib-js/stats-incr-nangmean/actions/workflows/test.yml/badge.svg?branch=v0.1.0
|
|
195
|
+
[test-url]: https://github.com/stdlib-js/stats-incr-nangmean/actions/workflows/test.yml?query=branch:v0.1.0
|
|
196
|
+
|
|
197
|
+
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-incr-nangmean/main.svg
|
|
198
|
+
[coverage-url]: https://codecov.io/github/stdlib-js/stats-incr-nangmean?branch=main
|
|
199
|
+
|
|
200
|
+
<!--
|
|
201
|
+
|
|
202
|
+
[dependencies-image]: https://img.shields.io/david/stdlib-js/stats-incr-nangmean.svg
|
|
203
|
+
[dependencies-url]: https://david-dm.org/stdlib-js/stats-incr-nangmean/main
|
|
204
|
+
|
|
205
|
+
-->
|
|
206
|
+
|
|
207
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
208
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
209
|
+
|
|
210
|
+
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
211
|
+
|
|
212
|
+
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
213
|
+
|
|
214
|
+
[umd]: https://github.com/umdjs/umd
|
|
215
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
216
|
+
|
|
217
|
+
[deno-url]: https://github.com/stdlib-js/stats-incr-nangmean/tree/deno
|
|
218
|
+
[deno-readme]: https://github.com/stdlib-js/stats-incr-nangmean/blob/deno/README.md
|
|
219
|
+
[umd-url]: https://github.com/stdlib-js/stats-incr-nangmean/tree/umd
|
|
220
|
+
[umd-readme]: https://github.com/stdlib-js/stats-incr-nangmean/blob/umd/README.md
|
|
221
|
+
[esm-url]: https://github.com/stdlib-js/stats-incr-nangmean/tree/esm
|
|
222
|
+
[esm-readme]: https://github.com/stdlib-js/stats-incr-nangmean/blob/esm/README.md
|
|
223
|
+
[branches-url]: https://github.com/stdlib-js/stats-incr-nangmean/blob/main/branches.md
|
|
224
|
+
|
|
225
|
+
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/stats-incr-nangmean/main/LICENSE
|
|
226
|
+
|
|
227
|
+
[geometric-mean]: https://en.wikipedia.org/wiki/Geometric_mean
|
|
228
|
+
|
|
229
|
+
<!-- <related-links> -->
|
|
230
|
+
|
|
231
|
+
<!-- </related-links> -->
|
|
232
|
+
|
|
233
|
+
</section>
|
|
234
|
+
|
|
235
|
+
<!-- /.links -->
|
package/SECURITY.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var u=function(n,r){return function(){return r||n((r={exports:{}}).exports,r),r.exports}};var a=u(function(o,t){
|
|
2
|
+
var i=require('@stdlib/stats-incr-gmean/dist'),c=require('@stdlib/math-base-assert-is-nan/dist');function s(){var n=i();return r;function r(e){return arguments.length===0||c(e)?n():n(e)}}t.exports=s
|
|
3
|
+
});var m=a();module.exports=m;
|
|
4
|
+
/** @license Apache-2.0 */
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar incrgmean = require( '@stdlib/stats-incr-gmean' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Returns an accumulator function which incrementally computes a geometric mean, ignoring `NaN` values.\n*\n* @returns {Function} accumulator function\n*\n* @example\n* var accumulator = incrnangmean();\n*\n* var v = accumulator();\n* // returns null\n*\n* v = accumulator( 2.0 );\n* // returns 2.0\n*\n* v = accumulator( NaN );\n* // returns 2.0\n*\n* v = accumulator( 5.0 );\n* // returns ~3.16\n*\n* v = accumulator();\n* // returns ~3.16\n*/\nfunction incrnangmean() {\n\tvar gmean = incrgmean();\n\treturn accumulator;\n\n\t/**\n\t* If provided a value, the accumulator function returns an updated geometric mean. If not provided a value, the accumulator function returns the current geometric mean.\n\t*\n\t* @private\n\t* @param {number} [x] - new value\n\t* @returns {(number|null)} geometric mean or null\n\t*/\n\tfunction accumulator( x ) {\n\t\tif ( arguments.length === 0 || isnan( x ) ) {\n\t\t\treturn gmean();\n\t\t}\n\t\treturn gmean( x );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = incrnangmean;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute a geometric mean incrementally, ignoring `NaN` values.\n*\n* @module @stdlib/stats-incr-nangmean\n*\n* @example\n* var incrnangmean = require( '@stdlib/stats-incr-nangmean' );\n*\n* var accumulator = incrnangmean();\n*\n* var v = accumulator();\n* // returns null\n*\n* v = accumulator( 2.0 );\n* // returns 2.0\n*\n* v = accumulator( NaN );\n* // returns 2.0\n*\n* v = accumulator( 5.0 );\n* // returns ~3.16\n*\n* v = accumulator();\n* // returns ~3.16\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,0BAA2B,EAChDC,EAAQ,QAAS,iCAAkC,EA4BvD,SAASC,GAAe,CACvB,IAAIC,EAAQH,EAAU,EACtB,OAAOI,EASP,SAASA,EAAaC,EAAI,CACzB,OAAK,UAAU,SAAW,GAAKJ,EAAOI,CAAE,EAChCF,EAAM,EAEPA,EAAOE,CAAE,CACjB,CACD,CAKAN,EAAO,QAAUG,ICzBjB,IAAII,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_main", "__commonJSMin", "exports", "module", "incrgmean", "isnan", "incrnangmean", "gmean", "accumulator", "x", "main"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="26.325ex" height="7.676ex" style="vertical-align: -3.005ex;" viewBox="0 -2011.3 11334.4 3304.9" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" aria-labelledby="MathJax-SVG-1-Title">
|
|
2
|
+
<title id="MathJax-SVG-1-Title">left-parenthesis product Underscript i equals 0 Overscript n minus 1 Endscripts right-parenthesis Superscript StartFraction 1 Over n EndFraction Baseline equals RootIndex n StartRoot x 0 x 1 midline-horizontal-ellipsis x Subscript n minus 1 Baseline EndRoot</title>
|
|
3
|
+
<defs aria-hidden="true">
|
|
4
|
+
<path stroke-width="1" id="E1-MJMAIN-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path>
|
|
5
|
+
<path stroke-width="1" id="E1-MJSZ3-28" d="M701 -940Q701 -943 695 -949H664Q662 -947 636 -922T591 -879T537 -818T475 -737T412 -636T350 -511T295 -362T250 -186T221 17T209 251Q209 962 573 1361Q596 1386 616 1405T649 1437T664 1450H695Q701 1444 701 1441Q701 1436 681 1415T629 1356T557 1261T476 1118T400 927T340 675T308 359Q306 321 306 250Q306 -139 400 -430T690 -924Q701 -936 701 -940Z"></path>
|
|
6
|
+
<path stroke-width="1" id="E1-MJSZ2-220F" d="M220 812Q220 813 218 819T214 829T208 840T199 853T185 866T166 878T140 887T107 893T66 896H56V950H1221V896H1211Q1080 896 1058 812V-311Q1076 -396 1211 -396H1221V-450H725V-396H735Q864 -396 888 -314Q889 -312 889 -311V896H388V292L389 -311Q405 -396 542 -396H552V-450H56V-396H66Q195 -396 219 -314Q220 -312 220 -311V812Z"></path>
|
|
7
|
+
<path stroke-width="1" id="E1-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path>
|
|
8
|
+
<path stroke-width="1" id="E1-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path>
|
|
9
|
+
<path stroke-width="1" id="E1-MJMAIN-30" d="M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z"></path>
|
|
10
|
+
<path stroke-width="1" id="E1-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path>
|
|
11
|
+
<path stroke-width="1" id="E1-MJMAIN-2212" d="M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"></path>
|
|
12
|
+
<path stroke-width="1" id="E1-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path>
|
|
13
|
+
<path stroke-width="1" id="E1-MJMAIN-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path>
|
|
14
|
+
<path stroke-width="1" id="E1-MJSZ3-29" d="M34 1438Q34 1446 37 1448T50 1450H56H71Q73 1448 99 1423T144 1380T198 1319T260 1238T323 1137T385 1013T440 864T485 688T514 485T526 251Q526 134 519 53Q472 -519 162 -860Q139 -885 119 -904T86 -936T71 -949H56Q43 -949 39 -947T34 -937Q88 -883 140 -813Q428 -430 428 251Q428 453 402 628T338 922T245 1146T145 1309T46 1425Q44 1427 42 1429T39 1433T36 1436L34 1438Z"></path>
|
|
15
|
+
<path stroke-width="1" id="E1-MJMATHI-78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path>
|
|
16
|
+
<path stroke-width="1" id="E1-MJMAIN-22EF" d="M78 250Q78 274 95 292T138 310Q162 310 180 294T199 251Q199 226 182 208T139 190T96 207T78 250ZM525 250Q525 274 542 292T585 310Q609 310 627 294T646 251Q646 226 629 208T586 190T543 207T525 250ZM972 250Q972 274 989 292T1032 310Q1056 310 1074 294T1093 251Q1093 226 1076 208T1033 190T990 207T972 250Z"></path>
|
|
17
|
+
<path stroke-width="1" id="E1-MJMAIN-221A" d="M95 178Q89 178 81 186T72 200T103 230T169 280T207 309Q209 311 212 311H213Q219 311 227 294T281 177Q300 134 312 108L397 -77Q398 -77 501 136T707 565T814 786Q820 800 834 800Q841 800 846 794T853 782V776L620 293L385 -193Q381 -200 366 -200Q357 -200 354 -197Q352 -195 256 15L160 225L144 214Q129 202 113 190T95 178Z"></path>
|
|
18
|
+
</defs>
|
|
19
|
+
<g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)" aria-hidden="true">
|
|
20
|
+
<use xlink:href="#E1-MJSZ3-28" x="0" y="-1"></use>
|
|
21
|
+
<g transform="translate(736,0)">
|
|
22
|
+
<use xlink:href="#E1-MJSZ2-220F" x="25" y="0"></use>
|
|
23
|
+
<g transform="translate(90,-1090)">
|
|
24
|
+
<use transform="scale(0.707)" xlink:href="#E1-MJMATHI-69" x="0" y="0"></use>
|
|
25
|
+
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-3D" x="345" y="0"></use>
|
|
26
|
+
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-30" x="1124" y="0"></use>
|
|
27
|
+
</g>
|
|
28
|
+
<g transform="translate(0,1151)">
|
|
29
|
+
<use transform="scale(0.707)" xlink:href="#E1-MJMATHI-6E" x="0" y="0"></use>
|
|
30
|
+
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-2212" x="600" y="0"></use>
|
|
31
|
+
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-31" x="1379" y="0"></use>
|
|
32
|
+
</g>
|
|
33
|
+
</g>
|
|
34
|
+
<g transform="translate(2065,0)">
|
|
35
|
+
<use xlink:href="#E1-MJSZ3-29" x="0" y="-1"></use>
|
|
36
|
+
<g transform="translate(736,1177)">
|
|
37
|
+
<g transform="translate(120,0)">
|
|
38
|
+
<rect stroke="none" width="464" height="60" x="0" y="146"></rect>
|
|
39
|
+
<use transform="scale(0.574)" xlink:href="#E1-MJMAIN-31" x="154" y="647"></use>
|
|
40
|
+
<use transform="scale(0.574)" xlink:href="#E1-MJMATHI-6E" x="104" y="-475"></use>
|
|
41
|
+
</g>
|
|
42
|
+
</g>
|
|
43
|
+
</g>
|
|
44
|
+
<use xlink:href="#E1-MJMAIN-3D" x="3884" y="0"></use>
|
|
45
|
+
<g transform="translate(4940,0)">
|
|
46
|
+
<use transform="scale(0.574)" xlink:href="#E1-MJMATHI-6E" x="363" y="414"></use>
|
|
47
|
+
<use xlink:href="#E1-MJMAIN-221A" x="0" y="-207"></use>
|
|
48
|
+
<rect stroke="none" width="5560" height="60" x="833" y="534"></rect>
|
|
49
|
+
<g transform="translate(833,0)">
|
|
50
|
+
<use xlink:href="#E1-MJMATHI-78" x="0" y="0"></use>
|
|
51
|
+
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-30" x="809" y="-213"></use>
|
|
52
|
+
<g transform="translate(1026,0)">
|
|
53
|
+
<use xlink:href="#E1-MJMATHI-78" x="0" y="0"></use>
|
|
54
|
+
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-31" x="809" y="-213"></use>
|
|
55
|
+
</g>
|
|
56
|
+
<use xlink:href="#E1-MJMAIN-22EF" x="2219" y="0"></use>
|
|
57
|
+
<g transform="translate(3558,0)">
|
|
58
|
+
<use xlink:href="#E1-MJMATHI-78" x="0" y="0"></use>
|
|
59
|
+
<g transform="translate(572,-150)">
|
|
60
|
+
<use transform="scale(0.707)" xlink:href="#E1-MJMATHI-6E" x="0" y="0"></use>
|
|
61
|
+
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-2212" x="600" y="0"></use>
|
|
62
|
+
<use transform="scale(0.707)" xlink:href="#E1-MJMAIN-31" x="1379" y="0"></use>
|
|
63
|
+
</g>
|
|
64
|
+
</g>
|
|
65
|
+
</g>
|
|
66
|
+
</g>
|
|
67
|
+
</g>
|
|
68
|
+
</svg>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
|
+
|
|
21
|
+
/// <reference types="@stdlib/types"/>
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* If provided a value, returns an updated geometric mean; otherwise, returns the current geometric mean.
|
|
25
|
+
*
|
|
26
|
+
* @param x - value
|
|
27
|
+
* @returns geometric mean
|
|
28
|
+
*/
|
|
29
|
+
type accumulator = ( x?: number ) => number | null;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns an accumulator function which incrementally computes a geometric mean, ignoring `NaN` values.
|
|
33
|
+
*
|
|
34
|
+
* @returns accumulator function
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var accumulator = incrnangmean();
|
|
38
|
+
*
|
|
39
|
+
* var v = accumulator();
|
|
40
|
+
* // returns null
|
|
41
|
+
*
|
|
42
|
+
* v = accumulator( 2.0 );
|
|
43
|
+
* // returns 2.0
|
|
44
|
+
*
|
|
45
|
+
* v = accumulator( NaN );
|
|
46
|
+
* // returns 2.0
|
|
47
|
+
*
|
|
48
|
+
* v = accumulator( 5.0 );
|
|
49
|
+
* // returns ~3.16
|
|
50
|
+
*
|
|
51
|
+
* v = accumulator();
|
|
52
|
+
* // returns ~3.16
|
|
53
|
+
*/
|
|
54
|
+
declare function incrnangmean(): accumulator;
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
// EXPORTS //
|
|
58
|
+
|
|
59
|
+
export = incrnangmean;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Compute a geometric mean incrementally, ignoring `NaN` values.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/stats-incr-nangmean
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var incrnangmean = require( '@stdlib/stats-incr-nangmean' );
|
|
28
|
+
*
|
|
29
|
+
* var accumulator = incrnangmean();
|
|
30
|
+
*
|
|
31
|
+
* var v = accumulator();
|
|
32
|
+
* // returns null
|
|
33
|
+
*
|
|
34
|
+
* v = accumulator( 2.0 );
|
|
35
|
+
* // returns 2.0
|
|
36
|
+
*
|
|
37
|
+
* v = accumulator( NaN );
|
|
38
|
+
* // returns 2.0
|
|
39
|
+
*
|
|
40
|
+
* v = accumulator( 5.0 );
|
|
41
|
+
* // returns ~3.16
|
|
42
|
+
*
|
|
43
|
+
* v = accumulator();
|
|
44
|
+
* // returns ~3.16
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
// MODULES //
|
|
48
|
+
|
|
49
|
+
var main = require( './main.js' );
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// EXPORTS //
|
|
53
|
+
|
|
54
|
+
module.exports = main;
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var incrgmean = require( '@stdlib/stats-incr-gmean' );
|
|
24
|
+
var isnan = require( '@stdlib/math-base-assert-is-nan' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns an accumulator function which incrementally computes a geometric mean, ignoring `NaN` values.
|
|
31
|
+
*
|
|
32
|
+
* @returns {Function} accumulator function
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* var accumulator = incrnangmean();
|
|
36
|
+
*
|
|
37
|
+
* var v = accumulator();
|
|
38
|
+
* // returns null
|
|
39
|
+
*
|
|
40
|
+
* v = accumulator( 2.0 );
|
|
41
|
+
* // returns 2.0
|
|
42
|
+
*
|
|
43
|
+
* v = accumulator( NaN );
|
|
44
|
+
* // returns 2.0
|
|
45
|
+
*
|
|
46
|
+
* v = accumulator( 5.0 );
|
|
47
|
+
* // returns ~3.16
|
|
48
|
+
*
|
|
49
|
+
* v = accumulator();
|
|
50
|
+
* // returns ~3.16
|
|
51
|
+
*/
|
|
52
|
+
function incrnangmean() {
|
|
53
|
+
var gmean = incrgmean();
|
|
54
|
+
return accumulator;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* If provided a value, the accumulator function returns an updated geometric mean. If not provided a value, the accumulator function returns the current geometric mean.
|
|
58
|
+
*
|
|
59
|
+
* @private
|
|
60
|
+
* @param {number} [x] - new value
|
|
61
|
+
* @returns {(number|null)} geometric mean or null
|
|
62
|
+
*/
|
|
63
|
+
function accumulator( x ) {
|
|
64
|
+
if ( arguments.length === 0 || isnan( x ) ) {
|
|
65
|
+
return gmean();
|
|
66
|
+
}
|
|
67
|
+
return gmean( x );
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
// EXPORTS //
|
|
73
|
+
|
|
74
|
+
module.exports = incrnangmean;
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/stats-incr-nangmean",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Compute a geometric mean incrementally, ignoring NaN values.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"doc": "./docs",
|
|
19
|
+
"lib": "./lib",
|
|
20
|
+
"dist": "./dist"
|
|
21
|
+
},
|
|
22
|
+
"types": "./docs/types",
|
|
23
|
+
"scripts": {},
|
|
24
|
+
"homepage": "https://stdlib.io",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git://github.com/stdlib-js/stats-incr-nangmean.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
34
|
+
"@stdlib/stats-incr-gmean": "^0.2.2"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=0.10.0",
|
|
39
|
+
"npm": ">2.7.0"
|
|
40
|
+
},
|
|
41
|
+
"os": [
|
|
42
|
+
"aix",
|
|
43
|
+
"darwin",
|
|
44
|
+
"freebsd",
|
|
45
|
+
"linux",
|
|
46
|
+
"macos",
|
|
47
|
+
"openbsd",
|
|
48
|
+
"sunos",
|
|
49
|
+
"win32",
|
|
50
|
+
"windows"
|
|
51
|
+
],
|
|
52
|
+
"keywords": [
|
|
53
|
+
"stdlib",
|
|
54
|
+
"stdmath",
|
|
55
|
+
"statistics",
|
|
56
|
+
"stats",
|
|
57
|
+
"mathematics",
|
|
58
|
+
"math",
|
|
59
|
+
"geometric",
|
|
60
|
+
"mean",
|
|
61
|
+
"average",
|
|
62
|
+
"avg",
|
|
63
|
+
"central tendency",
|
|
64
|
+
"product",
|
|
65
|
+
"prod",
|
|
66
|
+
"incremental",
|
|
67
|
+
"accumulator",
|
|
68
|
+
"nan",
|
|
69
|
+
"ignore"
|
|
70
|
+
],
|
|
71
|
+
"funding": {
|
|
72
|
+
"type": "opencollective",
|
|
73
|
+
"url": "https://opencollective.com/stdlib"
|
|
74
|
+
}
|
|
75
|
+
}
|