Skip to content

Latest commit

 

History

History
172 lines (109 loc) · 4.38 KB

File metadata and controls

172 lines (109 loc) · 4.38 KB

Entropy

Hypergeometric distribution differential entropy.

The differential entropy for a hypergeometric random variable is given by

$$H(X) = - \sum_{k=\max(0, n+K-N)}^{\min(n, K)} P(X=k) \ln(P(X=k))$$

where N is the population size, K is the subpopulation size, and n is the number of draws.

Usage

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

entropy( N, K, n )

Returns the differential entropy for a hypergeometric distribution with population size N, subpopulation size K, and number of draws n (in nats).

var y = entropy( 16, 11, 4 );
// returns ~1.22

y = entropy( 2, 1, 1 );
// returns ~0.693

If provided NaN as any argument, the function returns NaN.

var y = entropy( NaN, 10, 4 );
// returns NaN

y = entropy( 20, NaN, 4 );
// returns NaN

y = entropy( 20, 10, NaN );
// returns NaN

If provided a population size N, subpopulation size K or draws n which is not a nonnegative integer, the function returns NaN.

var y = entropy( 10.5, 4, 2 );
// returns NaN

y = entropy( 10, 1.5, 2 );
// returns NaN

y = entropy( 10, 5, -2.0 );
// returns NaN

If the number of draws n or subpopulation size K exceeds population size N, the function returns NaN.

var y = entropy( 10, 11, 4 );
// returns NaN

y = entropy( 10, 5, 12 );
// returns NaN

Examples

var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var entropy = require( '@stdlib/stats/base/dists/hypergeometric/entropy' );

var i;
var N;
var K;
var n;
var y;

for ( i = 0; i < 10; i++ ) {
    N = round( randu() * 20.0 );
    K = round( randu() * N );
    n = round( randu() * N );
    y = entropy( N, K, n );
    console.log( 'N: %d, K: %d, n: %d, H(X;N,K,n): %d', N, K, n, y.toFixed( 4 ) );
}