Skip to content

Commit b2b2c84

Browse files
anandkaranubcPlaneshifterstdlib-bot
authored
feat: add stats/base/dists/bradford/quantile
PR-URL: #5295 Co-authored-by: Philipp Burckhardt <[email protected]> Co-authored-by: stdlib-bot <[email protected]> Signed-off-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 1ebcfd6 commit b2b2c84

File tree

18 files changed

+1398
-0
lines changed

18 files changed

+1398
-0
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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 `NaN` as any argument, the function returns `NaN`.
72+
73+
```javascript
74+
var y = quantile( NaN, 1.0 );
75+
// returns NaN
76+
77+
y = quantile( 0.0, NaN );
78+
// returns NaN
79+
```
80+
81+
If provided a probability `p` outside the interval `[0,1]`, the function returns `NaN`.
82+
83+
```javascript
84+
var y = quantile( 2.0, 0.5 );
85+
// returns NaN
86+
87+
y = quantile( -1.0, 0.5 );
88+
// returns NaN
89+
```
90+
91+
If provided a shape parameter `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 uniform = require( '@stdlib/random/array/uniform' );
129+
var quantile = require( '@stdlib/stats/base/dists/bradford/quantile' );
130+
131+
var p = uniform( 10, 0.0, 1.0 );
132+
var c = uniform( 10, 0.1, 10.0 );
133+
134+
var y;
135+
var i;
136+
for ( i = 0; i < p.length; i++ ) {
137+
y = quantile( p[ i ], c[ i ] );
138+
console.log( 'p: %d, c: %d, Q(p;c): %d', p[ i ].toFixed( 4 ), c[ i ].toFixed( 4 ), y.toFixed( 4 ) );
139+
}
140+
```
141+
142+
</section>
143+
144+
<!-- /.examples -->
145+
146+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
147+
148+
<section class="related">
149+
150+
</section>
151+
152+
<!-- /.related -->
153+
154+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
155+
156+
<section class="links">
157+
158+
[bradford-distribution]: https://en.wikipedia.org/wiki/Bradford%27s_law
159+
160+
[quantile-function]: https://en.wikipedia.org/wiki/Quantile_function
161+
162+
</section>
163+
164+
<!-- /.links -->
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pkg = require( './../package.json' ).name;
27+
var quantile = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var p;
34+
var c;
35+
var y;
36+
var i;
37+
38+
p = uniform( 100, 0.0, 1.0 );
39+
c = uniform( 100, 0.1, 10.0 );
40+
41+
b.tic();
42+
for ( i = 0; i < b.iterations; i++ ) {
43+
y = quantile( p[ i % p.length ], c[ i % c.length ] );
44+
if ( isnan( y ) ) {
45+
b.fail( 'should not return NaN' );
46+
}
47+
}
48+
b.toc();
49+
if ( isnan( y ) ) {
50+
b.fail( 'should not return NaN' );
51+
}
52+
b.pass( 'benchmark finished' );
53+
b.end();
54+
});
55+
56+
bench( pkg+':factory', function benchmark( b ) {
57+
var myquantile;
58+
var p;
59+
var y;
60+
var i;
61+
62+
p = uniform( 100, 0.0, 1.0 );
63+
myquantile = quantile.factory( 5.0 );
64+
65+
b.tic();
66+
for ( i = 0; i < b.iterations; i++ ) {
67+
y = myquantile( p[ i % p.length ] );
68+
if ( isnan( y ) ) {
69+
b.fail( 'should not return NaN' );
70+
}
71+
}
72+
b.toc();
73+
if ( isnan( y ) ) {
74+
b.fail( 'should not return NaN' );
75+
}
76+
b.pass( 'benchmark finished' );
77+
b.end();
78+
});
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)