Skip to content

Commit 32b70b7

Browse files
committed
chore: clean-up
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 7cda3e1 commit 32b70b7

File tree

5 files changed

+21
-81
lines changed

5 files changed

+21
-81
lines changed

lib/node_modules/@stdlib/stats/incr/nanmean/README.md

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var incrnanmean = require( '@stdlib/stats/incr/nanmean' );
5353

5454
#### incrnanmean()
5555

56-
Returns an accumulator `function` which incrementally computes an [arithmetic mean][arithmetic-mean], ignoring `NaN` values.
56+
Returns an accumulator function which incrementally computes an [arithmetic mean][arithmetic-mean], ignoring `NaN` values.
5757

5858
```javascript
5959
var accumulator = incrnanmean();
@@ -103,24 +103,17 @@ mu = accumulator();
103103
<!-- eslint no-undef: "error" -->
104104

105105
```javascript
106-
var randu = require( '@stdlib/random/base/randu' );
106+
var uniform = require( '@stdlib/random/base/uniform' );
107+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
107108
var incrnanmean = require( '@stdlib/stats/incr/nanmean' );
108109

109-
var accumulator;
110-
var v;
111-
var i;
112-
113110
// Initialize an accumulator:
114-
accumulator = incrnanmean();
111+
var accumulator = incrnanmean();
115112

