@stdlib/stats-base-dists-laplace-quantile
v0.3.1
Published
Laplace distribution quantile function.
Readme
Quantile Function
Laplace distribution quantile function.
The quantile function for a Laplace random variable is
for 0 <= p < 1, where mu is the location parameter and b > 0 is the scale parameter.
Installation
npm install @stdlib/stats-base-dists-laplace-quantileUsage
var quantile = require( '@stdlib/stats-base-dists-laplace-quantile' );quantile( p, mu, b )
Evaluates the quantile function for a Laplace distribution with parameters mu (location parameter) and b > 0 (scale parameter).
var y = quantile( 0.8, 0.0, 1.0 );
// returns ~0.916
y = quantile( 0.5, 4.0, 2.0 );
// returns 4If provided a probability p outside the interval [0,1], the function returns NaN.
var y = quantile( 1.9, 0.0, 1.0 );
// returns NaN
y = quantile( -0.1, 0.0, 1.0 );
// returns NaNIf provided NaN as any argument, the function returns NaN.
var y = quantile( NaN, 0.0, 1.0 );
// returns NaN
y = quantile( 0.0, NaN, 1.0 );
// returns NaN
y = quantile( 0.0, 0.0, NaN );
// returns NaNIf provided b <= 0, the function returns NaN.
var y = quantile( 0.4, 0.0, -1.0 );
// returns NaN
y = quantile( 0.4, 0.0, 0.0 );
// returns NaNquantile.factory( mu, b )
Returns a function for evaluating the quantile function of a Laplace distribution with parameters mu and b > 0.
var myquantile = quantile.factory( 10.0, 2.0 );
var y = myquantile( 0.5 );
// returns 10.0
y = myquantile( 0.8 );
// returns ~11.833Examples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var quantile = require( '@stdlib/stats-base-dists-laplace-quantile' );
var opts = {
'dtype': 'float64'
};
var p = uniform( 100, 0.0, 1.0, opts );
var mu = uniform( 100, 0.0, 10.0, opts );
var b = uniform( 100, 0.0, 10.0, opts );
logEachMap( 'p: %0.4f, µ: %0.4f, b: %0.4f, Q(p;µ,b): %0.4f', p, mu, b, quantile );C APIs
Usage
#include "stdlib/stats/base/dists/laplace/quantile.h"stdlib_base_dists_laplace_quantile( p, mu, b )
Evaluates the quantile function for a Laplace distribution with location parameter mu and scale parameter b at a probability p.
double out = stdlib_base_dists_laplace_quantile( 0.8, 0.0, 1.0 );
// returns ~0.916The function accepts the following arguments:
- p:
[in] doubleprobability. - mu:
[in] doublelocation parameter. - b:
[in] doublerate parameter.
double stdlib_base_dists_laplace_quantile( const double p, const double mu, const double b );Examples
#include "stdlib/stats/base/dists/laplace/quantile.h"
#include <stdlib.h>
#include <stdio.h>
static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
return min + ( v*(max-min) );
}
int main( void ) {
double mu;
double b;
double p;
double y;
int i;
for ( i = 0; i < 25; i++ ) {
mu = random_uniform( -5.0, 5.0 );
b = random_uniform( 0.0, 20.0 );
p = random_uniform( 0.0, 1.0 );
y = stdlib_base_dists_laplace_quantile( p, mu, b );
printf( "p: %lf, µ: %lf, b: %lf, Q(p;µ,b): %lf\n", p, mu, b, y );
}
}Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
