-
-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add stats/base/dists/planck/variance
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: passed - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- 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
1 parent
0fc382d
commit 244351c
Showing
12 changed files
with
680 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/variance/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) 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. | ||
--> | ||
|
||
# Variance | ||
|
||
> Planck distribution [variance][variance]. | ||
<!-- 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 [variance][variance] for a Planck random variable is | ||
|
||
<!-- <equation class="equation" label="eq:planck_variance" align="center" raw="\operatorname{Var}\left( X \right) = \frac{e^{-\lambda}}{\left( 1 - e^{-\lambda} \right)^{2}}" alt="Variance for a Planck distribution."> --> | ||
|
||
```math | ||
\mathop{\mathrm{Var}}\left( X \right) = \frac{e^{-\lambda}}{\left( 1 - e^{-\lambda} \right)^{2}} | ||
``` | ||
|
||
<!-- </equation> --> | ||
|
||
where `lambda` is the shape parameter. | ||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<!-- Package usage documentation. --> | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var variance = require( '@stdlib/stats/base/dists/planck/variance' ); | ||
``` | ||
|
||
#### variance( lambda ) | ||
|
||
Returns the [variance][variance] of a Planck distribution with shape parameter `lambda`. | ||
|
||
```javascript | ||
var v = variance( 0.1 ); | ||
// returns ~99.9167 | ||
|
||
v = variance( 1.5 ); | ||
// returns ~0.3697 | ||
``` | ||
|
||
If provided a success probability `lambda` which is negative, the function returns `NaN`. | ||
|
||
```javascript | ||
var v = variance( NaN ); | ||
// returns NaN | ||
|
||
v = variance( -1.0 ); | ||
// 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 variance = require( '@stdlib/stats/base/dists/planck/variance' ); | ||
|
||
var lambda; | ||
var v; | ||
var i; | ||
|
||
lambda = uniform( 10, 0.0, 10.0 ); | ||
|
||
for ( i = 0; i < 10; i++ ) { | ||
v = variance( lambda[ i ] ); | ||
console.log( 'lambda: %d, Var(X;lambda): %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"> | ||
|
||
[variance]: https://en.wikipedia.org/wiki/Variance | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
52 changes: 52 additions & 0 deletions
52
lib/node_modules/@stdlib/stats/base/dists/planck/variance/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) 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 uniform = require( '@stdlib/random/array/uniform' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var pkg = require( './../package.json' ).name; | ||
var variance = require( './../lib' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var lambda; | ||
var y; | ||
var i; | ||
|
||
lambda = uniform( 100, 0.0, 10.0 ); | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
y = variance( 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/variance/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}}( lambda ) | ||
Returns the variance of a Planck distribution with shape parameter | ||
`lambda`. | ||
|
||
If `lambda < 0`, the function returns `NaN`. | ||
|
||
Parameters | ||
---------- | ||
lambda: number | ||
Shape parameter. | ||
|
||
Returns | ||
------- | ||
out: number | ||
Variance. | ||
|
||
Examples | ||
-------- | ||
> var v = {{alias}}( 0.1 ) | ||
~99.9167 | ||
> v = {{alias}}( 1.5 ) | ||
~0.3697 | ||
|
||
See Also | ||
-------- | ||
|
52 changes: 52 additions & 0 deletions
52
lib/node_modules/@stdlib/stats/base/dists/planck/variance/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,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 variance of a Planck distribution. | ||
* | ||
* ## Notes | ||
* | ||
* - If `lambda < 0`, the function returns `NaN`. | ||
* | ||
* @param lambda - shape parameter | ||
* @returns variance | ||
* | ||
* @example | ||
* var v = variance( 0.1 ); | ||
* // returns ~99.9167 | ||
* | ||
* @example | ||
* var v = variance( 1.5 ); | ||
* // returns ~0.3697 | ||
* | ||
* @example | ||
* var v = variance( -1.0 ); | ||
* // returns NaN | ||
* | ||
* @example | ||
* var v = variance( NaN ); | ||
* // returns NaN | ||
*/ | ||
declare function variance( lambda: number ): number; | ||
|
||
|
||
// EXPORTS // | ||
|
||
export = variance; |
44 changes: 44 additions & 0 deletions
44
lib/node_modules/@stdlib/stats/base/dists/planck/variance/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) 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 variance = require( './index' ); | ||
|
||
|
||
// TESTS // | ||
|
||
// The function returns a number... | ||
{ | ||
variance( 0.3 ); // $ExpectType number | ||
} | ||
|
||
// The compiler throws an error if the function is provided a value other than a number... | ||
{ | ||
variance( true ); // $ExpectError | ||
variance( false ); // $ExpectError | ||
variance( null ); // $ExpectError | ||
variance( undefined ); // $ExpectError | ||
variance( '5' ); // $ExpectError | ||
variance( [] ); // $ExpectError | ||
variance( {} ); // $ExpectError | ||
variance( ( x: number ): number => x ); // $ExpectError | ||
} | ||
|
||
// The compiler throws an error if the function is provided insufficient arguments... | ||
{ | ||
variance(); // $ExpectError | ||
} |
33 changes: 33 additions & 0 deletions
33
lib/node_modules/@stdlib/stats/base/dists/planck/variance/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,33 @@ | ||
/** | ||
* @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 uniform = require( '@stdlib/random/array/uniform' ); | ||
var variance = require( './../lib' ); | ||
|
||
var lambda; | ||
var v; | ||
var i; | ||
|
||
lambda = uniform( 10, 0.0, 10.0 ); | ||
|
||
for ( i = 0; i < 10; i++ ) { | ||
v = variance( lambda[ i ] ); | ||
console.log( 'lambda: %d, Var(X;lambda): %d', lambda[ i ].toFixed( 4 ), v.toFixed( 4 ) ); | ||
} |
43 changes: 43 additions & 0 deletions
43
lib/node_modules/@stdlib/stats/base/dists/planck/variance/lib/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,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 variance. | ||
* | ||
* @module @stdlib/stats/base/dists/planck/variance | ||
* | ||
* @example | ||
* var variance = require( '@stdlib/stats/base/dists/planck/variance' ); | ||
* | ||
* var v = variance( 0.1 ); | ||
* // returns ~99.9167 | ||
* | ||
* v = variance( 1.5 ); | ||
* // returns ~0.3697 | ||
*/ | ||
|
||
// MODULES // | ||
|
||
var main = require( './main.js' ); | ||
|
||
|
||
// EXPORTS // | ||
|
||
module.exports = main; |
Oops, something went wrong.