|
| 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 | +# incrnanmda |
| 22 | + |
| 23 | +> Compute the [mean directional accuracy][mean-directional-accuracy] (MDA) incrementally, ignoring `NaN` value. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +The [mean directional accuracy][mean-directional-accuracy] is defined as |
| 28 | + |
| 29 | +<!-- <equation class="equation" label="eq:mean_directional_accuracy" align="center" raw="\operatorname{MDA} = \begin{cases} 1 & \textrm{if}\ N = 1 \\\frac{1}{N} \sum_{i=1}^{N} \delta_{\operatorname{sgn}(\Delta f_{i,i-1}),\ \operatorname{sgn}(\Delta a_{i,i-1})} & \textrm{if}\ N > 1 \end{cases}" alt="Equation for the mean directional accuracy."> --> |
| 30 | + |
| 31 | +```math |
| 32 | +\mathop{\mathrm{MDA}} = \begin{cases} 1 & \textrm{if}\ N = 1 \\\frac{1}{N} \sum_{i=1}^{N} \delta_{\mathop{\mathrm{sgn}}(\Delta f_{i,i-1}),\ \mathop{\mathrm{sgn}}(\Delta a_{i,i-1})} & \textrm{if}\ N > 1 \end{cases} |
| 33 | +``` |
| 34 | + |
| 35 | +<!-- <div class="equation" align="center" data-raw-text="\operatorname{MDA} = \begin{cases} 1 & \textrm{if}\ N = 1 \\\frac{1}{N} \sum_{i=1}^{N} \delta_{\operatorname{sgn}(\Delta f_{i,i-1}),\ \operatorname{sgn}(\Delta a_{i,i-1})} & \textrm{if}\ N > 1 \end{cases}" data-equation="eq:mean_directional_accuracy"> |
| 36 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@95b364439921fe28429acff89c5ba464a5a60caf/lib/node_modules/@stdlib/stats/incr/mda/docs/img/equation_mean_directional_accuracy.svg" alt="Equation for the mean directional accuracy."> |
| 37 | + <br> |
| 38 | +</div> --> |
| 39 | + |
| 40 | +<!-- </equation> --> |
| 41 | + |
| 42 | +where `f_i` is the forecast value, `a_i` is the actual value, `sgn(x)` is the [signum][@stdlib/math/base/special/signum] function, and `δ` is the [Kronecker delta][@stdlib/math/base/special/kronecker-delta]. |
| 43 | + |
| 44 | +</section> |
| 45 | + |
| 46 | +<!-- /.intro --> |
| 47 | + |
| 48 | +<section class="usage"> |
| 49 | + |
| 50 | +## Usage |
| 51 | + |
| 52 | +```javascript |
| 53 | +var incrnanmda = require( '@stdlib/stats/incr/nanmda' ); |
| 54 | +``` |
| 55 | + |
| 56 | +#### incrnanmda() |
| 57 | + |
| 58 | +Returns an accumulator `function` which incrementally computes the [mean directional accuracy][mean-directional-accuracy], ignoring `NaN` value. |
| 59 | + |
| 60 | +```javascript |
| 61 | +var accumulator = incrnanmda(); |
| 62 | +``` |
| 63 | + |
| 64 | +#### accumulator( \[f, a] ) |
| 65 | + |
| 66 | +If provided input values `f` and `a`, the accumulator function returns an updated [mean directional accuracy][mean-directional-accuracy]. If not provided input values `f` and `a`, the accumulator function returns the current [mean directional accuracy][mean-directional-accuracy]. |
| 67 | + |
| 68 | +```javascript |
| 69 | +var accumulator = incrnanmda(); |
| 70 | + |
| 71 | +var m = accumulator( 2.0, 3.0 ); |
| 72 | +// returns 1.0 |
| 73 | + |
| 74 | +m = accumulator( -1.0, 4.0 ); |
| 75 | +// returns 0.5 |
| 76 | + |
| 77 | +m = accumulator( NaN, 4.0 ); |
| 78 | +// returns 0.5 |
| 79 | + |
| 80 | +m = accumulator( -3.0, -2.0 ); |
| 81 | +// returns ~0.67 |
| 82 | + |
| 83 | +m = accumulator(); |
| 84 | +// returns ~0.67 |
| 85 | +``` |
| 86 | + |
| 87 | +</section> |
| 88 | + |
| 89 | +<!-- /.usage --> |
| 90 | + |
| 91 | +<section class="notes"> |
| 92 | + |
| 93 | +## Notes |
| 94 | + |
| 95 | +- Input values are type checked. If provided a NaN or a non-numeric value, the update is skipped and the accumulator returns the previously computed mean directional accuracy. If non-numeric inputs are possible, you are advised to type check and handle accordingly before passing the value to the accumulator function. |
| 96 | + |
| 97 | +</section> |
| 98 | + |
| 99 | +<!-- /.notes --> |
| 100 | + |
| 101 | +<section class="examples"> |
| 102 | + |
| 103 | +## Examples |
| 104 | + |
| 105 | +<!-- eslint no-undef: "error" --> |
| 106 | + |
| 107 | +```javascript |
| 108 | +var randu = require( '@stdlib/random/base/randu' ); |
| 109 | +var incrnanmda = require( '@stdlib/stats/incr/nanmda' ); |
| 110 | + |
| 111 | +var accumulator; |
| 112 | +var v1; |
| 113 | +var v2; |
| 114 | +var i; |
| 115 | + |
| 116 | +// Initialize an accumulator: |
| 117 | +accumulator = incrnanmda(); |
| 118 | + |
| 119 | +// For each simulated datum, update the mean directional accuracy... |
| 120 | +for ( i = 0; i < 100; i++ ) { |
| 121 | + if ( randu() < 0.2 ) { |
| 122 | + v1 = NaN; |
| 123 | + } else { |
| 124 | + v1 = ( randu()*100.0 ) - 50.0; |
| 125 | + } |
| 126 | + if ( randu() < 0.2 ) { |
| 127 | + v2 = NaN; |
| 128 | + } else { |
| 129 | + v2 = ( randu()*100.0 ) - 50.0; |
| 130 | + } |
| 131 | + accumulator( v1, v2 ); |
| 132 | +} |
| 133 | +console.log( accumulator() ); |
| 134 | +``` |
| 135 | + |
| 136 | +</section> |
| 137 | + |
| 138 | +<!-- /.examples --> |
| 139 | + |
| 140 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 141 | + |
| 142 | +<section class="related"> |
| 143 | + |
| 144 | +* * * |
| 145 | + |
| 146 | +## See Also |
| 147 | + |
| 148 | +- <span class="package-name">[`@stdlib/stats/incr/mape`][@stdlib/stats/incr/mape]</span><span class="delimiter">: </span><span class="description">compute the mean absolute percentage error (MAPE) incrementally.</span> |
| 149 | +- <span class="package-name">[`@stdlib/stats/incr/mmda`][@stdlib/stats/incr/mmda]</span><span class="delimiter">: </span><span class="description">compute a moving mean directional accuracy (MDA) incrementally.</span> |
| 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 | +<section class="links"> |
| 158 | + |
| 159 | +[mean-directional-accuracy]: https://en.wikipedia.org/wiki/Mean_Directional_Accuracy_%28MDA%29 |
| 160 | + |
| 161 | +[@stdlib/math/base/special/signum]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/signum |
| 162 | + |
| 163 | +[@stdlib/math/base/special/kronecker-delta]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/kronecker-delta |
| 164 | + |
| 165 | +<!-- <related-links> --> |
| 166 | + |
| 167 | +[@stdlib/stats/incr/mape]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mape |
| 168 | + |
| 169 | +[@stdlib/stats/incr/mmda]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mmda |
| 170 | + |
| 171 | +<!-- </related-links> --> |
| 172 | + |
| 173 | +</section> |
| 174 | + |
| 175 | +<!-- /.links --> |
0 commit comments