-
-
Notifications
You must be signed in to change notification settings - Fork 831
feat: add stats/base/dists/planck/mean
#3942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2b3b312
feat: add stats/base/dists/planck/mean
Jaysukh-409 2b45687
fix: apply code review suggestion
Jaysukh-409 7f100e8
Merge remote-tracking branch 'upstream/develop' into planck-mean
stdlib-bot e4e649f
Merge remote-tracking branch 'upstream/develop' into planck-mean
stdlib-bot 27d1683
fix: apply code review suggestion
Jaysukh-409 03838ec
chore: clean-up
kgryte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
lib/node_modules/@stdlib/stats/base/dists/planck/mean/README.md
This file contains hidden or 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,140 @@ | ||
<!-- | ||
|
||
@license Apache-2.0 | ||
|
||
Copyright (c) 2024 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. | ||
|
||
--> | ||
|
||
# Mean | ||
|
||
> Planck distribution [expected value][expected-value]. | ||
|
||
<!-- 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 [expected value][expected-value] for a Planck random variable is | ||
|
||
<!-- <equation class="equation" label="eq:planck_expectation" align="center" raw="\mathbb{E}\left[ X \right] = \frac{1}{e^{\lambda} - 1}" alt="Expected value for a Planck distribution."> --> | ||
|
||
```math | ||
\mathbb{E}\left[ X \right] = \frac{1}{e^{\lambda} - 1} | ||
``` | ||
|
||
<!-- </equation> --> | ||
|
||
where `lambda` is the shape parameter. | ||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<!-- Package usage documentation. --> | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var mean = require( '@stdlib/stats/base/dists/planck/mean' ); | ||
``` | ||
|
||
#### mean( lambda ) | ||
|
||
Returns the [expected value][expected-value] of a Planck distribution with shape parameter `lambda`. | ||
|
||
```javascript | ||
var v = mean( 0.1 ); | ||
// returns ~9.5083 | ||
|
||
v = mean( 0.5 ); | ||
// returns ~1.5415 | ||
``` | ||
|
||
If provided a shape parameter `lambda` which is negative or `NaN`, the function returns `NaN`. | ||
|
||
```javascript | ||
var v = mean( NaN ); | ||
// returns NaN | ||
|
||
v = mean( -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 randu = require( '@stdlib/random/base/randu' ); | ||
var mean = require( '@stdlib/stats/base/dists/planck/mean' ); | ||
|
||
var lambda; | ||
var v; | ||
var i; | ||
|
||
for ( i = 0; i < 10; i++ ) { | ||
lambda = randu(); | ||
v = mean( lambda ); | ||
console.log( 'lambda: %d, E(X;lambda): %d', lambda.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"> | ||
|
||
[expected-value]: https://en.wikipedia.org/wiki/Expected_value | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
51 changes: 51 additions & 0 deletions
51
lib/node_modules/@stdlib/stats/base/dists/planck/mean/benchmark/benchmark.js
This file contains hidden or 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,51 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 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 randu = require( '@stdlib/random/base/randu' ); | ||
Jaysukh-409 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var pkg = require( './../package.json' ).name; | ||
var mean = require( './../lib' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var lambda; | ||
var y; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
lambda = ( randu()*20.0 ); | ||
y = mean( lambda ); | ||
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/mean/docs/repl.txt
This file contains hidden or 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}}( lambda ) | ||
Returns the expected value of a Planck distribution with shape | ||
parameter `lambda`. | ||
|
||
If `lambda < 0`, the function returns `NaN`. | ||
|
||
Parameters | ||
---------- | ||
lambda: number | ||
Shape parameter. | ||
|
||
Returns | ||
------- | ||
out: number | ||
Expected value. | ||
|
||
Examples | ||
-------- | ||
> var v = {{alias}}( 0.1 ) | ||
~9.5083 | ||
> v = {{alias}}( 0.5 ) | ||
~1.5415 | ||
|
||
See Also | ||
-------- | ||
|
52 changes: 52 additions & 0 deletions
52
lib/node_modules/@stdlib/stats/base/dists/planck/mean/docs/types/index.d.ts
This file contains hidden or 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) 2024 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 expected value of a Planck distribution. | ||
* | ||
* ## Notes | ||
* | ||
* - If `lambda < 0`, the function returns `NaN`. | ||
* | ||
* @param lambda - shape parameter | ||
* @returns expected value | ||
* | ||
* @example | ||
* var v = mean( 0.1 ); | ||
* // returns ~9.5083 | ||
* | ||
* @example | ||
* var v = mean( 0.5 ); | ||
* // returns ~1.5415 | ||
* | ||
* @example | ||
* var v = mean( 1.1 ); | ||
* // returns ~0.4989 | ||
* | ||
* @example | ||
* var v = mean( NaN ); | ||
* // returns NaN | ||
*/ | ||
declare function mean( lambda: number ): number; | ||
|
||
|
||
// EXPORTS // | ||
|
||
export = mean; |
44 changes: 44 additions & 0 deletions
44
lib/node_modules/@stdlib/stats/base/dists/planck/mean/docs/types/test.ts
This file contains hidden or 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) 2024 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 mean = require( './index' ); | ||
|
||
|
||
// TESTS // | ||
|
||
// The function returns a number... | ||
{ | ||
mean( 0.3 ); // $ExpectType number | ||
} | ||
|
||
// The compiler throws an error if the function is provided a value other than a number... | ||
{ | ||
mean( true ); // $ExpectError | ||
mean( false ); // $ExpectError | ||
mean( null ); // $ExpectError | ||
mean( undefined ); // $ExpectError | ||
mean( '5' ); // $ExpectError | ||
mean( [] ); // $ExpectError | ||
mean( {} ); // $ExpectError | ||
mean( ( x: number ): number => x ); // $ExpectError | ||
} | ||
|
||
// The compiler throws an error if the function is provided insufficient arguments... | ||
{ | ||
mean(); // $ExpectError | ||
} |
32 changes: 32 additions & 0 deletions
32
lib/node_modules/@stdlib/stats/base/dists/planck/mean/examples/index.js
This file contains hidden or 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,32 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 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 randu = require( '@stdlib/random/base/randu' ); | ||
Jaysukh-409 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var mean = require( './../lib' ); | ||
|
||
var lambda; | ||
var v; | ||
var i; | ||
|
||
for ( i = 0; i < 10; i++ ) { | ||
lambda = randu(); | ||
v = mean( lambda ); | ||
console.log( 'lambda: %d, E(X;lambda): %d', lambda.toFixed( 4 ), v.toFixed( 4 ) ); | ||
} |
43 changes: 43 additions & 0 deletions
43
lib/node_modules/@stdlib/stats/base/dists/planck/mean/lib/index.js
This file contains hidden or 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,43 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 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'; | ||
|
||
/** | ||
* Planck distribution expected value. | ||
* | ||
* @module @stdlib/stats/base/dists/planck/mean | ||
* | ||
* @example | ||
* var mean = require( '@stdlib/stats/base/dists/planck/mean' ); | ||
* | ||
* var v = mean( 0.1 ); | ||
* // returns ~9.5083 | ||
* | ||
* v = mean( 0.5 ); | ||
* // returns ~1.5415 | ||
*/ | ||
|
||
// MODULES // | ||
|
||
var mean = require( './main.js' ); | ||
|
||
|
||
// EXPORTS // | ||
|
||
module.exports = mean; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.