@stdlib/stats-base-dists-cauchy-pdf
v0.2.3
Published
Cauchy distribution probability density function (PDF).
Readme
Probability Density Function
Cauchy distribution probability density function (PDF).
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-pdfUsage
var pdf = require( '@stdlib/stats-base-dists-cauchy-pdf' );pdf( x, x0, gamma )
Evaluates the probability density function (PDF) for a Cauchy distribution with parameters x0 (location parameter) and gamma > 0 (scale parameter).
var y = pdf( 2.0, 1.0, 1.0 );
// returns ~0.159
y = pdf( 4.0, 3.0, 0.1 );
// returns ~0.0315
y = pdf( 4.0, 3.0, 3.0 );
// returns ~0.095If provided NaN as any argument, the function returns NaN.
var y = pdf( NaN, 1.0, 1.0 );
// returns NaN
y = pdf( 2.0, NaN, 1.0 );
// returns NaN
y = pdf( 2.0, 1.0, NaN );
// returns NaNIf provided gamma <= 0, the function returns NaN.
var y = pdf( 2.0, 0.0, -1.0 );
// returns NaN
y = pdf( 2.0, 0.0, 0.0 );
// returns NaNpdf.factory( x0, gamma )
Returns a function for evaluating the PDF of a Cauchy distribution with location parameter x0 and scale parameter gamma.
var mypdf = pdf.factory( 10.0, 2.0 );
var y = mypdf( 10.0 );
// returns ~0.159
y = mypdf( 5.0 );
// returns ~0.022Examples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var EPS = require( '@stdlib/constants-float64-eps' );
var pdf = require( '@stdlib/stats-base-dists-cauchy-pdf' );
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, f(x;x0,γ): %0.4f', x, x0, gamma, pdf );C APIs
Usage
#include "stdlib/stats/base/dists/cauchy/pdf.h"stdlib_base_dists_cauchy_pdf( x, x0, gamma )
Evaluates 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_pdf( 0.5, 0.0, 2.0 );
// returns ~0.333The function accepts the following arguments:
- x:
[in] doubleinput value. - x0:
[in] doublelocation parameter. - gamma:
[in] doublescale parameter.
double stdlib_base_dists_cauchy_pdf( const double x, const double x0, const double gamma );Examples
#include "stdlib/stats/base/dists/cauchy/pdf.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_pdf( x, x0, gamma );
printf( "x: %lf, k: %lf, γ: %lf, 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.
