Skip to content

Commit f8aa307

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 cef2d06 commit f8aa307

File tree

9 files changed

+751
-0
lines changed

9 files changed

+751
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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+
# Probability Density Function
22+
23+
> [Bradford][bradford-distribution] distribution [probability density function][pdf] (PDF).
24+
25+
<section class="intro">
26+
27+
The [probability density function][pdf] (PDF) for a [bradford][bradford-distribution] random variable is
28+
29+
<!-- <equation class="equation" label="eq:bradford_pdf" align="center" raw="f(x;c)=\frac{c}{(\ln(1+c)) (1 + cx)}" alt="Probability density function (PDF) for a bradford distribution."> -->
30+
31+
```math
32+
f(x;c)=\frac{c}{(\ln(1+c)) (1 + cx)}
33+
```
34+
35+
<!-- <div class="equation" align="center" data-raw-text="f(x;c)=\frac{c}{(\ln(1+c)) (1 + cx)}" data-equation="eq:bradford_pdf">
36+
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/bradford/pdf/docs/img/equation_bradford_pdf.svg" alt="Probability density function (PDF) for a bradford distribution.">
37+
<br>
38+
</div> -->
39+
40+
<!-- </equation> -->
41+
42+
where `c` is the shape parameter of the distribution. The parameters must satisfy `0 <= x <= 1` and `c > 0`.
43+
44+
</section>
45+
46+
<!-- /.intro -->
47+
48+
<section class="usage">
49+
50+
## Usage
51+
52+
```javascript
53+
var pdf = require( '@stdlib/stats/base/dists/bradford/pdf' );
54+
```
55+
56+
#### pdf( x, c )
57+
58+
Evaluates the [probability density function][pdf] (PDF) for a [bradford][bradford-distribution] distribution with shape parameter `c` at a value `x`.
59+
60+
```javascript
61+
var y = pdf( 0.1, 0.1 );
62+
// returns ~1.039
63+
64+
y = pdf( 0.5, 5.0 );
65+
// returns ~0.797
66+
67+
y = pdf( 1.0, 10.0 );
68+
// returns ~0.379
69+
```
70+
71+
If provided `NaN` as any argument, the function returns `NaN`.
72+
73+
```javascript
74+
var y = pdf( NaN, 1.0 );
75+
// returns NaN
76+
77+
y = pdf( 0.0, NaN );
78+
// returns NaN
79+
```
80+
81+
If provided an input value `x` outside of the interval `[0,1]`, the function returns `NaN`.
82+
83+
```javascript
84+
var y = pdf( 2.0, 1.0 );
85+
// returns NaN
86+
87+
y = pdf( -0.5, 1.0 );
88+
// returns NaN
89+
```
90+
91+
If provided a shape parameter `c <= 0`, the function returns `NaN`.
92+
93+
```javascript
94+
var y = pdf( 0.0, 0.0 );
95+
// returns NaN
96+
97+
y = pdf( 0.5, -1.0 );
98+
// returns NaN
99+
```
100+
101+
#### pdf.factory( c )
102+
103+
Returns a `function` for evaluating the [PDF][pdf] of a [bradford][bradford-distribution] distribution with shape parameter `c`.
104+
105+
```javascript
106+
var myPDF = pdf.factory( 5.0 );
107+
var y = myPDF( 0.5 );
108+
// returns ~0.797
109+
110+
y = myPDF( 1.0 );
111+
// returns ~0.465
112+
```
113+
114+
</section>
115+
116+
<!-- /.usage -->
117+
118+
<section class="examples">
119+
120+
## Examples
121+
122+
<!-- eslint no-undef: "error" -->
123+
124+
```javascript
125+
var randu = require( '@stdlib/random/base/randu' );
126+
var pdf = require( '@stdlib/stats/base/dists/bradford/pdf' );
127+
128+
var x;
129+
var c;
130+
var y;
131+
var i;
132+
133+
for ( i = 0; i < 25; i++ ) {
134+
x = randu();
135+
c = ( randu()*10.0 );
136+
y = pdf( x, c );
137+
console.log( 'x: %d, c: %d, f(x;c): %d', x.toFixed( 4 ), c.toFixed( 4 ), y.toFixed( 4 ) );
138+
}
139+
```
140+
141+
</section>
142+
143+
<!-- /.examples -->
144+
145+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
146+
147+
<section class="related">
148+
149+
</section>
150+
151+
<!-- /.related -->
152+
153+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
154+
155+
<section class="links">
156+
157+
[pdf]: https://en.wikipedia.org/wiki/Probability_density_function
158+
159+
[bradford-distribution]: https://en.wikipedia.org/wiki/Bradford%27s_law
160+
161+
</section>
162+
163+
<!-- /.links -->
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 Float64Array = require( '@stdlib/array/float64' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
26+
var EPS = require( '@stdlib/constants/float64/eps' );
27+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
28+
var pkg = require( './../package.json' ).name;
29+
var pdf = require( './../lib' );
30+
31+
32+
// MAIN //
33+
34+
bench( pkg, function benchmark( b ) {
35+
var len;
36+
var x;
37+
var c;
38+
var y;
39+
var i;
40+
41+
len = 100;
42+
x = new Float64Array( len );
43+
c = new Float64Array( len );
44+
for ( i = 0; i < len; i++ ) {
45+
x[ i ] = uniform( 0.0, 1.0 );
46+
c[ i ] = uniform( EPS, 10.0 );
47+
}
48+
49+
b.tic();
50+
for ( i = 0; i < b.iterations; i++ ) {
51+
y = pdf( x[ i % len ], c[ i % len ] );
52+
if ( isnan( y ) ) {
53+
b.fail( 'should not return NaN' );
54+
}
55+
}
56+
b.toc();
57+
if ( isnan( y ) ) {
58+
b.fail( 'should not return NaN' );
59+
}
60+
b.pass( 'benchmark finished' );
61+
b.end();
62+
});
Lines changed: 50 additions & 0 deletions
Loading
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
{{alias}}( x, c )
3+
Evaluates the probability density function (PDF) for a bradford distribution
4+
with shape parameter `c` at a value `x`.
5+
6+
If provided `NaN` as any argument, the function returns `NaN`.
7+
8+
If `x < 0` or `x > 1`, the function returns `NaN`.
9+
10+
If provided `c <= 0`, the function returns `NaN`.
11+
12+
Parameters
13+
----------
14+
x: number
15+
Input value.
16+
17+
c: number
18+
Shape parameter.
19+
20+
Returns
21+
-------
22+
out: number
23+
Evaluated PDF.
24+
25+
Examples
26+
--------
27+
> var y = {{alias}}( 0.1, 0.1 )
28+
~1.039
29+
> y = {{alias}}( 0.5, 5.0 )
30+
~0.797
31+
> y = {{alias}}( 1.0, 10.0 )
32+
~0.379
33+
> y = {{alias}}( 0.5, 0.0 )
34+
NaN
35+
> y = {{alias}}( 2.0, 0.5 )
36+
NaN
37+
> y = {{alias}}( -1.0, 0.5 )
38+
NaN
39+
> y = {{alias}}( NaN, 1.0 )
40+
NaN
41+
> y = {{alias}}( 1.0, NaN )
42+
NaN
43+
44+
45+
{{alias}}.factory( c )
46+
Returns a function for evaluating the probability density function (PDF) of
47+
a bradford distribution with shape parameter `c`.
48+
49+
Parameters
50+
----------
51+
c: number
52+
Shape parameter.
53+
54+
Returns
55+
-------
56+
pdf: Function
57+
Probability density function (PDF).
58+
59+
Examples
60+
--------
61+
> var myPDF = {{alias}}.factory( 5.0 );
62+
> var y = myPDF( 0.5 )
63+
~0.797
64+
> y = myPDF( 1.0 )
65+
~0.465
66+
67+
See Also
68+
--------
69+

0 commit comments

Comments
 (0)