Skip to content

Commit 380e8ea

Browse files
feat: add stats/base/dists/burr-type3/cdf
--- 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: na - 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 ---
1 parent b688f77 commit 380e8ea

File tree

17 files changed

+1379
-0
lines changed

17 files changed

+1379
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 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 cdf = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var alpha;
34+
var beta;
35+
var len;
36+
var x;
37+
var y;
38+
var i;
39+
40+
len = 100;
41+
x = uniform( len, 0.0, 10.0 );
42+
alpha = uniform( len, 0.1, 100.0 );
43+
beta = uniform( len, 0.1, 100.0 );
44+
45+
b.tic();
46+
for ( i = 0; i < b.iterations; i++ ) {
47+
y = cdf( x[ i % len ], alpha[ i % len ], beta[ i % len ] );
48+
if ( isnan( y ) ) {
49+
b.fail( 'should not return NaN' );
50+
}
51+
}
52+
b.toc();
53+
if ( isnan( y ) ) {
54+
b.fail( 'should not return NaN' );
55+
}
56+
b.pass( 'benchmark finished' );
57+
b.end();
58+
});
59+
60+
bench( pkg+':factory', function benchmark( b ) {
61+
var mycdf;
62+
var len;
63+
var x;
64+
var y;
65+
var i;
66+
67+
len = 100;
68+
x = uniform( len, 0.0, 10.0 );
69+
mycdf = cdf.factory( 5.0, 6.0 );
70+
71+
b.tic();
72+
for ( i = 0; i < b.iterations; i++ ) {
73+
y = mycdf( x[ i % len ] );
74+
if ( isnan( y ) ) {
75+
b.fail( 'should not return NaN' );
76+
}
77+
}
78+
b.toc();
79+
if ( isnan( y ) ) {
80+
b.fail( 'should not return NaN' );
81+
}
82+
b.pass( 'benchmark finished' );
83+
b.end();
84+
});
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env python
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+
"""Benchmark scipy.stats.burr.cdf."""
20+
21+
from __future__ import print_function
22+
import timeit
23+
24+
NAME = "burr:cdf"
25+
REPEATS = 3
26+
ITERATIONS = 1000
27+
28+
29+
def print_version():
30+
"""Print the TAP version."""
31+
print("TAP version 13")
32+
33+
34+
def print_summary(total, passing):
35+
"""Print the benchmark summary.
36+
37+
# Arguments
38+
39+
* `total`: total number of tests
40+
* `passing`: number of passing tests
41+
42+
"""
43+
print("#")
44+
print("1.." + str(total)) # TAP plan
45+
print("# total " + str(total))
46+
print("# pass " + str(passing))
47+
print("#")
48+
print("# ok")
49+
50+
51+
def print_results(elapsed):
52+
"""Print benchmark results.
53+
54+
# Arguments
55+
56+
* `elapsed`: elapsed time (in seconds)
57+
58+
# Examples
59+
60+
``` python
61+
python> print_results(0.131009101868)
62+
```
63+
"""
64+
rate = ITERATIONS / elapsed
65+
66+
print(" ---")
67+
print(" iterations: " + str(ITERATIONS))
68+
print(" elapsed: " + str(elapsed))
69+
print(" rate: " + str(rate))
70+
print(" ...")
71+
72+
73+
def benchmark():
74+
"""Run the benchmark and print benchmark results."""
75+
setup = "from scipy.stats import burr; from random import random;"
76+
stmt = "y = burr.cdf(random(), 100.56789, 55.54321)"
77+
78+
t = timeit.Timer(stmt, setup=setup)
79+
80+
print_version()
81+
82+
for i in range(REPEATS):
83+
print("# python::" + NAME)
84+
elapsed = t.timeit(number=ITERATIONS)
85+
print_results(elapsed)
86+
print("ok " + str(i+1) + " benchmark finished")
87+
88+
print_summary(REPEATS, REPEATS)
89+
90+
91+
def main():
92+
"""Run the benchmark."""
93+
benchmark()
94+
95+
96+
if __name__ == "__main__":
97+
main()
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
{{alias}}( x, α, β )
3+
Evaluates the cumulative distribution function (CDF) for a
4+
Burr (type III) distribution with first shape parameter
5+
`α` and second shape parameter `β` at a value `x`.
6+
7+
If provided `NaN` as any argument, the function returns `NaN`.
8+
9+
If `α <= 0` or `β <= 0` or `x <= 0`, the function returns `NaN`.
10+
11+
Parameters
12+
----------
13+
x: number
14+
Input value.
15+
16+
α: number
17+
First shape parameter.
18+
19+
β: number
20+
Second shape parameter.
21+
22+
Returns
23+
-------
24+
out: number
25+
Evaluated CDF.
26+
27+
Examples
28+
--------
29+
> var y = {{alias}}( 0.1, 1.0, 1.0 )
30+
~0.09
31+
> y = {{alias}}( 0.2, 2.0, 2.0 )
32+
~0.0015
33+
> y = {{alias}}( 0.8, 0.5, 0.5 )
34+
~0.69
35+
> y = {{alias}}( 0.3, 0.5, 0.5 )
36+
~0.59
37+
38+
> y = {{alias}}( -0.5, 4.0, 2.0 )
39+
NaN
40+
> y = {{alias}}( 2.0, -1.0, 0.5 )
41+
NaN
42+
> y = {{alias}}( 2.0, 0.5, -1.0 )
43+
NaN
44+
45+
> y = {{alias}}( NaN, 1.0, 1.0 )
46+
NaN
47+
> y = {{alias}}( 0.0, NaN, 1.0 )
48+
NaN
49+
> y = {{alias}}( 0.0, 1.0, NaN )
50+
NaN
51+
52+
53+
{{alias}}.factory( α, β )
54+
Returns a function for evaluating the cumulative distribution
55+
function (CDF) of a Burr (type III) distribution with
56+
first shape parameter `α` and second shape parameter `β`.
57+
58+
Parameters
59+
----------
60+
α: number
61+
First shape parameter.
62+
63+
β: number
64+
Second shape parameter.
65+
66+
Returns
67+
-------
68+
cdf: Function
69+
Cumulative distribution function (CDF).
70+
71+
Examples
72+
--------
73+
> var mycdf = {{alias}}.factory( 0.5, 0.5 );
74+
> var y = mycdf( 0.8 )
75+
~0.69
76+
> y = mycdf( 0.3 )
77+
~0.59
78+
79+
See Also
80+
--------
81+
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 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+
* Evaluates the cumulative distribution function (CDF) for a Burr (type III) distribution.
23+
*
24+
* @param x - input value
25+
* @returns evaluated CDF
26+
*/
27+
type Unary = ( x: number ) => number;
28+
29+
/**
30+
* Interface for the cumulative distribution function (CDF) of a Burr (type III) distribution.
31+
*/
32+
interface CDF {
33+
/**
34+
* Evaluates the cumulative distribution function (CDF) for a Burr (type III) distribution with first shape parameter `alpha` and second shape parameter `beta` at a value `x`.
35+
*
36+
* ## Notes
37+
*
38+
* - If `alpha <= 0` or `beta <= 0` or `x <= 0`, the function returns `NaN`.
39+
*
40+
* @param x - input value
41+
* @param alpha - first shape parameter
42+
* @param beta - second shape parameter
43+
* @returns evaluated CDF
44+
*
45+
* @example
46+
* var y = cdf( 0.1, 1.0, 1.0 );
47+
* // returns ~0.09
48+
*
49+
* @example
50+
* var y = cdf( 0.2, 2.0, 2.0 );
51+
* // returns ~0.0015
52+
*
53+
* @example
54+
* var y = cdf( 0.4, 4.0, 4.0 );
55+
* // returns ~3.88e-7
56+
*
57+
* @example
58+
* var y = cdf( 1.0, 0.1, 1.0 );
59+
* // returns 0.5
60+
*
61+
* @example
62+
* var y = cdf( 2.0, -1.0, 0.5 );
63+
* // returns NaN
64+
*
65+
* @example
66+
* var y = cdf( 2.0, 0.5, -1.0 );
67+
* // returns NaN
68+
*
69+
* @example
70+
* var y = cdf( NaN, 1.0, 1.0 );
71+
* // returns NaN
72+
*
73+
* @example
74+
* var y = cdf( 0.0, NaN, 1.0 );
75+
* // returns NaN
76+
*
77+
* @example
78+
* var y = cdf( 0.0, 1.0, NaN );
79+
* // returns NaN
80+
*/
81+
( x: number, alpha: number, beta: number ): number;
82+
83+
/**
84+
* Returns a function for evaluating the cumulative distribution function (CDF) for a Burr (type III) distribution with first shape parameter `alpha` and second shape parameter `beta`.
85+
*
86+
* @param alpha - first shape parameter
87+
* @param beta - second shape parameter
88+
* @returns CDF
89+
*
90+
* @example
91+
* var myCDF = cdf.factory( 0.5, 0.5 );
92+
*
93+
* var y = myCDF( 0.8 );
94+
* // returns ~0.69
95+
*
96+
* y = myCDF( 0.3 );
97+
* // returns ~0.59
98+
*/
99+
factory( alpha: number, beta: number ): Unary;
100+
}
101+
102+
/**
103+
* Burr (type III) distribution cumulative distribution function (CDF).
104+
*
105+
* @param x - input value
106+
* @param alpha - first shape parameter
107+
* @param beta - second shape parameter
108+
* @returns evaluated CDF
109+
*
110+
* @example
111+
* var y = cdf( 0.5, 1.0, 1.0 );
112+
* // returns ~0.33
113+
*
114+
* y = cdf( 0.5, 2.0, 4.0 );
115+
* // returns ~0.0015
116+
*
117+
* var myCDF = cdf.factory( 0.5, 0.5 );
118+
*
119+
* y = myCDF( 0.8 );
120+
* // returns ~0.69
121+
*
122+
* y = myCDF( 0.3 );
123+
* // returns ~0.59
124+
*/
125+
declare var cdf: CDF;
126+
127+
128+
// EXPORTS //
129+
130+
export = cdf;

0 commit comments

Comments
 (0)