main.js (1885B)
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 incrmean = require( './../../../incr/mean' ); 24 var abs = require( '@stdlib/math/base/special/abs' ); 25 var atan = require( '@stdlib/math/base/special/atan' ); 26 27 28 // MAIN // 29 30 /** 31 * Returns an accumulator function which incrementally computes the mean arctangent absolute percentage error. 32 * 33 * @returns {Function} accumulator function 34 * 35 * @example 36 * var accumulator = incrmaape(); 37 * 38 * var m = accumulator(); 39 * // returns null 40 * 41 * m = accumulator( 2.0, 3.0 ); 42 * // returns ~0.3218 43 * 44 * m = accumulator( 5.0, 2.0 ); 45 * // returns ~0.6523 46 * 47 * m = accumulator(); 48 * // returns ~0.6523 49 */ 50 function incrmaape() { 51 var mean = incrmean(); 52 return accumulator; 53 54 /** 55 * If provided input values, the accumulator function returns an updated mean arctangent absolute percentage error. If not provided input values, the accumulator function returns the current mean arctangent absolute percentage error. 56 * 57 * @private 58 * @param {number} [f] - input value 59 * @param {number} [a] - input value 60 * @returns {(number|null)} mean arctangent absolute percentage error or null 61 */ 62 function accumulator( f, a ) { 63 if ( arguments.length === 0 ) { 64 return mean(); 65 } 66 return mean( atan( abs( (a-f)/a ) ) ); 67 } 68 } 69 70 71 // EXPORTS // 72 73 module.exports = incrmaape;