README.md (3911B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 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 > [Normal][normal-distribution] 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 [normal][normal-distribution] random variable with mean `μ` and standard deviation `σ > 0` is 30 31 <!-- <equation class="equation" label="eq:normal_entropy" align="center" raw="h\left( X \right) = \tfrac{1}{2}\ln(2\pi \,e\,\sigma ^{2})" alt="Differential entropy for a normal distribution."> --> 32 33 <div class="equation" align="center" data-raw-text="h\left( X \right) = \tfrac{1}{2}\ln(2\pi \,e\,\sigma ^{2})" data-equation="eq:normal_entropy"> 34 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/normal/entropy/docs/img/equation_normal_entropy.svg" alt="Differential entropy for a normal distribution."> 35 <br> 36 </div> 37 38 <!-- </equation> --> 39 40 </section> 41 42 <!-- /.intro --> 43 44 <!-- Package usage documentation. --> 45 46 <section class="usage"> 47 48 ## Usage 49 50 ```javascript 51 var entropy = require( '@stdlib/stats/base/dists/normal/entropy' ); 52 ``` 53 54 #### entropy( mu, sigma ) 55 56 Returns the [differential entropy][entropy] for a [normal][normal-distribution] distribution with mean `mu` and standard deviation `sigma` (in [nats][nats]). 57 58 ```javascript 59 var y = entropy( 2.0, 1.0 ); 60 // returns ~1.419 61 62 y = entropy( -1.0, 4.0 ); 63 // returns ~2.805 64 ``` 65 66 If provided `NaN` as any argument, the function returns `NaN`. 67 68 ```javascript 69 var y = entropy( NaN, 1.0 ); 70 // returns NaN 71 72 y = entropy( 0.0, NaN ); 73 // returns NaN 74 ``` 75 76 If provided `sigma <= 0`, the function returns `NaN`. 77 78 ```javascript 79 var y = entropy( 0.0, 0.0 ); 80 // returns NaN 81 82 y = entropy( 0.0, -1.0 ); 83 // returns NaN 84 ``` 85 86 </section> 87 88 <!-- /.usage --> 89 90 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 91 92 <section class="notes"> 93 94 </section> 95 96 <!-- /.notes --> 97 98 <!-- Package usage examples. --> 99 100 <section class="examples"> 101 102 ## Examples 103 104 <!-- eslint no-undef: "error" --> 105 106 ```javascript 107 var randu = require( '@stdlib/random/base/randu' ); 108 var entropy = require( '@stdlib/stats/base/dists/normal/entropy' ); 109 110 var sigma; 111 var mu; 112 var y; 113 var i; 114 115 for ( i = 0; i < 10; i++ ) { 116 mu = ( randu()*10.0 ) - 5.0; 117 sigma = randu() * 20.0; 118 y = entropy( mu, sigma ); 119 console.log( 'µ: %d, σ: %d, h(X;µ,σ): %d', mu.toFixed( 4 ), sigma.toFixed( 4 ), y.toFixed( 4 ) ); 120 } 121 ``` 122 123 </section> 124 125 <!-- /.examples --> 126 127 <!-- 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. --> 128 129 <section class="references"> 130 131 </section> 132 133 <!-- /.references --> 134 135 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 136 137 <section class="links"> 138 139 [normal-distribution]: https://en.wikipedia.org/wiki/Normal_distribution 140 141 [entropy]: https://en.wikipedia.org/wiki/Entropy_%28information_theory%29 142 143 [nats]: https://en.wikipedia.org/wiki/Nat_%28unit%29 144 145 </section> 146 147 <!-- /.links -->