Skip to content

feat: add stats/base/dists/bradford/cdf #5282

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

Merged
merged 8 commits into from
Feb 22, 2025
Merged
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
157 changes: 157 additions & 0 deletions lib/node_modules/@stdlib/stats/base/dists/bradford/cdf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<!--

@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

> [Bradford][bradford-distribution] distribution [cumulative distribution function][cdf] (CDF).

<section class="intro">

The [cumulative distribution function][cdf] (CDF) for a [Bradford][bradford-distribution] random variable is

<!-- <equation class="equation" label="eq:bradford_cdf" align="center" raw="F(x;c)=\frac{\ln(1+cx)}{\ln(1+c)}" alt="Cumulative distribution function (CDF) for a Bradford distribution."> -->

```math
F(x;c)=\frac{\ln(1+cx)}{\ln(1+c)}
```

<!-- <div class="equation" align="center" data-raw-text="F(x;c)=\frac{\ln(1+cx)}{\ln(1+c)}" data-equation="eq:bradford_cdf">
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/bradford/cdf/docs/img/equation_bradford_cdf.svg" alt="Cumulative distribution function (CDF) for a Bradford distribution.">
<br>
</div> -->

<!-- </equation> -->

where `c > 0` is the shape parameter of the distribution.

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var cdf = require( '@stdlib/stats/base/dists/bradford/cdf' );
```

#### cdf( x, c )

Evaluates the [cumulative distribution function][cdf] (CDF) for a [Bradford][bradford-distribution] distribution with shape parameter `c` at a value `x`.

```javascript
var y = cdf( 0.1, 0.1 );
// returns ~0.104

y = cdf( 0.5, 5.0 );
// returns ~0.699

y = cdf( 1.0, 10.0 );
// returns 1.0

y = cdf( -0.5, 1.0 );
// returns 0.0

y = cdf( 2.0, 1.0 );
// returns 1.0
```

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

```javascript
var y = cdf( NaN, 1.0 );
// returns NaN

y = cdf( 0.0, NaN );
// returns NaN
```

If provided a shape parameter `c <= 0`, the function returns `NaN`.

```javascript
var y = cdf( 0.0, 0.0 );
// returns NaN

y = cdf( 0.5, -5.0 );
// returns NaN
```

#### cdf.factory( c )

Returns a function for evaluating the [CDF][cdf] of a [Bradford][bradford-distribution] distribution with shape parameter `c`.

```javascript
var myPDF = cdf.factory( 5.0 );
var y = myPDF( 0.5 );
// returns ~0.699

y = myPDF( 1.0 );
// returns 1.0
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var uniform = require( '@stdlib/random/array/uniform' );
var cdf = require( '@stdlib/stats/base/dists/bradford/cdf' );

var x = uniform( 10, 0.0, 1.0 );
var c = uniform( 10, 0.1, 10.0 );

var y;
var i;
for ( i = 0; i < x.length; i++ ) {
y = cdf( x[ i ], c[ i ] );
console.log( 'x: %d, c: %d, F(x;c): %d', x[ i ].toFixed( 4 ), c[ 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">

[cdf]: https://en.wikipedia.org/wiki/Cumulative_distribution_function

[bradford-distribution]: https://en.wikipedia.org/wiki/Bradford%27s_law

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* @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 x;
var c;
var y;
var i;

x = uniform( 100, 0.0, 1.0 );
c = uniform( 100, 0.1, 10.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = cdf( x[ i % x.length ], c[ i % c.length ] );
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 x;
var y;
var i;

x = uniform( 100, 0.0, 1.0 );
mycdf = cdf.factory( 5.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = mycdf( x[ i % x.length ] );
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();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

{{alias}}( x, c )
Evaluates the cumulative distribution function
(CDF) for a Bradford distribution
with shape parameter `c` at a value `x`.

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

If provided `c <= 0`, the function returns `NaN`.

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

c: number
Shape parameter.

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

Examples
--------
> var y = {{alias}}( 0.1, 0.1 )
~0.104
> y = {{alias}}( 0.5, 5.0 )
~0.699
> y = {{alias}}( 1.0, 10.0 )
1.0
> y = {{alias}}( -1.0, 0.5 )
0.0
> y = {{alias}}( 2.0, 0.5 )
1.0

> y = {{alias}}( 0.5, 0.0 )
NaN
> y = {{alias}}( 0.5, -5.0 )
NaN

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


{{alias}}.factory( c )
Returns a function for evaluating the cumulative distribution function
(CDF) of a Bradford distribution with shape parameter `c`.

Parameters
----------
c: number
Shape parameter.

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

Examples
--------
> var myCDF = {{alias}}.factory( 5.0 );
> var y = myCDF( 0.5 )
~0.699
> y = myCDF( 1.0 )
1.0

See Also
--------

Loading
Loading