-
-
Notifications
You must be signed in to change notification settings - Fork 813
feat: add stats/base/dists/burr-type3/cdf
#5916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
vivekmaurya001
wants to merge
8
commits into
stdlib-js:develop
Choose a base branch
from
vivekmaurya001:burr-type3/cdf
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,562
−0
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
380e8ea
feat: add stats/base/dists/burr-type3/cdf
vivekmaurya001 aea9bc8
chore: update copyright years
stdlib-bot bd1e67c
feat: add stats/base/dists/burr-type3/cdf
vivekmaurya001 0d7f2e6
Merge branch 'burr-type3/cdf' of https://github.com/vivekmaurya001/st…
vivekmaurya001 6fce82f
feat: add stats/base/dists/burr-type3/cdf
vivekmaurya001 d99a756
Merge branch 'stdlib-js:develop' into burr-type3/cdf
vivekmaurya001 43fcdf5
docs: use available width of 80 chars
Planeshifter 4e0fb52
Merge branch 'stdlib-js:develop' into burr-type3/cdf
vivekmaurya001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
183 changes: 183 additions & 0 deletions
183
lib/node_modules/@stdlib/stats/base/dists/burr-type3/cdf/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
<!-- | ||
|
||
@license Apache-2.0 | ||
|
||
Copyright (c) 2025 The Stdlib Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
--> | ||
|
||
# Cumulative Distribution Function | ||
|
||
> [Burr (type III)][burr-distribution] distribution [cumulative distribution function][cdf]. | ||
|
||
<section class="intro"> | ||
|
||
The [cumulative distribution function][cdf] for a [Burr (type III)][burr-distribution] random variable is | ||
|
||
<!-- <equation class="equation" label="eq:burr-type3_cdf" align="center" | ||
raw="F(x; c, d) = (1 + x^{-c})^{-d}" | ||
alt="Cumulative distribution function for a Burr (Type III) distribution."> --> | ||
|
||
```math | ||
F(x; alpha, beta) = (1 + x^{-alpha})^{-beta} | ||
``` | ||
|
||
<!-- <div class="equation" align="center" data-raw-text="F(x;c,d) = (1 + x^{-c})^{-d}" data-equation="eq:burr-type3_cdf"> | ||
<img src="https://quicklatex.com/cache3/1e/ql_96e6c56a3c01ce5db3f378b28ee9511e_l3.png" alt="Cumulative distribution function for a Burr (Type III) distribution."> | ||
<br> | ||
</div> --> | ||
|
||
<!-- </equation> --> | ||
|
||
where `alpha > 0` is the first shape parameter and `beta > 0` is the second shape parameter. | ||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var cdf = require( '@stdlib/stats/base/dists/burr-type3/cdf' ); | ||
``` | ||
|
||
#### cdf( x, alpha, beta ) | ||
|
||
Evaluates the [cumulative distribution function][cdf] (CDF) for a [Burr (type III)][burr-distribution] distribution with parameters `alpha` (first shape parameter) and `beta` (second shape parameter). | ||
|
||
```javascript | ||
var y = cdf( 0.1, 1.0, 1.0 ); | ||
// returns ~0.09 | ||
|
||
y = cdf( 0.2, 2.0, 2.0 ); | ||
// returns ~0.0015 | ||
|
||
y = cdf( 0.4, 4.0, 4.0 ); | ||
// returns ~3.88e-7 | ||
|
||
y = cdf( 1.0, 0.1, 1.0 ); | ||
// returns 0.5 | ||
|
||
y = cdf( 0.3, 0.5, 0.5 ); | ||
// returns ~0.59 | ||
|
||
y = cdf( 0.5, 1.0, 1.0 ); | ||
// returns ~0.33 | ||
|
||
y = cdf( 0.5, 2.0, 4.0 ); | ||
// returns ~0.0016 | ||
|
||
y = cdf( 0.8, 0.5, 0.5 ); | ||
// returns ~0.69 | ||
``` | ||
|
||
If provided `NaN` as any argument, the function returns `NaN`. | ||
|
||
```javascript | ||
var y = cdf( NaN, 1.0, 1.0 ); | ||
// returns NaN | ||
|
||
y = cdf( 0.0, NaN, 1.0 ); | ||
// returns NaN | ||
|
||
y = cdf( 0.0, 1.0, NaN ); | ||
// returns NaN | ||
``` | ||
|
||
If provided `alpha <= 0`, the function returns `NaN`. | ||
|
||
```javascript | ||
var y = cdf( 2.0, -1.0, 0.5 ); | ||
// returns NaN | ||
|
||
y = cdf( 2.0, 0.0, 0.5 ); | ||
// returns NaN | ||
``` | ||
|
||
If provided `beta <= 0`, the function returns `NaN`. | ||
|
||
```javascript | ||
var y = cdf( 2.0, 0.5, -1.0 ); | ||
// returns NaN | ||
|
||
y = cdf( 2.0, 0.5, 0.0 ); | ||
// returns NaN | ||
``` | ||
|
||
#### cdf.factory( alpha, beta ) | ||
|
||
Returns a function for evaluating the [cumulative distribution function][cdf] for a [Burr (type III)][burr-distribution] distribution with parameters `alpha` (first shape parameter) and `beta` (second shape parameter). | ||
|
||
```javascript | ||
var mycdf = cdf.factory( 0.5, 0.5 ); | ||
|
||
var y = mycdf( 0.8 ); | ||
// returns ~0.69 | ||
|
||
y = mycdf( 0.3 ); | ||
// returns ~0.59 | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var cdf = require( '@stdlib/stats/base/dists/burr-type3/cdf' ); | ||
var linspace = require( '@stdlib/array/linspace' ); | ||
|
||
var alpha = linspace( 1, 10.0, 10 ); | ||
var beta = linspace( 1, 10.0, 10 ); | ||
var x = linspace( 0.1, 1.0, 10 ); | ||
var y; | ||
var i; | ||
|
||
for ( i = 0; i < 10; i++ ) { | ||
y = cdf( x[ i ], alpha[ i ], beta[ i ] ); | ||
console.log( 'x: %d, α: %d, β: %d, F(x;α,β): %d', x[i].toFixed( 4 ), alpha[i].toFixed( 4 ), beta[i].toFixed( 4 ), y.toFixed( 4 ) ); | ||
} | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
||
<section class="related"> | ||
|
||
</section> | ||
|
||
<!-- /.related --> | ||
|
||
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="links"> | ||
|
||
[burr-distribution]: https://en.wikipedia.org/wiki/Burr_distribution | ||
|
||
[cdf]: https://en.wikipedia.org/wiki/Cumulative_distribution_function | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
84 changes: 84 additions & 0 deletions
84
lib/node_modules/@stdlib/stats/base/dists/burr-type3/cdf/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2025 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var uniform = require( '@stdlib/random/array/uniform' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var pkg = require( './../package.json' ).name; | ||
var cdf = require( './../lib' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var alpha; | ||
var beta; | ||
var len; | ||
var x; | ||
var y; | ||
var i; | ||
|
||
len = 100; | ||
x = uniform( len, 0.0, 10.0 ); | ||
alpha = uniform( len, 0.1, 100.0 ); | ||
beta = uniform( len, 0.1, 100.0 ); | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
y = cdf( x[ i % len ], alpha[ i % len ], beta[ i % len ] ); | ||
if ( isnan( y ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( y ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); | ||
|
||
bench( pkg+':factory', function benchmark( b ) { | ||
var mycdf; | ||
var len; | ||
var x; | ||
var y; | ||
var i; | ||
|
||
len = 100; | ||
x = uniform( len, 0.0, 10.0 ); | ||
mycdf = cdf.factory( 5.0, 6.0 ); | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
y = mycdf( x[ i % len ] ); | ||
if ( isnan( y ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( y ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); |
97 changes: 97 additions & 0 deletions
97
lib/node_modules/@stdlib/stats/base/dists/burr-type3/cdf/benchmark/python/benchmark.scipy.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/usr/bin/env python | ||
# | ||
# @license Apache-2.0 | ||
# | ||
# Copyright (c) 2025 The Stdlib Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Benchmark scipy.stats.burr.cdf.""" | ||
|
||
from __future__ import print_function | ||
import timeit | ||
|
||
NAME = "burr:cdf" | ||
REPEATS = 3 | ||
ITERATIONS = 1000 | ||
|
||
|
||
def print_version(): | ||
"""Print the TAP version.""" | ||
print("TAP version 13") | ||
|
||
|
||
def print_summary(total, passing): | ||
"""Print the benchmark summary. | ||
|
||
# Arguments | ||
|
||
* `total`: total number of tests | ||
* `passing`: number of passing tests | ||
|
||
""" | ||
print("#") | ||
print("1.." + str(total)) # TAP plan | ||
print("# total " + str(total)) | ||
print("# pass " + str(passing)) | ||
print("#") | ||
print("# ok") | ||
|
||
|
||
def print_results(elapsed): | ||
"""Print benchmark results. | ||
|
||
# Arguments | ||
|
||
* `elapsed`: elapsed time (in seconds) | ||
|
||
# Examples | ||
|
||
``` python | ||
python> print_results(0.131009101868) | ||
``` | ||
""" | ||
rate = ITERATIONS / elapsed | ||
|
||
print(" ---") | ||
print(" iterations: " + str(ITERATIONS)) | ||
print(" elapsed: " + str(elapsed)) | ||
print(" rate: " + str(rate)) | ||
print(" ...") | ||
|
||
|
||
def benchmark(): | ||
"""Run the benchmark and print benchmark results.""" | ||
setup = "from scipy.stats import burr; from random import random;" | ||
stmt = "y = burr.cdf(random(), 100.56789, 55.54321)" | ||
|
||
t = timeit.Timer(stmt, setup=setup) | ||
|
||
print_version() | ||
|
||
for i in range(REPEATS): | ||
print("# python::" + NAME) | ||
elapsed = t.timeit(number=ITERATIONS) | ||
print_results(elapsed) | ||
print("ok " + str(i+1) + " benchmark finished") | ||
|
||
print_summary(REPEATS, REPEATS) | ||
|
||
|
||
def main(): | ||
"""Run the benchmark.""" | ||
benchmark() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove this as it will be auto-generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ook