Laplace distribution logarithm of probability density function (PDF).
The probability density function (PDF) for a Laplace random variable is
where mu is the location parameter and b > 0 is the scale parameter (also called diversity).
var logpdf = require( '@stdlib/stats/base/dists/laplace/logpdf' );Evaluates the logarithm of the probability density function (PDF) for a Laplace distribution with parameters mu (location parameter) and b > 0 (scale parameter).
var y = logpdf( 2.0, 0.0, 1.0 );
// returns ~-2.693
y = logpdf( -1.0, 2.0, 3.0 );
// returns ~-2.792
y = logpdf( 2.5, 2.0, 3.0 );
// returns ~-1.958If provided NaN as any argument, the function returns NaN.
var y = logpdf( NaN, 0.0, 1.0 );
// returns NaN
y = logpdf( 0.0, NaN, 1.0 );
// returns NaN
y = logpdf( 0.0, 0.0, NaN );
// returns NaNIf provided b <= 0, the function returns NaN.
var y = logpdf( 2.0, 0.0, -1.0 );
// returns NaN
y = logpdf( 2.0, 8.0, 0.0 );
// returns NaNReturns a function for evaluating the logarithm of the PDF for a Laplace distribution with parameters mu (location parameter) and b > 0 (scale parameter).
var mylogpdf = logpdf.factory( 10.0, 2.0 );
var y = mylogpdf( 10.0 );
// returns ~-1.386
y = mylogpdf( 5.0 );
// returns ~-3.886
y = mylogpdf( 12.0 );
// returns ~-2.386- In virtually all cases, using the
logpdforlogcdffunctions is preferable to manually computing the logarithm of thepdforcdf, respectively, since the latter is prone to overflow and underflow.
var uniform = require( '@stdlib/random/array/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var logpdf = require( '@stdlib/stats/base/dists/laplace/logpdf' );
var opts = {
'dtype': 'float64'
};
var x = uniform( 100, 0.0, 10.0, opts );
var mu = uniform( 100, 0.0, 10.0, opts );
var b = uniform( 100, 0.0, 10.0, opts );
logEachMap( 'x: %0.4f, µ: %0.4f, b: %0.4f, ln(f(x;µ,b)): %0.4f', x, mu, b, logpdf );#include "stdlib/stats/base/dists/laplace/logpdf.h"Evaluates the logarithm of the probability density function (PDF) for a Laplace distribution with location parameter mu and scale parameter b at a value x.
double out = stdlib_base_dists_laplace_logpdf( 2.0, 0.0, 1.0 );
// returns ~-2.693The function accepts the following arguments:
- x:
[in] doubleinput value. - mu:
[in] doublelocation parameter. - b:
[in] doublerate parameter.
double stdlib_base_dists_laplace_logpdf( const double x, const double mu, const double b );#include "stdlib/stats/base/dists/laplace/logpdf.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 x;
double y;
int i;
for ( i = 0; i < 25; i++ ) {
mu = random_uniform( -5.0, 5.0 );
b = random_uniform( 0.0, 20.0 );
x = random_uniform( 0.0, 20.0 );
y = stdlib_base_dists_laplace_logpdf( x, mu, b );
printf( "x: %lf, µ: %lf, b: %lf, ln(f(x;µ,b)): %lf\n", x, mu, b, y );
}
}