|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# Entropy |
| 22 | + |
| 23 | +> Planck (discrete exponential) distribution [differential entropy][entropy]. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +The [differential entropy][entropy] (in [nats][nats]) for a Planck random variable is |
| 30 | + |
| 31 | +<!-- <equation class="equation" label="eq:planck_entropy" align="center" raw="H\left( X \right) = \frac{\lambda e^{-\lambda}}{1 - e^{-\lambda}} - \log\left( 1 - e^{-\lambda} \right)" alt="Differential entropy for a Planck distribution."> --> |
| 32 | + |
| 33 | +```math |
| 34 | +H\left( X \right) = \frac{\lambda e^{-\lambda}}{1 - e^{-\lambda}} - \log\left( 1 - e^{-\lambda} \right) |
| 35 | +``` |
| 36 | + |
| 37 | +<!-- </equation> --> |
| 38 | + |
| 39 | +where `λ` is the shape parameter. |
| 40 | + |
| 41 | +</section> |
| 42 | + |
| 43 | +<!-- /.intro --> |
| 44 | + |
| 45 | +<!-- Package usage documentation. --> |
| 46 | + |
| 47 | +<section class="usage"> |
| 48 | + |
| 49 | +## Usage |
| 50 | + |
| 51 | +```javascript |
| 52 | +var entropy = require( '@stdlib/stats/base/dists/planck/entropy' ); |
| 53 | +``` |
| 54 | + |
| 55 | +#### entropy( lambda ) |
| 56 | + |
| 57 | +Returns the [differential entropy][entropy] of a Planck distribution with shape parameter `lambda` (in [nats][nats]). |
| 58 | + |
| 59 | +```javascript |
| 60 | +var v = entropy( 0.1 ); |
| 61 | +// returns ~3.3030 |
| 62 | + |
| 63 | +v = entropy( 1.5 ); |
| 64 | +// returns ~0.6833 |
| 65 | +``` |
| 66 | + |
| 67 | +If provided a shape parameter `lambda` which is `NaN` or nonpositive, the function returns `NaN`. |
| 68 | + |
| 69 | +```javascript |
| 70 | +var v = entropy( NaN ); |
| 71 | +// returns NaN |
| 72 | + |
| 73 | +v = entropy( -1.5 ); |
| 74 | +// returns NaN |
| 75 | +``` |
| 76 | + |
| 77 | +</section> |
| 78 | + |
| 79 | +<!-- /.usage --> |
| 80 | + |
| 81 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 82 | + |
| 83 | +<section class="notes"> |
| 84 | + |
| 85 | +</section> |
| 86 | + |
| 87 | +<!-- /.notes --> |
| 88 | + |
| 89 | +<!-- Package usage examples. --> |
| 90 | + |
| 91 | +<section class="examples"> |
| 92 | + |
| 93 | +## Examples |
| 94 | + |
| 95 | +<!-- eslint no-undef: "error" --> |
| 96 | + |
| 97 | +```javascript |
| 98 | +var uniform = require( '@stdlib/random/array/uniform' ); |
| 99 | +var entropy = require( '@stdlib/stats/base/dists/planck/entropy' ); |
| 100 | + |
| 101 | +var lambda = uniform( 10, 0.1, 5.0 ); |
| 102 | + |
| 103 | +var v; |
| 104 | +var i; |
| 105 | +for ( i = 0; i < lambda.length; i++ ) { |
| 106 | + v = entropy( lambda[ i ] ); |
| 107 | + console.log( 'λ: %d, H(X;λ): %d', lambda[ i ].toFixed( 4 ), v.toFixed( 4 ) ); |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +</section> |
| 112 | + |
| 113 | +<!-- /.examples --> |
| 114 | + |
| 115 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 116 | + |
| 117 | +<section class="references"> |
| 118 | + |
| 119 | +</section> |
| 120 | + |
| 121 | +<!-- /.references --> |
| 122 | + |
| 123 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 124 | + |
| 125 | +<section class="related"> |
| 126 | + |
| 127 | +</section> |
| 128 | + |
| 129 | +<!-- /.related --> |
| 130 | + |
| 131 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 132 | + |
| 133 | +<section class="links"> |
| 134 | + |
| 135 | +[entropy]: https://en.wikipedia.org/wiki/Entropy_%28information_theory%29 |
| 136 | + |
| 137 | +[nats]: https://en.wikipedia.org/wiki/Nat_%28unit%29 |
| 138 | + |
| 139 | +</section> |
| 140 | + |
| 141 | +<!-- /.links --> |
0 commit comments