-
-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into de…
…velop --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
- Loading branch information
Showing
54 changed files
with
3,795 additions
and
0 deletions.
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
lib/node_modules/@stdlib/stats/base/dists/planck/entropy/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<!-- | ||
@license Apache-2.0 | ||
Copyright (c) 2025 The Stdlib Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
# Entropy | ||
|
||
> Planck (discrete exponential) distribution [differential entropy][entropy]. | ||
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||
|
||
<section class="intro"> | ||
|
||
The [differential entropy][entropy] (in [nats][nats]) for a Planck random variable is | ||
|
||
<!-- <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."> --> | ||
|
||
```math | ||
H\left( X \right) = \frac{\lambda e^{-\lambda}}{1 - e^{-\lambda}} - \log\left( 1 - e^{-\lambda} \right) | ||
``` | ||
|
||
<!-- </equation> --> | ||
|
||
where `λ` is the shape parameter. | ||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<!-- Package usage documentation. --> | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var entropy = require( '@stdlib/stats/base/dists/planck/entropy' ); | ||
``` | ||
|
||
#### entropy( lambda ) | ||
|
||
Returns the [differential entropy][entropy] of a Planck distribution with shape parameter `lambda` (in [nats][nats]). | ||
|
||
```javascript | ||
var v = entropy( 0.1 ); | ||
// returns ~3.3030 | ||
|
||
v = entropy( 1.5 ); | ||
// returns ~0.6833 | ||
``` | ||
|
||
If provided a shape parameter `lambda` which is `NaN` or nonpositive, the function returns `NaN`. | ||
|
||
```javascript | ||
var v = entropy( NaN ); | ||
// returns NaN | ||
|
||
v = entropy( -1.5 ); | ||
// returns NaN | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="notes"> | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<!-- Package usage examples. --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var uniform = require( '@stdlib/random/array/uniform' ); | ||
var entropy = require( '@stdlib/stats/base/dists/planck/entropy' ); | ||
|
||
var lambda = uniform( 10, 0.1, 5.0 ); | ||
|
||
var v; | ||
var i; | ||
for ( i = 0; i < lambda.length; i++ ) { | ||
v = entropy( lambda[ i ] ); | ||
console.log( 'λ: %d, H(X;λ): %d', lambda[ i ].toFixed( 4 ), v.toFixed( 4 ) ); | ||
} | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
<!-- 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. --> | ||
|
||
<section class="references"> | ||
|
||
</section> | ||
|
||
<!-- /.references --> | ||
|
||
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
||
<section class="related"> | ||
|
||
</section> | ||
|
||
<!-- /.related --> | ||
|
||
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="links"> | ||
|
||
[entropy]: https://en.wikipedia.org/wiki/Entropy_%28information_theory%29 | ||
|
||
[nats]: https://en.wikipedia.org/wiki/Nat_%28unit%29 | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
52 changes: 52 additions & 0 deletions
52
lib/node_modules/@stdlib/stats/base/dists/planck/entropy/benchmark/benchmark.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2025 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var uniform = require( '@stdlib/random/array/uniform' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var pkg = require( './../package.json' ).name; | ||
var entropy = require( './../lib' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var lambda; | ||
var y; | ||
var i; | ||
|
||
lambda = uniform( 100, 0.1, 10.0 ); | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
y = entropy( lambda[ i % lambda.length ] ); | ||
if ( isnan( y ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( y ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); |
27 changes: 27 additions & 0 deletions
27
lib/node_modules/@stdlib/stats/base/dists/planck/entropy/docs/repl.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
{{alias}}( λ ) | ||
Returns the differential entropy of a Planck distribution with shape | ||
parameter `λ` (in nats). | ||
|
||
If `λ <= 0`, the function returns `NaN`. | ||
|
||
Parameters | ||
---------- | ||
λ: number | ||
Shape parameter. | ||
|
||
Returns | ||
------- | ||
out: number | ||
Entropy. | ||
|
||
Examples | ||
-------- | ||
> var v = {{alias}}( 0.1 ) | ||
~3.3030 | ||
> v = {{alias}}( 1.5 ) | ||
~0.6833 | ||
|
||
See Also | ||
-------- | ||
|
56 changes: 56 additions & 0 deletions
56
lib/node_modules/@stdlib/stats/base/dists/planck/entropy/docs/types/index.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2025 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// TypeScript Version: 4.1 | ||
|
||
/** | ||
* Returns the differential entropy of a Planck distribution. | ||
* | ||
* ## Notes | ||
* | ||
* - If `lambda <= 0`, the function returns `NaN`. | ||
* | ||
* @param lambda - shape parameter | ||
* @returns differential entropy | ||
* | ||
* @example | ||
* var v = entropy( 0.1 ); | ||
* // returns ~3.3030 | ||
* | ||
* @example | ||
* var v = entropy( 1.5 ); | ||
* // returns ~0.6833 | ||
* | ||
* @example | ||
* var v = entropy( 2.9 ); | ||
* // returns ~0.2255 | ||
* | ||
* @example | ||
* var v = entropy( -1.1 ); | ||
* // returns NaN | ||
* | ||
* @example | ||
* var v = entropy( NaN ); | ||
* // returns NaN | ||
*/ | ||
declare function entropy( lambda: number ): number; | ||
|
||
|
||
// EXPORTS // | ||
|
||
export = entropy; |
44 changes: 44 additions & 0 deletions
44
lib/node_modules/@stdlib/stats/base/dists/planck/entropy/docs/types/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2025 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import entropy = require( './index' ); | ||
|
||
|
||
// TESTS // | ||
|
||
// The function returns a number... | ||
{ | ||
entropy( 0.3 ); // $ExpectType number | ||
} | ||
|
||
// The compiler throws an error if the function is provided a value other than a number... | ||
{ | ||
entropy( true ); // $ExpectError | ||
entropy( false ); // $ExpectError | ||
entropy( null ); // $ExpectError | ||
entropy( undefined ); // $ExpectError | ||
entropy( '5' ); // $ExpectError | ||
entropy( [] ); // $ExpectError | ||
entropy( {} ); // $ExpectError | ||
entropy( ( x: number ): number => x ); // $ExpectError | ||
} | ||
|
||
// The compiler throws an error if the function is provided insufficient arguments... | ||
{ | ||
entropy(); // $ExpectError | ||
} |
31 changes: 31 additions & 0 deletions
31
lib/node_modules/@stdlib/stats/base/dists/planck/entropy/examples/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2025 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var uniform = require( '@stdlib/random/array/uniform' ); | ||
var entropy = require( './../lib' ); | ||
|
||
var lambda = uniform( 10, 0.1, 5.0 ); | ||
|
||
var v; | ||
var i; | ||
for ( i = 0; i < lambda.length; i++ ) { | ||
v = entropy( lambda[ i ] ); | ||
console.log( 'λ: %d, H(X;λ): %d', lambda[ i ].toFixed( 4 ), v.toFixed( 4 ) ); | ||
} |
Oops, something went wrong.
10d74f0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report
The above coverage report was generated for the changes in this push.