Skip to content

Commit 6979a16

Browse files
committed
Refactor to use update formula using the residual and rename variable
1 parent 4c79105 commit 6979a16

File tree

1 file changed

+6
-6
lines changed
  • lib/node_modules/@stdlib/stats/incr/ewmean/lib

1 file changed

+6
-6
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var isNonNegativeNumber = require( '@stdlib/assert/is-nonnegative-number' ).isPr
4949
* // returns -1.5
5050
*/
5151
function increwmean( alpha ) {
52-
var v;
52+
var m;
5353
if ( !isNonNegativeNumber( alpha ) ) {
5454
throw new TypeError( 'invalid input argument. Must provide a nonnegative number. Value: `' + alpha + '`.' );
5555
}
@@ -67,14 +67,14 @@ function increwmean( alpha ) {
6767
*/
6868
function accumulator( x ) {
6969
if ( arguments.length === 0 ) {
70-
return ( v === void 0 ) ? null : v;
70+
return ( m === void 0 ) ? null : m;
7171
}
72-
if ( v === void 0 ) {
73-
v = x;
72+
if ( m === void 0 ) {
73+
m = x;
7474
} else {
75-
v = (alpha*x) + ((1.0-alpha)*v);
75+
m += alpha * ( x-m );
7676
}
77-
return v;
77+
return m;
7878
}
7979
}
8080

0 commit comments

Comments
 (0)