Skip to content

Commit 891d515

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: na - 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 a8da41d commit 891d515

File tree

8 files changed

+493
-0
lines changed

8 files changed

+493
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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+
# Mean
22+
23+
> [Bradford][bradford-distribution] distribution [median][median].
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
The [median][median] for a [Bradford][bradford-distribution] random variable is
30+
31+
<!-- <equation class="equation" label="eq:bradford_median" align="center" raw="\mathop{\mathrm{Median}}\left( X \right) = \frac{(1 + c)^{0.5} - 1}{c}" alt="Median for a Bradford distribution."> -->
32+
33+
```math
34+
\mathop{\mathrm{Median}}\left( X \right) = \frac{(1 + c)^{0.5} - 1}{c}
35+
```
36+
37+
<!-- <div class="equation" align="center" data-raw-text="\mathop{\mathrm{Median}}\left( X \right) = \frac{(1 + c)^{0.5} - 1}{c}" data-equation="eq:bradford_median">
38+
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@591cf9d5c3a0cd3c1ceec961e5c49d73a68374cb/lib/node_modules/@stdlib/stats/base/dists/bradford/median/docs/img/equation_bradford_median.svg" alt="Median for a Bradford distribution.">
39+
<br>
40+
</div> -->
41+
42+
<!-- </equation> -->
43+
44+
where `c` is the shape parameter.
45+
46+
</section>
47+
48+
<!-- /.intro -->
49+
50+
<!-- Package usage documentation. -->
51+
52+
<section class="usage">
53+
54+
## Usage
55+
56+
```javascript
57+
var median = require( '@stdlib/stats/base/dists/bradford/median' );
58+
```
59+
60+
#### median( c )
61+
62+
Returns the [median][median] of a [Bradford][bradford-distribution] distribution with shape parameter `c`.
63+
64+
```javascript
65+
var v = median( 0.1 );
66+
// returns ~0.488
67+
68+
v = median( 10.0 );
69+
// returns ~0.232
70+
```
71+
72+
If `c <= 0`, the function returns `NaN`.
73+
74+
```javascript
75+
var v = median( NaN );
76+
// returns NaN
77+
78+
v = median( 0.0 );
79+
// returns NaN
80+
81+
v = median( -1.5 );
82+
// returns NaN
83+
```
84+
85+
</section>
86+
87+
<!-- /.usage -->
88+
89+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
90+
91+
<section class="notes">
92+
93+
</section>
94+
95+
<!-- /.notes -->
96+
97+
<!-- Package usage examples. -->
98+
99+
<section class="examples">
100+
101+
## Examples
102+
103+
<!-- eslint no-undef: "error" -->
104+
105+
```javascript
106+
var randu = require( '@stdlib/random/base/randu' );
107+
var median = require( '@stdlib/stats/base/dists/bradford/median' );
108+
109+
var c;
110+
var v;
111+
var i;
112+
113+
for ( i = 0; i < 10; i++ ) {
114+
c = ( randu()*10.0 );
115+
v = median( c );
116+
console.log( 'c: %d, Median(X;c): %d', c.toFixed( 4 ), v.toFixed( 4 ) );
117+
}
118+
```
119+
120+
</section>
121+
122+
<!-- /.examples -->
123+
124+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
125+
126+
<section class="related">
127+
128+
</section>
129+
130+
<!-- /.related -->
131+
132+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
133+
134+
<section class="links">
135+
136+
[bradford-distribution]: https://en.wikipedia.org/wiki/Bradford%27s_law
137+
138+
[median]: https://en.wikipedia.org/wiki/Median
139+
140+
</section>
141+
142+
<!-- /.links -->
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 median = require( './../lib' );
30+
31+
32+
// MAIN //
33+
34+
bench( pkg, function benchmark( b ) {
35+
var len;
36+
var c;
37+
var y;
38+
var i;
39+
40+
len = 100;
41+
c = new Float64Array( len );
42+
for ( i = 0; i < len; i++ ) {
43+
c[ i ] = uniform( EPS, 10.0 );
44+
}
45+
46+
b.tic();
47+
for ( i = 0; i < b.iterations; i++ ) {
48+
y = median( c[ i % len ] );
49+
if ( isnan( y ) ) {
50+
b.fail( 'should not return NaN' );
51+
}
52+
}
53+
b.toc();
54+
if ( isnan( y ) ) {
55+
b.fail( 'should not return NaN' );
56+
}
57+
b.pass( 'benchmark finished' );
58+
b.end();
59+
});
Lines changed: 58 additions & 0 deletions
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
{{alias}}( c )
3+
Returns the median of a Bradford distribution with shape
4+
parameter `c`.
5+
6+
If `c <= 0`, the function returns `NaN`.
7+
8+
Parameters
9+
----------
10+
c: number
11+
Shape parameter.
12+
13+
Returns
14+
-------
15+
out: number
16+
Median.
17+
18+
Examples
19+
--------
20+
> var v = {{alias}}( 0.1 )
21+
~0.488
22+
> v = {{alias}}( 0.5 )
23+
~0.449
24+
> v = {{alias}}( 10.0 )
25+
~0.232
26+
27+
See Also
28+
--------
29+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Returns the median of a Bradford distribution.
23+
*
24+
* ## Notes
25+
*
26+
* - If `c <= 0`, the function returns `NaN`.
27+
*
28+
* @param c - shape parameter
29+
* @returns median
30+
*
31+
* @example
32+
* var v = median( 0.1 );
33+
* // returns ~0.488
34+
*
35+
* @example
36+
* var v = median( 0.5 );
37+
* // returns ~0.449
38+
*
39+
* @example
40+
* var v = median( 10.0 );
41+
* // returns ~0.232
42+
*
43+
* @example
44+
* var v = median( 0.0 );
45+
* // returns NaN
46+
*
47+
* @example
48+
* var v = median( -1.0 );
49+
* // returns NaN
50+
*
51+
* @example
52+
* var v = median( NaN );
53+
* // returns NaN
54+
*/
55+
declare function median( c: number ): number;
56+
57+
58+
// EXPORTS //
59+
60+
export = median;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
import median = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
median( 0.3 ); // $ExpectType number
27+
}
28+
29+
// The compiler throws an error if the function is provided a value other than a number...
30+
{
31+
median( true ); // $ExpectError
32+
median( false ); // $ExpectError
33+
median( null ); // $ExpectError
34+
median( undefined ); // $ExpectError
35+
median( '5' ); // $ExpectError
36+
median( [] ); // $ExpectError
37+
median( {} ); // $ExpectError
38+
median( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The compiler throws an error if the function is provided insufficient arguments...
42+
{
43+
median(); // $ExpectError
44+
}

0 commit comments

Comments
 (0)