time-to-botec

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

README.md (4339B)


      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 # gammincinv
     22 
     23 > Inverse of [incomplete gamma function][incomplete-gamma-function].
     24 
     25 <section class="intro">
     26 
     27 Computes the inverse of the lower [incomplete gamma function][incomplete-gamma-function]
     28 
     29 <!-- <equation class="equation" label="eq:lower_incomplete_gamma" align="center" raw="P( x, a ) = \frac{\gamma(a,x)}{\Gamma(a)} = \frac{1}{\Gamma(a)} \int_0^x t^{a-1} e^{-t} \; dt" alt="Regularized lower incomplete gamma function."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="P( x, a ) = \frac{\gamma(a,x)}{\Gamma(a)} = \frac{1}{\Gamma(a)} \int_0^x t^{a-1} e^{-t} \; dt" data-equation="eq:lower_incomplete_gamma">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/gammaincinv/docs/img/equation_lower_incomplete_gamma.svg" alt="Regularized lower incomplete gamma function.">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 Specifically, for given `p` and `a` it finds the `x` such that `p =  P(x, a)`.
     39 
     40 The function can also be used to invert the upper incomplete gamma function, which is defined as follows:  
     41 
     42 <!-- <equation class="equation" label="eq:upper_incomplete_gamma" align="center" raw="Q( x, a ) = \frac{\Gamma(a,x)}{\Gamma(a)} = \frac{1}{\Gamma(a)} \int_x^\infty t^{a-1} e^{-t} \; dt" alt="Regularized upper incomplete gamma function."> -->
     43 
     44 <div class="equation" align="center" data-raw-text="Q( x, a ) = \frac{\Gamma(a,x)}{\Gamma(a)} = \frac{1}{\Gamma(a)} \int_x^\infty t^{a-1} e^{-t} \; dt" data-equation="eq:upper_incomplete_gamma">
     45     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/gammaincinv/docs/img/equation_upper_incomplete_gamma.svg" alt="Regularized upper incomplete gamma function.">
     46     <br>
     47 </div>
     48 
     49 <!-- </equation> -->
     50 
     51 Again, for given `p` and `a` the function returns the `x` which satisfies `p = Q(x, a)`.
     52 
     53 </section>
     54 
     55 <!-- /.intro -->
     56 
     57 <section class="usage">
     58 
     59 ## Usage
     60 
     61 ```javascript
     62 var gammaincinv = require( '@stdlib/math/base/special/gammaincinv' );
     63 ```
     64 
     65 #### gammaincinv( p, s\[, upper ] )
     66 
     67 Inverts the regularized incomplete gamma function. Contrary to the more commonly used definition, in this implementation the first argument is the probability `p` and the second argument is the scale factor `a`. By default, the function inverts the _lower_ regularized incomplete gamma function, `P(x,a)`. To invert the _upper_ function instead, i.e. `Q(x,a)`, set the `upper` argument to `true`.
     68 
     69 ```javascript
     70 var y = gammaincinv( 0.5, 2.0 );
     71 // returns ~1.678
     72 
     73 y = gammaincinv( 0.1, 10.0 );
     74 // returns ~6.221
     75 
     76 y = gammaincinv( 0.75, 3.0 );
     77 // returns ~3.92
     78 
     79 y = gammaincinv( 0.75, 3.0, true );
     80 // returns ~1.727
     81 ```
     82 
     83 If provided `NaN` as any argument, the function returns `NaN`.
     84 
     85 ```javascript
     86 var y = gammaincinv( NaN, 1.0 );
     87 // returns NaN
     88 
     89 y = gammaincinv( 0.5, NaN );
     90 // returns NaN
     91 ```
     92 
     93 If provided a value outside `[0,1]` for `p`, the function returns `NaN`.
     94 
     95 ```javascript
     96 var y = gammaincinv( 1.2, 1.0 );
     97 // returns NaN
     98 
     99 y = gammaincinv( -0.5, 1.0 );
    100 // returns NaN
    101 ```
    102 
    103 </section>
    104 
    105 <!-- /.usage -->
    106 
    107 <section class="examples">
    108 
    109 ## Examples
    110 
    111 <!-- eslint no-undef: "error" -->
    112 
    113 ```javascript
    114 var randu = require( '@stdlib/random/base/randu' );
    115 var gammaincinv = require( '@stdlib/math/base/special/gammaincinv' );
    116 
    117 var a;
    118 var i;
    119 var p;
    120 
    121 for ( i = 0; i < 100; i++ ) {
    122     p = randu();
    123     a = randu() * 50.0;
    124     console.log( 'p: %d, \t a: %d, \t P^(-1)(p, a): %d', p.toFixed( 4 ), a.toFixed( 4 ), gammaincinv( p, a ).toFixed( 4 ) );
    125 }
    126 ```
    127 
    128 </section>
    129 
    130 <!-- /.examples -->
    131 
    132 <section class="links">
    133 
    134 [incomplete-gamma-function]: https://en.wikipedia.org/wiki/Incomplete_gamma_function
    135 
    136 </section>
    137 
    138 <!-- /.links -->