Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into de…
Browse files Browse the repository at this point in the history
…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
kgryte committed Jan 2, 2025
2 parents cbb3066 + 5524db1 commit 10d74f0
Show file tree
Hide file tree
Showing 54 changed files with 3,795 additions and 0 deletions.
141 changes: 141 additions & 0 deletions lib/node_modules/@stdlib/stats/base/dists/planck/entropy/README.md
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 -->
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();
});
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
--------

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;
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
}
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 ) );
}
Loading

1 comment on commit 10d74f0

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/geometric/quantile $\color{green}234/234$
$\color{green}+100.00\%$
$\color{green}25/25$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}234/234$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.