116113
// For each simulated datum, update the mean...
114+
var i;
117115
for ( i = 0; i < 100; i++ ) {
118-
if ( randu() < 0.2 ) {
119-
v = NaN;
120-
} else {
121-
v = randu() * 100.0;
122-
}
123-
accumulator( v );
116+
accumulator( ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ) );
124117
}
125118
console.log( accumulator() );
126119
```
@@ -133,17 +126,6 @@ console.log( accumulator() );
133126

134127
<section class="related">
135128

136-
* * *
137-
138-
## See Also
139-
140-
- <span class="package-name">[`@stdlib/stats/incr/midrange`][@stdlib/stats/incr/midrange]</span><span class="delimiter">: </span><span class="description">compute a mid-range incrementally.</span>
141-
- <span class="package-name">[`@stdlib/stats/incr/mmean`][@stdlib/stats/incr/mmean]</span><span class="delimiter">: </span><span class="description">compute a moving arithmetic mean incrementally.</span>
142-
- <span class="package-name">[`@stdlib/stats/incr/stdev`][@stdlib/stats/incr/stdev]</span><span class="delimiter">: </span><span class="description">compute a corrected sample standard deviation incrementally.</span>
143-
- <span class="package-name">[`@stdlib/stats/incr/sum`][@stdlib/stats/incr/sum]</span><span class="delimiter">: </span><span class="description">compute a sum incrementally.</span>
144-
- <span class="package-name">[`@stdlib/stats/incr/summary`][@stdlib/stats/incr/summary]</span><span class="delimiter">: </span><span class="description">compute a statistical summary incrementally.</span>
145-
- <span class="package-name">[`@stdlib/stats/incr/variance`][@stdlib/stats/incr/variance]</span><span class="delimiter">: </span><span class="description">compute an unbiased sample variance incrementally.</span>
146-
147129
</section>
148130

149131
<!-- /.related -->
@@ -154,22 +136,6 @@ console.log( accumulator() );
154136

155137
[arithmetic-mean]: https://en.wikipedia.org/wiki/Arithmetic_mean
156138

157-
<!-- <related-links> -->
158-
159-
[@stdlib/stats/incr/midrange]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/midrange
160-
161-
[@stdlib/stats/incr/mmean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mmean
162-
163-
[@stdlib/stats/incr/stdev]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/stdev
164-
165-
[@stdlib/stats/incr/sum]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/sum
166-
167-
[@stdlib/stats/incr/summary]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/summary
168-
169-
[@stdlib/stats/incr/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/variance
170-
171-
<!-- </related-links> -->
172-
173139
</section>
174140

175141
<!-- /.links -->

lib/node_modules/@stdlib/stats/incr/nanmean/benchmark/benchmark.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
2524
var pkg = require( './../package.json' ).name;
2625
var incrnanmean = require( './../lib' );
2726

@@ -55,7 +54,7 @@ bench( pkg+'::accumulator', function benchmark( b ) {
5554

5655
b.tic();
5756
for ( i = 0; i < b.iterations; i++ ) {
58-
v = acc( randu() );
57+
v = acc( i );
5958
if ( v !== v ) {
6059
b.fail( 'should not return NaN' );
6160
}

lib/node_modules/@stdlib/stats/incr/nanmean/examples/index.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,20 @@
1818

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
21+
var uniform = require( '@stdlib/random/base/uniform' );
22+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
2223
var incrnanmean = require( './../lib' );
2324

24-
var accumulator;
25-
var mu;
26-
var v;
27-
var i;
28-
2925
// Initialize an accumulator:
30-
accumulator = incrnanmean();
26+
var accumulator = incrnanmean();
3127

3228
// For each simulated datum, update the mean...
3329
console.log( '\nValue\tMean\n' );
30+
var mu;
31+
var v;
32+
var i;
3433
for ( i = 0; i < 100; i++ ) {
35-
if ( randu() < 0.2 ) {
36-
v = NaN;
37-
} else {
38-
v = randu() * 100.0;
39-
}
34+
v = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 );
4035
mu = accumulator( v );
4136
console.log( '%d\t%d', v.toFixed( 4 ), ( mu === null ) ? NaN : mu.toFixed( 4 ) );
4237
}

lib/node_modules/@stdlib/stats/incr/nanmean/lib/main.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,6 @@ var incrmean = require( '@stdlib/stats/incr/mean' );
2626
/**
2727
* Returns an accumulator function which incrementally computes an arithmetic mean, ignoring `NaN` values.
2828
*
29-
* ## Method
30-
*
31-
* - This implementation uses [Welford's method][algorithms-variance] for efficient computation, which can be derived as follows
32-
*
33-
* ```tex
34-
* \begin{align*}
35-
* \mu_n &= \frac{1}{n} \sum_{i=0}^{n-1} x_i \\
36-
* &= \frac{1}{n} \biggl(x_{n-1} + \sum_{i=0}^{n-2} x_i \biggr) \\
37-
* &= \frac{1}{n} (x_{n-1} + (n-1)\mu_{n-1}) \\
38-
* &= \mu_{n-1} + \frac{1}{n} (x_{n-1} - \mu_{n-1})
39-
* \end{align*}
40-
* ```
41-
*
42-
* [algorithms-variance]: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
43-
*
4429
* @returns {Function} accumulator function
4530
*
4631
* @example
@@ -62,7 +47,6 @@ var incrmean = require( '@stdlib/stats/incr/mean' );
6247
* // returns -1.5
6348
*/
6449
function incrnanmean() {
65-
var count = 0;
6650
var mean = incrmean();
6751
return accumulator;
6852

@@ -73,15 +57,11 @@ function incrnanmean() {
7357
* @param {number} [x] - new value
7458
* @returns {(number|null)} mean value or null
7559
*/
76-
function accumulator(x) {
77-
if ( arguments.length === 0 ) {
78-
return ( count === 0 ) ? null : mean();
79-
}
80-
if ( !isnan( x ) ) {
81-
count += 1;
82-
return mean( x );
60+
function accumulator( x ) {
61+
if ( arguments.length === 0 || isnan( x ) ) {
62+
return mean();
8363
}
84-
return mean();
64+
return mean( x );
8565
}
8666
}
8767

lib/node_modules/@stdlib/stats/incr/nanmean/test/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ tape( 'main export is a function', function test( t ) {
3434
});
3535

3636
tape( 'the function returns an accumulator function', function test( t ) {
37-
t.equal( typeof incrnanmean(), 'function', 'returns a function' );
37+
t.equal( typeof incrnanmean(), 'function', 'returns expected value' );
3838
t.end();
3939
});
4040

@@ -74,7 +74,7 @@ tape( 'the accumulator function incrementally computes an arithmetic mean', func
7474
expected.push( ( count === 0 ) ? null : sum / count );
7575
actual.push( acc( d ) );
7676
}
77-
t.deepEqual( actual, expected, 'returns expected incremental results' );
77+
t.deepEqual( actual, expected, 'returns expected value' );
7878
t.end();
7979
});
8080

@@ -88,6 +88,6 @@ tape( 'if not provided an input value, the accumulator function returns the curr
8888
for ( i = 0; i < data.length; i++ ) {
8989
acc( data[ i ] );
9090
}
91-
t.equal( acc(), 2.0, 'returns the current accumulated mean' );
91+
t.equal( acc(), 2.0, 'returns expected value' );
9292
t.end();
9393
});

0 commit comments

Comments
 (0)