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
23 changes: 10 additions & 13 deletions lib/node_modules/@stdlib/stats/base/dists/chisquare/mean/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,26 +144,27 @@ for ( i = 0; i < 10; i++ ) {

#### stdlib_base_dists_chisquare_mean( k )

Returns the [expected value][expected-value] of a [chi-squared][chisquare-distribution] distribution with degrees of freedom `k`.
Returns the expected value of a chi-squared distribution with degerees of freedom `k`.

```c
double out = stdlib_base_dists_chisquare_mean( 9.0 );
// returns 9.0
double y = stdlib_base_dists_chisquare_mean( 9.0 );
// returns ~9.0
```

The function accepts the following arguments:

- **k**: `[in] double` degrees of freedom.
- **k**: `[in] double` degrees of freedom

```c
double stdlib_base_dists_chisquare_mean( const double k );
double stdlib_base_dists_chisquare( const double k );
```

</section>

<!-- /.usage -->

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

<section class="notes">

Expand All @@ -178,10 +179,6 @@ double stdlib_base_dists_chisquare_mean( const double k );
### Examples

```c
#include "stdlib/stats/base/dists/chisquare/mean.h"
#include <stdlib.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) );
Expand All @@ -192,10 +189,10 @@ int main( void ) {
double y;
int i;

for ( i = 0; i < 25; i++ ) {
k = random_uniform( 0.0, 20.0 );
for ( i = 0; i < 10; i++ ) {
k = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
y = stdlib_base_dists_chisquare_mean( k );
printf( "k: %lf, E(X;k): %lf\n", k, y );
printf( "k: %1f, E(X;k): %lf\n", k, y );
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var EPS = require( '@stdlib/constants/float64/eps' );
var uniform = require( '@stdlib/random/base/uniform' );
var Float64Array = require( '@stdlib/array/float64' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var EPS = require( '@stdlib/constants/float64/eps' );
var pkg = require( './../package.json' ).name;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static double benchmark( void ) {

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
y = stdlib_base_dists_chisquare_mean( k[ i%100 ] );
y = stdlib_base_dists_chisquare_mean( k[ i % 100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include "stdlib/stats/base/dists/chisquare/mean.h"
#include "stdlib/constants/float64/eps.h"
#include <stdlib.h>
#include <stdio.h>

Expand All @@ -30,9 +31,9 @@ int main( void ) {
double y;
int i;

for ( i = 0; i < 25; i++ ) {
k = random_uniform( 0.0, 20.0 );
for ( i = 0; i < 10; i++ ) {
k = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
y = stdlib_base_dists_chisquare_mean( k );
printf( "k: %lf, E(X;k): %lf\n", k, y );
printf( "k: %1f, E(X;k): %lf\n", k, y );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern "C" {
#endif

/**
* Returns the expected value of a chi-squared distribution.
* Returns the expected value of a chi-squared distribution with degerees of freedom `k`.
*/
double stdlib_base_dists_chisquare_mean( const double k );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var addon = require( './../src/addon.node' );
/**
* Returns the expected value of a chi-squared distribution.
*
* @private
* @param {NonNegativeNumber} k - degrees of freedom
* @returns {NonNegativeNumber} expected value
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan"
"@stdlib/math/base/assert/is-nan",
"@stdlib/constants/float64/eps"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,30 @@
#include "stdlib/math/base/assert/is_nan.h"

/**
* Returns the expected value of a chi-squared distribution.
* Returns the expected value of a chi-squared distribution with degerees of freedom `k`.
*
* @param x degrees of freedom
* @return expected value
* @param k degrees of freedom
* @returns evaluated mean
*
* @example
* double y = stdlib_base_chisquare_mean( 9.0 );
* // returns 9.0
* double y = stdlib_base_dists_chisquare_mean( 9.0 );
* // returns ~9.0
*
* @example
* double y = stdlib_base_dists_chisquare_mean( 1.0 );
* // returns ~1.0
*
* @example
* double y = stdlib_base_dists_chisquare_mean( -0.2 );
* // returns NaN
*
* @example
* double y = stdlib_base_dists_chisquare_mean( NaN );
* // returns NaN
*/
double stdlib_base_dists_chisquare_mean( const double k ) {
if ( stdlib_base_is_nan( k ) || k < 0.0 ) {
return 0.0/0.0; //NaN
return 0.0 / 0.0;
}
return k;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@

var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var tryRequire = require( '@stdlib/utils/try-require' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var NINF = require( '@stdlib/constants/float64/ninf' );


// FIXTURES //

var data = require( './fixtures/julia/data.json' );


// VARIABLES //

var mean = tryRequire( resolve( __dirname, './../lib/native.js' ) );
Expand All @@ -40,6 +35,11 @@ var opts = {
};


// FIXTURES //

var data = require( './fixtures/julia/data.json' );


// TESTS //

tape( 'main export is a function', opts, function test( t ) {
Expand Down