@stdlib/stats-base-dists-degenerate-entropy
v0.3.1
Published
Degenerate distribution entropy.
Downloads
175
Readme
Entropy
Degenerate distribution entropy.
The entropy (in nats) for a degenerate random variable is
where μ is the constant value of the distribution.
Installation
npm install @stdlib/stats-base-dists-degenerate-entropyUsage
var entropy = require( '@stdlib/stats-base-dists-degenerate-entropy' );entropy( mu )
Returns the entropy of a degenerate distribution with constant value mu.
var v = entropy( 10.0 );
// returns 0.0
v = entropy( -0.5 );
// returns 0.0
v = entropy( NaN );
// returns NaNExamples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var entropy = require( '@stdlib/stats-base-dists-degenerate-entropy' );
var opts = {
'dtype': 'float64'
};
var mu = uniform( 10, 0.0, 1.0, opts );
logEachMap( 'µ: %0.4f, H(X;µ): %0.4f', mu, entropy );C APIs
Usage
#include "stdlib/stats/base/dists/degenerate/entropy.h"stdlib_base_dists_degenerate_entropy( mu )
Returns the entropy of a degenerate distribution with constant value mu.
double y = stdlib_base_dists_degenerate_entropy( 0.1 );
// returns 0.0The function accepts the following arguments:
- mu:
[in] doubleconstant value of distribution.
double stdlib_base_dists_degenerate_entropy( const double mu );Examples
#include "stdlib/stats/base/dists/degenerate/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 mu;
double y;
int i;
for ( i = 0; i < 10; i++ ) {
mu = random_uniform( 0.0, 1.0 );
y = stdlib_base_dists_degenerate_entropy( mu );
printf( "µ: %lf, H(X;µ): %lf\n", mu, 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.
