@stdlib/stats-base-dists-cauchy-logpdf
v0.2.3
Published
Cauchy distribution logarithm of probability density function (logPDF).
Downloads
475
Readme
Logarithm of Probability Density Function
Cauchy distribution logarithm of probability density function (logPDF).
The probability density function (PDF) for a Cauchy random variable is
where x0 is the location parameter and gamma > 0 is the scale parameter.
Installation
npm install @stdlib/stats-base-dists-cauchy-logpdfUsage
var logpdf = require( '@stdlib/stats-base-dists-cauchy-logpdf' );logpdf( x, x0, gamma )
Evaluates the natural logarithm of the probability density function (PDF) for a Cauchy distribution with parameters x0 (location parameter) and gamma > 0 (scale parameter).
var y = logpdf( 2.0, 1.0, 1.0 );
// returns ~-1.838
y = logpdf( 4.0, 3.0, 0.1 );
// returns ~-3.457
y = logpdf( 4.0, 3.0, 3.0 );
// returns ~-2.349If provided NaN as any argument, the function returns NaN.
var y = logpdf( NaN, 1.0, 1.0 );
// returns NaN
y = logpdf( 2.0, NaN, 1.0 );
// returns NaN
y = logpdf( 2.0, 1.0, NaN );
// returns NaNIf provided gamma <= 0, the function returns NaN.
var y = logpdf( 2.0, 0.0, -1.0 );
// returns NaNlogpdf.factory( x0, gamma )
Returns a function for evaluating the natural logarithm of the PDF of a Cauchy distribution with location parameter x0 and scale parameter gamma.
var mylogpdf = logpdf.factory( 10.0, 2.0 );
var y = mylogpdf( 10.0 );
// returns ~-1.838
y = mylogpdf( 5.0 );
// returns ~-3.819Notes
- 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.
Examples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var EPS = require( '@stdlib/constants-float64-eps' );
var logpdf = require( '@stdlib/stats-base-dists-cauchy-logpdf' );
var opts = {
'dtype': 'float64'
};
var gamma = uniform( 10, EPS, 20.0, opts );
var x0 = uniform( 10, -5.0, 5.0, opts );
var x = uniform( 10, 0.0, 10.0, opts );
logEachMap( 'x: %0.4f, x0: %0.4f, γ: %0.4f, ln(f(x;x0,γ)): %0.4f', x, x0, gamma, logpdf );C APIs
Usage
#include "stdlib/stats/base/dists/cauchy/logpdf.h"stdlib_base_dists_cauchy_logpdf( x, x0, gamma )
Evaluates the natural logarithm of the probability density function (PDF) for a Cauchy distribution with parameters x0 (location parameter) and gamma > 0 (scale parameter).
double out = stdlib_base_dists_cauchy_logpdf( 2.0, 1.0, 1.0 );
// returns ~-1.838The function accepts the following arguments:
- x:
[in] doubleinput value. - x0:
[in] doublelocation parameter. - gamma:
[in] doublescale parameter.
double stdlib_base_dists_cauchy_logpdf( const double x, const double x0, const double gamma );Examples
#include "stdlib/stats/base/dists/cauchy/logpdf.h"
#include "stdlib/constants/float64/eps.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 gamma;
double x0;
double x;
double y;
int i;
for ( i = 0; i < 25; i++ ) {
x = random_uniform( 0.0, 10.0 );
x0 = random_uniform( -5.0, 5.0 );
gamma = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
y = stdlib_base_dists_cauchy_logpdf( x, x0, gamma );
printf( "x: %lf, x0: %lf, γ: %lf, ln(f(x;x0,γ)): %lf\n", x, x0, gamma, 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.
