Skip to content
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

feat: add stats/base/dists/burr-type3/cdf #5916

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

{{alias}}( x, α, β )
Evaluates the cumulative distribution function (CDF) for a
Burr (type III) distribution with first shape parameter
`α` and second shape parameter `β` at a value `x`.

If provided `NaN` as any argument, the function returns `NaN`.

If `α <= 0` or `β <= 0` or `x <= 0`, the function returns `NaN`.

Parameters
----------
x: number
Input value.

α: number
First shape parameter.

β: number
Second shape parameter.

Returns
-------
out: number
Evaluated CDF.

Examples
--------
> var y = {{alias}}( 0.1, 1.0, 1.0 )
~0.09
> y = {{alias}}( 0.2, 2.0, 2.0 )
~0.0015
> y = {{alias}}( 0.8, 0.5, 0.5 )
~0.69
> y = {{alias}}( 0.3, 0.5, 0.5 )
~0.59

> y = {{alias}}( -0.5, 4.0, 2.0 )
NaN
> y = {{alias}}( 2.0, -1.0, 0.5 )
NaN
> y = {{alias}}( 2.0, 0.5, -1.0 )
NaN

> y = {{alias}}( NaN, 1.0, 1.0 )
NaN
> y = {{alias}}( 0.0, NaN, 1.0 )
NaN
> y = {{alias}}( 0.0, 1.0, NaN )
NaN


{{alias}}.factory( α, β )
Returns a function for evaluating the cumulative distribution
function (CDF) of a Burr (type III) distribution with
first shape parameter `α` and second shape parameter `β`.

Parameters
----------
α: number
First shape parameter.

β: number
Second shape parameter.

Returns
-------
cdf: Function
Cumulative distribution function (CDF).

Examples
--------
> var mycdf = {{alias}}.factory( 0.5, 0.5 );
> var y = mycdf( 0.8 )
~0.69
> y = mycdf( 0.3 )
~0.59

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* @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.
*/

// TypeScript Version: 4.1

/**
* Evaluates the cumulative distribution function (CDF) for a Burr (type III) distribution.
*
* @param x - input value
* @returns evaluated CDF
*/
type Unary = ( x: number ) => number;

/**
* Interface for the cumulative distribution function (CDF) of a Burr (type III) distribution.
*/
interface CDF {
/**
* 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`.
*
* ## Notes
*
* - If `alpha <= 0` or `beta <= 0` or `x <= 0`, the function returns `NaN`.
*
* @param x - input value
* @param alpha - first shape parameter
* @param beta - second shape parameter
* @returns evaluated CDF
*
* @example
* var y = cdf( 0.1, 1.0, 1.0 );
* // returns ~0.09
*
* @example
* var y = cdf( 0.2, 2.0, 2.0 );
* // returns ~0.0015
*
* @example
* var y = cdf( 0.4, 4.0, 4.0 );
* // returns ~3.88e-7
*
* @example
* var y = cdf( 1.0, 0.1, 1.0 );
* // returns 0.5
*
* @example
* var y = cdf( 2.0, -1.0, 0.5 );
* // returns NaN
*
* @example
* var y = cdf( 2.0, 0.5, -1.0 );
* // returns NaN
*
* @example
* var y = cdf( NaN, 1.0, 1.0 );
* // returns NaN
*
* @example
* var y = cdf( 0.0, NaN, 1.0 );
* // returns NaN
*
* @example
* var y = cdf( 0.0, 1.0, NaN );
* // returns NaN
*/
( x: number, alpha: number, beta: number ): number;

/**
* 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`.
*
* @param alpha - first shape parameter
* @param beta - second shape parameter
* @returns CDF
*
* @example
* var myCDF = cdf.factory( 0.5, 0.5 );
*
* var y = myCDF( 0.8 );
* // returns ~0.69
*
* y = myCDF( 0.3 );
* // returns ~0.59
*/
factory( alpha: number, beta: number ): Unary;
}

/**
* Burr (type III) distribution cumulative distribution function (CDF).
*
* @param x - input value
* @param alpha - first shape parameter
* @param beta - second shape parameter
* @returns evaluated CDF
*
* @example
* var y = cdf( 0.5, 1.0, 1.0 );
* // returns ~0.33
*
* y = cdf( 0.5, 2.0, 4.0 );
* // returns ~0.0015
*
* var myCDF = cdf.factory( 0.5, 0.5 );
*
* y = myCDF( 0.8 );
* // returns ~0.69
*
* y = myCDF( 0.3 );
* // returns ~0.59
*/
declare var cdf: CDF;


// EXPORTS //

export = cdf;
Loading