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
97 changes: 19 additions & 78 deletions lib/node_modules/@stdlib/stats/base/dists/geometric/cdf/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<!--

@license Apache-2.0

Copyright (c) 2018 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 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
Expand All @@ -15,7 +14,6 @@ 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
Expand All @@ -24,33 +22,22 @@ limitations under the License.

<section class="intro">

The [cumulative distribution function][cdf] for a [geometric][geometric-distribution] random variable is

<!-- <equation class="equation" label="eq:geometric_cdf" align="center" raw="F(x;p)= \begin{cases} 0 & \text{ for } x < 0 \\ 1-(1 - p)^{\left\lfloor x \right\rfloor+1} & \text{ otherwise} \end{cases}" alt="Cumulative distribution function for a geometric distribution."> -->
The [cumulative distribution function][cdf] for a [geometric][geometric-distribution] random variable is:

```math
F(x;p)= \begin{cases} 0 & \text{ for } x < 0 \\ 1-(1 - p)^{\left\lfloor x \right\rfloor+1} & \text{ otherwise} \end{cases}
F(x;p)= \begin{cases} 0 & \text{for } x < 0 \\ 1-(1 - p)^{\left\lfloor x \right\rfloor+1} & \text{otherwise} \end{cases}
```

<!-- <div class="equation" align="center" data-raw-text="F(x;p)= \begin{cases} 0 &amp; \text{ for } x &lt; 0 \\ 1-(1 - p)^{\left\lfloor x \right\rfloor+1} &amp; \text{ otherwise} \end{cases}" data-equation="eq:geometric_cdf">
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/geometric/cdf/docs/img/equation_geometric_cdf.svg" alt="Cumulative distribution function for a geometric distribution.">
<br>
</div> -->

<!-- </equation> -->

where `0 <= p <= 1` is the success probability. `x` denotes the number of _failures_ before the first success.

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

#### cdf( x, p )
Expand Down Expand Up @@ -87,7 +74,7 @@ y = cdf( 2.0, 1.5 );

#### cdf.factory( p )

Returns a function for evaluating the [cumulative distribution function][cdf] of a [geometric][geometric-distribution] distribution with success probability `p`
Returns a function for evaluating the [cumulative distribution function][cdf] of a [geometric][geometric-distribution] distribution with success probability `p`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"I added a period at the end to follow proper documentation style. If this change is not required, please let me know — I’ll revert it."


```javascript
var mycdf = cdf.factory( 0.5 );
Expand All @@ -100,17 +87,13 @@ y = mycdf( 1.0 );

</section>

<!-- /.usage -->

<section class="examples">

## Examples

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

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

var p;
var x;
Expand All @@ -127,25 +110,18 @@ for ( i = 0; i < 10; i++ ) {

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs
<section class="references">

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

<section class="intro">
- [Cumulative distribution function (Wikipedia)](https://en.wikipedia.org/wiki/Cumulative_distribution_function)
- [Geometric distribution (Wikipedia)](https://en.wikipedia.org/wiki/Geometric_distribution)

</section>

<!-- /.intro -->
<section class="c">

<!-- C usage documentation. -->
## C APIs

<section class="usage">

Expand All @@ -164,29 +140,8 @@ double out = stdlib_base_dists_geometric_cdf( 2.0, 0.5 );
// returns 0.875
```

The function accepts the following arguments:

- **x**: `[in] double` input value.
- **p**: `[in] double` probability of success.

```c
double stdlib_base_dists_geometric_cdf( const double x, const double p );
```

</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
Expand All @@ -199,7 +154,7 @@ double stdlib_base_dists_geometric_cdf( const double x, const double p );

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

int main( void ) {
Expand All @@ -219,30 +174,16 @@ int main( void ) {

</section>

<!-- /.references -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- 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

[geometric-distribution]: https://en.wikipedia.org/wiki/Geometric_distribution

</section>

<!-- /.examples -->
<!-- /.c -->
<!-- /.links -->



Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @param x input value
* @param p success probability
* @return evaluated CDF
* @return evaluated CDF or NaN (if input is invalid)
*
* @example
* double y = stdlib_base_dists_geometric_cdf( 2.0, 0.5 );
Expand All @@ -50,3 +50,4 @@ double stdlib_base_dists_geometric_cdf( const double x, const double p ) {
}
return 1.0 - stdlib_base_pow( 1.0 - p, stdlib_base_floor( x ) + 1.0 );
}