Skip to content

Commit ff84239

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 985a881 + 201cb87 commit ff84239

25 files changed

Lines changed: 1544 additions & 4 deletions

File tree

docs/links/database.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,6 +2579,19 @@
25792579
"error"
25802580
]
25812581
},
2582+
"https://en.wikipedia.org/wiki/Mean_squared_error": {
2583+
"id": "mean-squared-error",
2584+
"description": "Wikipedia entry for the mean squared error (MSE).",
2585+
"short_url": "",
2586+
"keywords": [
2587+
"mse",
2588+
"statistics",
2589+
"stats",
2590+
"error",
2591+
"model",
2592+
"prediction"
2593+
]
2594+
},
25822595
"https://en.wikipedia.org/wiki/Median": {
25832596
"id": "median",
25842597
"description": "Wikipedia entry for the median.",

lib/node_modules/@stdlib/namespace/lib/namespace/i.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,18 @@ ns.push({
663663
]
664664
});
665665

666+
ns.push({
667+
'alias': 'incrmmse',
668+
'path': '@stdlib/stats/incr/mmse',
669+
'value': require( '@stdlib/stats/incr/mmse' ),
670+
'type': 'Function',
671+
'related': [
672+
'@stdlib/stats/incr/mrmse',
673+
'@stdlib/stats/incr/mrss',
674+
'@stdlib/stats/incr/mse'
675+
]
676+
});
677+
666678
ns.push({
667679
'alias': 'incrmpcorr',
668680
'path': '@stdlib/stats/incr/mpcorr',
@@ -738,6 +750,18 @@ ns.push({
738750
]
739751
});
740752

753+
ns.push({
754+
'alias': 'incrmse',
755+
'path': '@stdlib/stats/incr/mse',
756+
'value': require( '@stdlib/stats/incr/mse' ),
757+
'type': 'Function',
758+
'related': [
759+
'@stdlib/stats/incr/mmse',
760+
'@stdlib/stats/incr/rmse',
761+
'@stdlib/stats/incr/rss'
762+
]
763+
});
764+
741765
ns.push({
742766
'alias': 'incrmstdev',
743767
'path': '@stdlib/stats/incr/mstdev',

lib/node_modules/@stdlib/repl/code-blocks/lib/db.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,12 +1017,14 @@ var db = {
10171017
"incrmminabs": "accumulator = incrmminabs( 3 );\nm = accumulator()\nm = accumulator( 2.0 )\nm = accumulator( -5.0 )\nm = accumulator( 3.0 )\nm = accumulator( 5.0 )\nm = accumulator()\n",
10181018
"incrmminmax": "accumulator = incrmminmax( 3 );\nmm = accumulator()\nmm = accumulator( 2.0 )\nmm = accumulator( -5.0 )\nmm = accumulator( 3.0 )\nmm = accumulator( 5.0 )\nmm = accumulator()\n",
10191019
"incrmmpe": "accumulator = incrmmpe( 3 );\nm = accumulator()\nm = accumulator( 2.0, 3.0 )\nm = accumulator( 5.0, 2.0 )\nm = accumulator( 3.0, 2.0 )\nm = accumulator( 2.0, 5.0 )\nm = accumulator()\n",
1020+
"incrmmse": "accumulator = incrmmse( 3 );\nm = accumulator()\nm = accumulator( 2.0, 3.0 )\nm = accumulator( -5.0, 2.0 )\nm = accumulator( 3.0, 2.0 )\nm = accumulator( 5.0, -2.0 )\nm = accumulator()\n",
10201021
"incrmpcorr": "accumulator = incrmpcorr( 3 );\nr = accumulator()\nr = accumulator( 2.0, 1.0 )\nr = accumulator( -5.0, 3.14 )\nr = accumulator( 3.0, -1.0 )\nr = accumulator( 5.0, -9.5 )\nr = accumulator()\n",
10211022
"incrmpcorrdist": "accumulator = incrmpcorrdist( 3 );\nd = accumulator()\nd = accumulator( 2.0, 1.0 )\nd = accumulator( -5.0, 3.14 )\nd = accumulator( 3.0, -1.0 )\nd = accumulator( 5.0, -9.5 )\nd = accumulator()\n",
10221023
"incrmpe": "accumulator = incrmpe();\nm = accumulator()\nm = accumulator( 2.0, 3.0 )\nm = accumulator( 5.0, 2.0 )\nm = accumulator()\n",
10231024
"incrmprod": "accumulator = incrmprod( 3 );\np = accumulator()\np = accumulator( 2.0 )\np = accumulator( -5.0 )\np = accumulator( 3.0 )\np = accumulator( 5.0 )\np = accumulator()\n",
10241025
"incrmrange": "accumulator = incrmrange( 3 );\nr = accumulator()\nr = accumulator( 2.0 )\nr = accumulator( -5.0 )\nr = accumulator( 3.0 )\nr = accumulator( 5.0 )\nr = accumulator()\n",
10251026
"incrmrss": "accumulator = incrmrss( 3 );\nr = accumulator()\nr = accumulator( 2.0, 3.0 )\nr = accumulator( -5.0, 2.0 )\nr = accumulator( 3.0, 2.0 )\nr = accumulator( 5.0, -2.0 )\nr = accumulator()\n",
1027+
"incrmse": "accumulator = incrmse();\nr = accumulator()\nr = accumulator( 2.0, 3.0 )\nr = accumulator( -5.0, 2.0 )\nr = accumulator()\n",
10261028
"incrmstdev": "accumulator = incrmstdev( 3 );\ns = accumulator()\ns = accumulator( 2.0 )\ns = accumulator( -5.0 )\ns = accumulator( 3.0 )\ns = accumulator( 5.0 )\ns = accumulator()\n",
10271029
"incrmsum": "accumulator = incrmsum( 3 );\ns = accumulator()\ns = accumulator( 2.0 )\ns = accumulator( -5.0 )\ns = accumulator( 3.0 )\ns = accumulator( 5.0 )\ns = accumulator()\n",
10281030
"incrmsumabs": "accumulator = incrmsumabs( 3 );\ns = accumulator()\ns = accumulator( 2.0 )\ns = accumulator( -5.0 )\ns = accumulator( 3.0 )\ns = accumulator( -5.0 )\ns = accumulator()\n",

lib/node_modules/@stdlib/repl/help/lib/db.js

Lines changed: 4 additions & 2 deletions
Large diffs are not rendered by default.

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,15 @@ setReadOnly( ns, 'incrmminmax', require( '@stdlib/stats/incr/mminmax' ) );
378378
*/
379379
setReadOnly( ns, 'incrmmpe', require( '@stdlib/stats/incr/mmpe' ) );
380380

381+
/**
382+
* @name incrmmse
383+
* @memberof ns
384+
* @readonly
385+
* @type {Function}
386+
* @see {@link module:@stdlib/stats/incr/mmse}
387+
*/
388+
setReadOnly( ns, 'incrmmse', require( '@stdlib/stats/incr/mmse' ) );
389+
381390
/**
382391
* @name incrmpcorr
383392
* @memberof ns
@@ -432,6 +441,15 @@ setReadOnly( ns, 'incrmrange', require( '@stdlib/stats/incr/mrange' ) );
432441
*/
433442
setReadOnly( ns, 'incrmrss', require( '@stdlib/stats/incr/mrss' ) );
434443

444+
/**
445+
* @name incrmse
446+
* @memberof ns
447+
* @readonly
448+
* @type {Function}
449+
* @see {@link module:@stdlib/stats/incr/mse}
450+
*/
451+
setReadOnly( ns, 'incrmse', require( '@stdlib/stats/incr/mse' ) );
452+
435453
/**
436454
* @name incrmstdev
437455
* @memberof ns
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2018 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+
# incrmmse
22+
23+
> Compute a moving [mean squared error][mean-squared-error] (MSE) incrementally.
24+
25+
<section class="intro">
26+
27+
For a window of size `W`, the [mean squared error][mean-squared-error] is defined as
28+
29+
<!-- <equation class="equation" label="eq:mean_squared_error" align="center" raw="\operatorname{MSE} = \frac{1}{W} \sum_{i=0}^{W-1} (y_i - x_i)^2" alt="Equation for the mean squared error."> -->
30+
31+
<div class="equation" align="center" data-raw-text="\operatorname{MSE} = \frac{1}{W} \sum_{i=0}^{W-1} (y_i - x_i)^2" data-equation="eq:mean_squared_error">
32+
<img src="https://cdn.rawgit.com/stdlib-js/stdlib/9cb3c4a2fcf92ca07ed60c34de1ceda40f75919c/lib/node_modules/@stdlib/stats/incr/mmse/docs/img/equation_mean_squared_error.svg" alt="Equation for the mean squared error.">
33+
<br>
34+
</div>
35+
36+
<!-- </equation> -->
37+
38+
</section>
39+
40+
<!-- /.intro -->
41+
42+
<section class="usage">
43+
44+
## Usage
45+
46+
```javascript
47+
var incrmmse = require( '@stdlib/stats/incr/mmse' );
48+
```
49+
50+
#### incrmmse( window )
51+
52+
Returns an accumulator `function` which incrementally computes a moving [mean squared error][mean-squared-error]. The `window` parameter defines the number of values over which to compute the moving [mean squared error][mean-squared-error].
53+
54+
```javascript
55+
var accumulator = incrmmse( 3 );
56+
```
57+
58+
#### accumulator( \[x, y] )
59+
60+
If provided input values `x` and `y`, the accumulator function returns an updated [mean squared error][mean-squared-error]. If not provided input values `x` and `y`, the accumulator function returns the current [mean squared error][mean-squared-error].
61+
62+
```javascript
63+
var accumulator = incrmmse( 3 );
64+
65+
var m = accumulator();
66+
// returns null
67+
68+
// Fill the window...
69+
m = accumulator( 2.0, 3.0 ); // [(2.0,3.0)]
70+
// returns 1.0
71+
72+
m = accumulator( -1.0, 4.0 ); // [(2.0,3.0), (-1.0,4.0)]
73+
// returns 13.0
74+
75+
m = accumulator( 3.0, 9.0 ); // [(2.0,3.0), (-1.0,4.0), (3.0,9.0)]
76+
// returns ~20.67
77+
78+
// Window begins sliding...
79+
m = accumulator( -7.0, 3.0 ); // [(-1.0,4.0), (3.0,9.0), (-7.0,3.0)]
80+
// returns ~53.67
81+
82+
m = accumulator( -5.0, -3.0 ); // [(3.0,9.0), (-7.0,3.0), (-5.0,-3.0)]
83+
// returns ~46.67
84+
85+
m = accumulator();
86+
// returns ~46.67
87+
```
88+
89+
</section>
90+
91+
<!-- /.usage -->
92+
93+
<section class="notes">
94+
95+
## Notes
96+
97+
- 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 least** `W-1` future invocations. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function.
98+
- As `W` (x,y) pairs 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 calculated from all provided values.
99+
100+
</section>
101+
102+
<!-- /.notes -->
103+
104+
<section class="examples">
105+
106+
## Examples
107+
108+
<!-- eslint no-undef: "error" -->
109+
110+
```javascript
111+
var randu = require( '@stdlib/random/base/randu' );
112+
var incrmmse = require( '@stdlib/stats/incr/mmse' );
113+
114+
var accumulator;
115+
var v1;
116+
var v2;
117+
var i;
118+
119+
// Initialize an accumulator:
120+
accumulator = incrmmse( 5 );
121+
122+
// For each simulated datum, update the moving mean squared error...
123+
for ( i = 0; i < 100; i++ ) {
124+
v1 = ( randu()*100.0 ) - 50.0;
125+
v2 = ( randu()*100.0 ) - 50.0;
126+
accumulator( v1, v2 );
127+
}
128+
console.log( accumulator() );
129+
```
130+
131+
</section>
132+
133+
<!-- /.examples -->
134+
135+
<section class="links">
136+
137+
[mean-squared-error]: https://en.wikipedia.org/wiki/Mean_squared_error
138+
139+
</section>
140+
141+
<!-- /.links -->
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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 bench = require( '@stdlib/bench' );
24+
var randu = require( '@stdlib/random/base/randu' );
25+
var pkg = require( './../package.json' ).name;
26+
var incrmmse = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var f;
33+
var i;
34+
b.tic();
35+
for ( i = 0; i < b.iterations; i++ ) {
36+
f = incrmmse( (i%5)+1 );
37+
if ( typeof f !== 'function' ) {
38+
b.fail( 'should return a function' );
39+
}
40+
}
41+
b.toc();
42+
if ( typeof f !== 'function' ) {
43+
b.fail( 'should return a function' );
44+
}
45+
b.pass( 'benchmark finished' );
46+
b.end();
47+
});
48+
49+
bench( pkg+'::accumulator', function benchmark( b ) {
50+
var acc;
51+
var v;
52+
var i;
53+
54+
acc = incrmmse( 5 );
55+
56+
b.tic();
57+
for ( i = 0; i < b.iterations; i++ ) {
58+
v = acc( randu()-0.5, randu()-0.5 );
59+
if ( v !== v ) {
60+
b.fail( 'should not return NaN' );
61+
}
62+
}
63+
b.toc();
64+
if ( v !== v ) {
65+
b.fail( 'should not return NaN' );
66+
}
67+
b.pass( 'benchmark finished' );
68+
b.end();
69+
});

0 commit comments

Comments
 (0)