Skip to content
Closed
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
102 changes: 102 additions & 0 deletions lib/node_modules/@stdlib/stats/base/dists/hypergeometric/cdf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,108 @@ for ( i = 0; i < 10; i++ ) {

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/stats/base/dists/hypergeometric/cdf.h"
```

#### stdlib_base_dists_hypergeometric_cdf( x, N, K, n )

Evaluates the [probability mass function][cdf] (cdf) for a [hypergeometric][hypergeometric-distribution] distribution with parameters `N` (population size), `K` (subpopulation size), and `n` (number of draws).

```c
double out = stdlib_base_dists_hypergeometric_cdf( 1.0, 8, 4, 2 );
// returns ~0.786
```

The function accepts the following arguments:

- **x**: `[in] double` input value.
- **N**: `[in] int32_t` population size.
- **K**: `[in] int32_t` subpopulation size.
- **n**: `[in] int32_t` number of draws.

```c
double stdlib_base_dists_hypergeometric_cdf( const double x, const int32_t N, const int32_t K, const int32_t n );
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
#include "stdlib/stats/base/dists/hypergeometric/cdf.h"
#include "stdlib/math/base/special/round.h"
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>

static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
return min + ( v * ( max - min ) );
}

int main( void ) {
int32_t N;
int32_t K;
int32_t n;
double x;
double y;
int i;
for ( i = 0; i < 10; i++ ) {
x = stdlib_base_round( random_uniform( 0.0, 5.0 ) );
N = stdlib_base_round( random_uniform( 0.0, 20.0 ) );
K = stdlib_base_round( random_uniform( 0.0, N ) );
n = stdlib_base_round( random_uniform( 0.0, N ) );
y = stdlib_base_dists_hypergeometric_cdf( x, N, K, n );
printf( "x: %lf, N: %d, K: %d, n: %d, P(X=x;N,K,n): %lf\n", x, N, K, n, y );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* @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 resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var cdf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( cdf instanceof Error )
};


// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var len;
var N;
var K;
var n;
var x;
var y;
var i;

len = 100;
N = new Float64Array( len );
K = new Float64Array( len );
n = new Float64Array( len );
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = discreteUniform( 1, 10 );
N[ i ] = discreteUniform( 1, 100 );
K[ i ] = discreteUniform( 1, N[ i ] );
n[ i ] = discreteUniform( 1, N[ i ] );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = cdf( x[ i%len ], N[ i%len ], K[ i%len ], n[ 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();
});
Loading
Loading