Skip to content

Commit 47be8ae

Browse files
committed
feat: add docs, benchmarks and examples
--- 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: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - 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 ---
1 parent 52c1a89 commit 47be8ae

File tree

9 files changed

+794
-0
lines changed

9 files changed

+794
-0
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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+
# Quantile Function
22+
23+
> [Bradford][bradford-distribution] distribution [quantile function][quantile-function].
24+
25+
<section class="intro">
26+
27+
The [quantile function][quantile-function] for a [Bradford][bradford-distribution] random variable is
28+
29+
<!-- <equation class="equation" label="eq:bradford_quantile_function" align="center" raw="Q(p;c)=\frac{(1+c)^p - 1}{c}" alt="Quantile function for a Bradford distribution."> -->
30+
31+
```math
32+
Q(p;c)=\frac{(1+c)^p - 1}{c}
33+
```
34+
35+
<!-- <div class="equation" align="center" data-raw-text="Q(p;c)=\frac{(1+c)^p - 1}{c}" data-equation="eq:bradford_quantile_function">
36+
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@591cf9d5c3a0cd3c1ceec961e5c49d73a68374cb/lib/node_modules/@stdlib/stats/base/dists/bradford/quantile/docs/img/equation_bradford_quantile_function.svg" alt="Quantile function for a Bradford distribution.">
37+
<br>
38+
</div> -->
39+
40+
<!-- </equation> -->
41+
42+
for `0 <= p <= 1`, where `c` is the shape parameter.
43+
44+
</section>
45+
46+
<!-- /.intro -->
47+
48+
<section class="usage">
49+
50+
## Usage
51+
52+
```javascript
53+
var quantile = require( '@stdlib/stats/base/dists/bradford/quantile' );
54+
```
55+
56+
#### quantile( p, c )
57+
58+
Evaluates the [quantile function][quantile-function] for a [Bradford][bradford-distribution] distribution with shape parameter 'c' at a probability `p`.
59+
60+
```javascript
61+
var y = quantile( 0.1, 0.1 );
62+
// returns ~0.096
63+
64+
y = quantile( 0.5, 5.0 );
65+
// returns ~0.290
66+
67+
y = quantile( 1.0, 10.0 );
68+
// returns 1.0
69+
```
70+
71+
If provided a probability `p` outside the interval `[0,1]`, the function returns `NaN`.
72+
73+
```javascript
74+
var y = quantile( 2.0, 0.5 );
75+
// returns NaN
76+
77+
y = quantile( -1.0, 0.5 );
78+
// returns NaN
79+
```
80+
81+
If provided `NaN` as any argument, the function returns `NaN`.
82+
83+
```javascript
84+
var y = quantile( NaN, 1.0 );
85+
// returns NaN
86+
87+
y = quantile( 0.0, NaN );
88+
// returns NaN
89+
```
90+
91+
If provided `c <= 0`, the function returns `NaN`.
92+
93+
```javascript
94+
var y = quantile( 0.5, 0.0 );
95+
// returns NaN
96+
97+
y = quantile( 0.5, -10.0 );
98+
// returns NaN
99+
```
100+
101+
#### quantile.factory( c )
102+
103+
Returns a function for evaluating the [quantile function][quantile-function] for a [Bradford][bradford-distribution] distribution with shape parameter `c`.
104+
105+
```javascript
106+
var myquantile = quantile.factory( 5.0 );
107+
var y = myquantile( 0.4 );
108+
// returns ~0.210
109+
110+
y = myquantile( 0.8 );
111+
// returns ~0.639
112+
113+
y = myquantile( 1.0 );
114+
// returns 1.0
115+
```
116+
117+
</section>
118+
119+
<!-- /.usage -->
120+
121+
<section class="examples">
122+
123+
## Examples
124+
125+
<!-- eslint no-undef: "error" -->
126+
127+
```javascript
128+
var randu = require( '@stdlib/random/base/randu' );
129+
var quantile = require( '@stdlib/stats/base/dists/bradford/quantile' );
130+
131+
var p;
132+
var c;
133+
var y;
134+
var i;
135+
136+
for ( i = 0; i < 10; i++ ) {
137+
p = randu();
138+
c = ( randu()*10.0 );
139+
y = quantile( p, c );
140+
console.log( 'p: %d, c: %d, Q(p;c): %d', p.toFixed( 4 ), c.toFixed( 4 ), y.toFixed( 4 ) );
141+
}
142+
```
143+
144+
</section>
145+
146+
<!-- /.examples -->
147+
148+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
149+
150+
<section class="related">
151+
152+
</section>
153+
154+
<!-- /.related -->
155+
156+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
157+
158+
<section class="links">
159+
160+
[bradford-distribution]: https://en.wikipedia.org/wiki/Bradford%27s_law
161+
162+
[quantile-function]: https://en.wikipedia.org/wiki/Quantile_function
163+
164+
</section>
165+
166+
<!-- /.links -->
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var Float64Array = require( '@stdlib/array/float64' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var pkg = require( './../package.json' ).name;
28+
var quantile = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg, function benchmark( b ) {
34+
var len;
35+
var p;
36+
var c;
37+
var y;
38+
var i;
39+
40+
len = 100;
41+
p = new Float64Array( len );
42+
c = new Float64Array( len );
43+
for ( i = 0; i < len; i++ ) {
44+
p[ i ] = uniform( 0.0, 1.0 );
45+
c[ i ] = uniform( 0.1, 10.0 );
46+
}
47+
48+
b.tic();
49+
for ( i = 0; i < b.iterations; i++ ) {
50+
y = quantile( p[ i % len ], c[ i % len ] );
51+
if ( isnan( y ) ) {
52+
b.fail( 'should not return NaN' );
53+
}
54+
}
55+
b.toc();
56+
if ( isnan( y ) ) {
57+
b.fail( 'should not return NaN' );
58+
}
59+
b.pass( 'benchmark finished' );
60+
b.end();
61+
});
62+
63+
bench( pkg+':factory', function benchmark( b ) {
64+
var myquantile;
65+
var len;
66+
var p;
67+
var c;
68+
var y;
69+
var i;
70+
71+
c = 5.0;
72+
myquantile = quantile.factory( c );
73+
len = 100;
74+
p = new Float64Array( len );
75+
for ( i = 0; i < len; i++ ) {
76+
p[ i ] = uniform( 0.0, 1.0 );
77+
}
78+
79+
b.tic();
80+
for ( i = 0; i < b.iterations; i++ ) {
81+
y = myquantile( p[ i % len ] );
82+
if ( isnan( y ) ) {
83+
b.fail( 'should not return NaN' );
84+
}
85+
}
86+
b.toc();
87+
if ( isnan( y ) ) {
88+
b.fail( 'should not return NaN' );
89+
}
90+
b.pass( 'benchmark finished' );
91+
b.end();
92+
});
Lines changed: 42 additions & 0 deletions
Loading
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
{{alias}}( p, c )
3+
Evaluates the quantile function for a Bradford distribution with shape
4+
parameter 'c' at a probability `p`.
5+
6+
If `p < 0` or `p > 1`, the function returns `NaN`.
7+
8+
If `c <= 0`, the function returns `NaN`.
9+
10+
If provided `NaN` as any argument, the function returns `NaN`.
11+
12+
Parameters
13+
----------
14+
p: number
15+
Input probability.
16+
17+
c: number
18+
Shape parameter.
19+
20+
Returns
21+
-------
22+
out: number
23+
Evaluated quantile function.
24+
25+
Examples
26+
--------
27+
> var y = {{alias}}( 0.1, 0.1 )
28+
~0.096
29+
> y = {{alias}}( 0.5, 5.0 )
30+
~0.290
31+
> y = {{alias}}( 1.0, 10.0 )
32+
1.0
33+
34+
> y = {{alias}}( 0.5, 0.0 )
35+
NaN
36+
37+
> y = {{alias}}( 2.0, 0.5 )
38+
NaN
39+
> y = {{alias}}( -1.0, 0.5 )
40+
NaN
41+
42+
> y = {{alias}}( NaN, 1.0 )
43+
NaN
44+
> y = {{alias}}( 1.0, NaN )
45+
NaN
46+
47+
48+
{{alias}}.factory( c )
49+
Returns a function for evaluating the quantile function of a Bradford
50+
distribution with shape parameter `c`.
51+
52+
Parameters
53+
----------
54+
c: number
55+
Shape parameter.
56+
57+
Returns
58+
-------
59+
quantile: Function
60+
Quantile function.
61+
62+
Examples
63+
--------
64+
> var myquantile = {{alias}}.factory( 5.0 );
65+
> var y = myquantile( 0.4 )
66+
~0.210
67+
> y = myquantile( 0.8 )
68+
~0.639
69+
> y = myquantile( 1.0 )
70+
1.0
71+
72+
See Also
73+
--------
74+

0 commit comments

Comments
 (0)