@stdlib/stats-base-dists-poisson-logpmf
v0.3.1
Published
Natural logarithm of the probability mass function (PMF) for a Poisson distribution.
Readme
Logarithm of Probability Mass Function
Evaluate the natural logarithm of the probability mass function (PMF) for a Poisson distribution.
The probability mass function (PMF) for a Poisson random variable is
where lambda > 0 is the mean parameter.
Installation
npm install @stdlib/stats-base-dists-poisson-logpmfUsage
var logpmf = require( '@stdlib/stats-base-dists-poisson-logpmf' );logpmf( x, lambda )
Evaluates the natural logarithm of the probability mass function (PMF) for a Poisson distribution with mean parameter lambda.
var y = logpmf( 4.0, 3.0 );
// returns ~-1.784
y = logpmf( 1.0, 3.0 );
// returns ~-1.901
y = logpmf( -1.0, 2.0 );
// returns -InfinityIf provided NaN as any argument, the function returns NaN.
var y = logpmf( NaN, 2.0 );
// returns NaN
y = logpmf( 0.0, NaN );
// returns NaNIf provided a negative mean parameter lambda, the function returns NaN.
var y = logpmf( 2.0, -1.0 );
// returns NaN
y = logpmf( 4.0, -2.0 );
// returns NaNIf provided lambda = 0, the function evaluates the natural logarithm of the PMF of a degenerate distribution centered at 0.0.
var y = logpmf( 2.0, 0.0 );
// returns -Infinity
y = logpmf( 0.0, 0.0 );
// returns 0.0logpmf.factory( lambda )
Returns a function for evaluating the natural logarithm of the probability mass function (PMF) for a Poisson distribution with mean parameter lambda.
var mylogpmf = logpmf.factory( 1.0 );
var y = mylogpmf( 3.0 );
// returns ~-2.792
y = mylogpmf( 1.0 );
// returns ~-1.0Examples
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var logpmf = require( '@stdlib/stats-base-dists-poisson-logpmf' );
var opts = {
'dtype': 'float64'
};
var x = discreteUniform( 10, 0.0, 10.0, opts );
var lambda = uniform( 10, 0.0, 10.0, opts );
logEachMap( 'x: %d, λ: %0.4f, ln(P(X=x;λ)): %0.4f', x, lambda, logpmf );C APIs
Usage
#include "stdlib/stats/base/dists/poisson/logpmf.h"stdlib_base_dists_poisson_logpmf( x, lambda )
Evaluates the natural logarithm of the probability mass function (PMF) for a Poisson distribution with mean parameter lambda.
double out = stdlib_base_dists_poisson_logpmf( 4.0, 3.0 );
// returns ~-1.784The function accepts the following arguments:
- x:
[in] doubleinput value. - lambda:
[in] doublemean parameter.
double stdlib_base_dists_poisson_logpmf( const double x, const double lambda );Examples
#include "stdlib/stats/base/dists/poisson/logpmf.h"
#include "stdlib/random/base/ceil.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 lambda;
double x;
double y;
int i;
for ( i = 0; i < 25; i++ ) {
x = stdlib_base_ceil( random_uniform( 0.0, 10.0 ) );
lambda = random_uniform( 0.0, 10.0);
y = stdlib_base_dists_poisson_logpmf( x, lambda );
printf( "x: %lf, λ: %lf, ln(P(X=x;λ)): %lf\n", x, lambda, 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.
