Skip to content

Latest commit

 

History

History
236 lines (143 loc) · 5.58 KB

File metadata and controls

236 lines (143 loc) · 5.58 KB

Entropy

Poisson distribution entropy.

The entropy (in nats) for a Poisson random variable is

$$H\left( X \right) = \lambda [1-\log(\lambda )]+e^{-\lambda }\sum_{k=0}^{\infty }{\frac{\lambda ^{k}\log(k!)}{k!}}$$

where λ is the mean parameter.

Usage

var entropy = require( '@stdlib/stats/base/dists/poisson/entropy' );

entropy( lambda )

Returns the entropy of a Poisson distribution with mean parameter lambda (in nats).

var v = entropy( 9.0 );
// returns ~2.508

v = entropy( 0.5 );
// returns ~0.928

If provided lambda < 0, the function returns NaN.

var v = entropy( -1.0 );
// returns NaN

Examples

var uniform = require( '@stdlib/random/array/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var entropy = require( '@stdlib/stats/base/dists/poisson/entropy' );

var opts = {
    'dtype': 'float64'
};
var lambda = uniform( 10, 0.0, 20.0, opts );

logEachMap( 'λ: %0.4f, H(X;λ): %0.4f', lambda, entropy );

C APIs

Usage

#include "stdlib/stats/base/dists/poisson/entropy.h"

stdlib_base_dists_poisson_entropy( lambda )

Returns the entropy of a Poisson distribution with mean parameter lambda (in nats).

double out = stdlib_base_dists_poisson_entropy( 9.0 );
// returns ~2.508

The function accepts the following arguments:

  • lambda: [in] double mean parameter.
double stdlib_base_dists_poisson_entropy( const double lambda );

Examples

#include "stdlib/stats/base/dists/poisson/entropy.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 y;
    int i;

    for ( i = 0; i < 25; i++ ) {
        lambda = random_uniform( 0.0, 20.0 );
        y = stdlib_base_dists_poisson_entropy( lambda );
        printf( "λ: %lf, h(X;λ): %lf\n", lambda, y );
    }
}