time-to-botec

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

main.js (1579B)


      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 factory = require( './factory.js' );
     24 
     25 
     26 // MAIN //
     27 
     28 /**
     29 * Returns a random number drawn from an inverse gamma distribution.
     30 *
     31 * ## Method
     32 *
     33 * When
     34 *
     35 * ```tex
     36 * X \sim \operatorname{Gamma}( \alpha, \beta )
     37 * ```
     38 *
     39 * then
     40 *
     41 * ```tex
     42 * \frac{1}{X} \sim \operatorname{InvGamma}\left( \alpha, \tfrac{1}{beta} \right)
     43 * ```
     44 *
     45 * Hence, to generate a draw from an inverse gamma distribution with parameters \\( \alpha \\) and \\( \beta \\), sample `X` from a \\( \operatorname{Gamma}\left( \alpha, \tfrac{1}{\beta} \right) \\) distribution and return `1/X`.
     46 *
     47 *
     48 * @name invgamma
     49 * @type {PRNG}
     50 * @param {PositiveNumber} alpha - shape parameter
     51 * @param {PositiveNumber} beta - scale parameter
     52 * @returns {number} pseudorandom number
     53 *
     54 * @example
     55 * var v = invgamma( 2.0, 1.0 );
     56 * // returns <number>
     57 *
     58 * @example
     59 * var v = invgamma( -2.0, 5.0 );
     60 * // returns NaN
     61 */
     62 var invgamma = factory();
     63 
     64 
     65 // EXPORTS //
     66 
     67 module.exports = invgamma;