Skip to content

fix: update geometric median documentation #5922

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

Closed
wants to merge 5 commits into from
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
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Returns the [median][median] of a [geometric][geometric-distribution] distributi

```c
double out = stdlib_base_dists_geometric_median( 0.5 );
// returns 1
// returns 0
```

The function accepts the following arguments:
Expand Down Expand Up @@ -187,7 +187,6 @@ double stdlib_base_dists_geometric_median( const double p );
#include "stdlib/stats/base/dists/geometric/median.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' );
var EPS = require( '@stdlib/constants/float64/eps' );
var pkg = require( './../package.json' ).name;
var median = require( './../lib' );
var uniform = require('@stdlib/random/base/uniform');


// MAIN //
Expand All @@ -42,8 +43,8 @@ bench( pkg, function benchmark( b ) {
mu = new Float64Array( len );
c = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
mu[ i ] = ( randu() * 100.0 ) - 50.0;
c[ i ] = ( randu() * 20.0 ) + EPS;
mu[ i ] = uniform( -50.0, 50.0 );
c[ i ] = uniform( EPS, 20.0 + EPS );
}

b.tic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
var uniform = require('@stdlib/random/base/uniform');


// VARIABLES //
Expand All @@ -51,8 +52,8 @@ bench( pkg+'::native', opts, function benchmark( b ) {
mu = new Float64Array( len );
c = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
mu[ i ] = ( randu() * 100.0 ) - 50.0;
c[ i ] = ( randu() * 20.0 ) + EPS;
mu[ i ] = uniform( -50.0, 50.0 );
c[ i ] = uniform( EPS, 20.0 + EPS );
}

b.tic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ tape( 'main export is a function', opts, function test( t ) {

tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) {
var y = median( NaN, 1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );
y = median( 1.0, NaN );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );
t.end();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ y = mylogcdf( 8.0 );

## Notes

- In virtually all cases, using the `logcdf` or `logcdf` functions is preferable to manually computing the logarithm of the `pdf` or `cdf`, respectively, since the latter is prone to overflow and underflow.
- In virtually all cases, using the `logcdf` or `logcdf` functions is preferable to manually computing the logarithm of the `cdf` or `cdf`, respectively, since the latter is prone to overflow and underflow.

</section>

Expand Down Expand Up @@ -186,7 +186,7 @@ for ( i = 0; i < 25; i++ ) {

#### stdlib_base_dists_geometric_logcdf( x, a, b, c )

Evaluates the natural logarithm of the [cumulative distribution function][cdf] (CDF) for a [triangular][triangular-distribution] distribution with parameters `a` (lower limit), `b` (upper limit) and `c` (mode).
Evaluates the natural logarithm of the [cumulative distribution function][cdf] (CDF) for a [triangular][triangular-distribution] distribution with parameters `a` (lower limit), `b` (upper limit), and `c` (mode).

```c
double y = stdlib_base_dists_geometric_logcdf( 0.5, -1.0, 1.0, 0.0 );
Expand Down Expand Up @@ -227,7 +227,6 @@ double stdlib_base_dists_geometric_logcdf( const double x, const double a, const
#include "stdlib/constants/float64/eps.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "stdlib/constants/float64/eps.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' );
// MAIN //

/**
* Evaluates the natural logarithm of the cumulative distribution function (CDF) for a triangular distribution with lower limit `a` and upper limit `b` and mode `c` at a value `x`.
* Evaluates the logarithm of the cumulative distribution function (CDF) for a triangular distribution.
*
* @private
* @param {number} x - input value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ double stdlib_base_dists_triangular_logcdf( const double x, const double a, cons
if ( x <= c ) {
return ( 2.0 * stdlib_base_ln( x - a ) - stdlib_base_ln( ( b - a ) * ( c - a ) ) );
}
if( x < b ){
if ( x < b ) {
return stdlib_base_ln( 1.0 - ( stdlib_base_pow( b - x, 2.0 ) / ( ( b - a ) * ( b - c ) ) ) );
}
return 0.0;
Expand Down