time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

main.js (1956B)


      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 expm1 = require( './../../../../base/special/expm1' );
     24 var log1p = require( './../../../../base/special/log1p' );
     25 var abs = require( './../../../../base/special/abs' );
     26 var isnan = require( './../../../../base/assert/is-nan' );
     27 
     28 
     29 // MAIN //
     30 
     31 /**
     32 * Computes the inverse of a one-parameter Box-Cox transformation for `1+x`.
     33 *
     34 * @param {number} y - input value
     35 * @param {number} lambda - power parameter
     36 * @returns {number} inverse of the Box-Cox transformation
     37 *
     38 * @example
     39 * var v = boxcox1pinv( 1.0, 2.5 );
     40 * // returns ~0.6505
     41 *
     42 * @example
     43 * var v = boxcox1pinv( 4.0, 2.5 );
     44 * // returns ~1.6095
     45 *
     46 * @example
     47 * var v = boxcox1pinv( 10.0, 2.5 );
     48 * // returns ~2.6812
     49 *
     50 * @example
     51 * var v = boxcox1pinv( 2.0, 0.0 );
     52 * // returns ~6.3891
     53 *
     54 * @example
     55 * var v = boxcox1pinv( -1.0, 2.5 );
     56 * // returns NaN
     57 *
     58 * @example
     59 * var v = boxcox1pinv( 0.0, -1.0 );
     60 * // returns 0.0
     61 *
     62 * @example
     63 * var v = boxcox1pinv( 1.0, NaN );
     64 * // returns NaN
     65 *
     66 * @example
     67 * var v = boxcox1pinv( NaN, 3.1 );
     68 * // returns NaN
     69 */
     70 function boxcox1pinv( y, lambda ) {
     71 	var ly;
     72 	if ( isnan( y ) || isnan( lambda ) ) {
     73 		return NaN;
     74 	}
     75 	if ( lambda === 0.0 ) {
     76 		return expm1( y );
     77 	}
     78 	ly = lambda * y;
     79 	if ( abs( ly ) < 1.0e-154 ) {
     80 		return y;
     81 	}
     82 	return expm1( log1p( ly ) / lambda );
     83 }
     84 
     85 
     86 // EXPORTS //
     87 
     88 module.exports = boxcox1pinv;