Skip to content

Commit a828e8b

Browse files
chore: clean up
1 parent a87eb4e commit a828e8b

File tree

16 files changed

+90
-102
lines changed

16 files changed

+90
-102
lines changed

lib/node_modules/@stdlib/stats/base/dists/beta/cdf/README.md

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -197,36 +197,6 @@ Evaluates the cumulative distribution function (CDF) for an beta distribution.
197197
```c
198198
double y = stdlib_base_dists_beta_cdf( 0.5, 1.0, 1.0 );
199199
// returns ~0.5
200-
201-
y = stdlib_base_dists_beta_cdf( 0.5, 2.0, 4.0 );
202-
// returns ~0.813
203-
204-
y = stdlib_base_dists_beta_cdf( 0.2, 2.0, 2.0 );
205-
// returns ~0.104
206-
207-
y = stdlib_base_dists_beta_cdf( 0.8, 4.0, 4.0 );
208-
// returns ~0.967
209-
210-
y = stdlib_base_dists_beta_cdf( -0.5, 4.0, 2.0 );
211-
// returns ~0.0
212-
213-
y = stdlib_base_dists_beta_cdf( 1.5, 4.0, 2.0 );
214-
// returns ~1.0
215-
216-
y = stdlib_base_dists_beta_cdf( 2.0, -1.0, 0.5 );
217-
// returns NaN
218-
219-
y = stdlib_base_dists_beta_cdf( 2.0, 0.5, -1.0 );
220-
// returns NaN
221-
222-
y = stdlib_base_dists_beta_cdf( NaN, 1.0, 1.0 );
223-
// returns NaN
224-
225-
y = stdlib_base_dists_beta_cdf( 0.0, NaN, 1.0 );
226-
// returns NaN
227-
228-
y = stdlib_base_dists_beta_cdf( 0.0, 1.0, NaN );
229-
// returns NaN
230200
```
231201

232202
The function accepts the following arguments:
@@ -263,6 +233,11 @@ double stdlib_base_dists_bernoulli_cdf( const double x, const double alpha, cons
263233
#include <stdlib.h>
264234
#include <stdio.h>
265235
236+
static double random_uniform( const double min, const double max ) {
237+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
238+
return min + ( v*(max-min) );
239+
}
240+
266241
int main( void ) {
267242
double p;
268243
double alpha;
@@ -272,9 +247,9 @@ int main( void ) {
272247
int i;
273248
274249
for ( i = 0; i < 10; i++ ) {
275-
x = ( (double)rand() / (double)RAND_MAX );
276-
alpha = ( ( (double)rand() / (double)RAND_MAX )*5.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
277-
beta = ( ( (double)rand() / (double)RAND_MAX )*5.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
250+
x = random_uniform( 0.0, 1.0 );
251+
alpha = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 5.0 );
252+
beta = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 5.0 );
278253
y = stdlib_base_dists_beta_cdf( x, alpha, beta );
279254
printf( "x: %1f, α: %1f, β: %1f, F(x;α,β): %lf\n", x, alpha, beta, y );
280255
}

lib/node_modules/@stdlib/stats/base/dists/beta/cdf/benchmark/benchmark.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
var bench = require( '@stdlib/bench' );
2424
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
26+
var Float64Array = require( '@stdlib/array/float64' );
2527
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2628
var EPS = require( '@stdlib/constants/float64/eps' );
2729
var pkg = require( './../package.json' ).name;
@@ -31,18 +33,30 @@ var cdf = require( './../lib' );
3133
// MAIN //
3234

3335
bench( pkg, function benchmark( b ) {
36+
var len;
3437
var alpha;
3538
var beta;
3639
var x;
3740
var y;
3841
var i;
3942

43+
len = 100;
44+
x = new Float64Array( len );
45+
for ( i = 0; i < len; i++ ) {
46+
x[ i ] = uniform( EPS, 3.0 );
47+
}
48+
alpha = new Float64Array( len );
49+
for ( i = 0; i < len; i++ ) {
50+
alpha[ i ] = uniform( EPS, 3.0 );
51+
}
52+
beta = new Float64Array( len );
53+
for ( i = 0; i < len; i++ ) {
54+
beta[ i ] = uniform( EPS, 3.0 );
55+
}
56+
4057
b.tic();
4158
for ( i = 0; i < b.iterations; i++ ) {
42-
x = ( randu()*2.0 ) + EPS;
43-
alpha = ( randu()*100.0 ) + EPS;
44-
beta = ( randu()*100.0 ) + EPS;
45-
y = cdf( x, alpha, beta );
59+
y = cdf( x[ i%100 ], alpha[ i%100 ], beta[ i%100 ] );
4660
if ( isnan( y ) ) {
4761
b.fail( 'should not return NaN' );
4862
}

lib/node_modules/@stdlib/stats/base/dists/beta/cdf/benchmark/benchmark.native.js

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
26+
var Float64Array = require( '@stdlib/array/float64' );
2627
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2728
var tryRequire = require( '@stdlib/utils/try-require' );
2829
var EPS = require( '@stdlib/constants/float64/eps' );
@@ -40,46 +41,30 @@ var opts = {
4041
// MAIN //
4142

4243
bench( pkg+'::native', opts, function benchmark( b ) {
44+
var len;
4345
var alpha;
4446
var beta;
4547
var x;
4648
var y;
4749
var i;
4850

49-
b.tic();
50-
for ( i = 0; i < b.iterations; i++ ) {
51-
x = ( randu()*2.0 ) + EPS;
52-
alpha = ( randu()*100.0 ) + EPS;
53-
beta = ( randu()*100.0 ) + EPS;
54-
y = cdf( x, alpha, beta );
55-
if ( isnan( y ) ) {
56-
b.fail( 'should not return NaN' );
57-
}
51+
len = 100;
52+
x = new Float64Array( len );
53+
for ( i = 0; i < len; i++ ) {
54+
x[ i ] = uniform( EPS, 3.0 );
5855
}
59-
b.toc();
60-
if ( isnan( y ) ) {
61-
b.fail( 'should not return NaN' );
56+
alpha = new Float64Array( len );
57+
for ( i = 0; i < len; i++ ) {
58+
alpha[ i ] = uniform( EPS, 3.0 );
59+
}
60+
beta = new Float64Array( len );
61+
for ( i = 0; i < len; i++ ) {
62+
beta[ i ] = uniform( EPS, 3.0 );
6263
}
63-
b.pass( 'benchmark finished' );
64-
b.end();
65-
});
66-
67-
bench( pkg+':factory', opts, function benchmark( b ) {
68-
var mycdf;
69-
var alpha;
70-
var beta;
71-
var x;
72-
var y;
73-
var i;
74-
75-
alpha = 100.56789;
76-
beta = 55.54321;
77-
mycdf = cdf.factory( alpha, beta );
7864

7965
b.tic();
8066
for ( i = 0; i < b.iterations; i++ ) {
81-
x = ( randu()*2.0 ) + EPS;
82-
y = mycdf( x );
67+
y = cdf( x[ i%100 ], alpha[ i%100 ], beta[ i%100 ] );
8368
if ( isnan( y ) ) {
8469
b.fail( 'should not return NaN' );
8570
}

lib/node_modules/@stdlib/stats/base/dists/beta/cdf/benchmark/c/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ run: $(c_targets)
143143
clean:
144144
$(QUIET) -rm -f *.o *.out
145145

146-
.PHONY: clean
146+
.PHONY: clean

lib/node_modules/@stdlib/stats/base/dists/beta/cdf/benchmark/c/benchmark.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ static double tic( void ) {
7676
}
7777

7878
/**
79-
* Generates a random number on the interval [0,1).
79+
* Generates a random number on the interval [min,max).
8080
*
81-
* @return random number
81+
* @param min minimum value (inclusive)
82+
* @param max maximum value (exclusive)
83+
* @return random number
8284
*/
83-
static double rand_double( void ) {
84-
int r = rand();
85-
return (double)r / ( (double)RAND_MAX + 1.0 );
85+
static double random_uniform( const double min, const double max ) {
86+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
87+
return min + ( v*(max-min) );
8688
}
8789

8890
/**
@@ -92,19 +94,26 @@ static double rand_double( void ) {
9294
*/
9395
static double benchmark( void ) {
9496
double elapsed;
95-
double alpha;
96-
double beta;
97-
double x;
97+
double alpha[ 100 ];
98+
double beta[ 100 ];
99+
double x[ 100 ];
98100
double y;
99101
double t;
100102
int i;
101103

104+
for ( i = 0; i < 100; i++ ) {
105+
x[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 2.0 );
106+
}
107+
for ( i = 0; i < 100; i++ ) {
108+
alpha[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 100.0 );
109+
}
110+
for ( i = 0; i < 100; i++ ) {
111+
beta[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 100.0 );
112+
}
113+
102114
t = tic();
103115
for ( i = 0; i < ITERATIONS; i++ ) {
104-
x = ( ( (double)rand() / (double)RAND_MAX )*3.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
105-
alpha = ( ( (double)rand() / (double)RAND_MAX )*100.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
106-
beta = ( ( (double)rand() / (double)RAND_MAX )*100.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
107-
y = stdlib_base_dists_beta_cdf( x, alpha, beta );
116+
y = stdlib_base_dists_beta_cdf( x[ i%100 ], alpha[ i%100 ], beta[ i%100 ] );
108117
if ( y != y ) {
109118
printf( "should not return NaN\n" );
110119
break;
@@ -135,4 +144,4 @@ int main( void ) {
135144
printf( "ok %d benchmark finished\n", i+1 );
136145
}
137146
print_summary( REPEATS, REPEATS );
138-
}
147+
}

lib/node_modules/@stdlib/stats/base/dists/beta/cdf/binding.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,4 @@
167167
], # end actions
168168
}, # end target copy_addon
169169
], # end targets
170-
}
170+
}

lib/node_modules/@stdlib/stats/base/dists/beta/cdf/examples/c/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ run: $(c_targets)
143143
clean:
144144
$(QUIET) -rm -f *.o *.out
145145

146-
.PHONY: clean
146+
.PHONY: clean

lib/node_modules/@stdlib/stats/base/dists/beta/cdf/examples/c/example.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,24 @@
2121
#include <stdlib.h>
2222
#include <stdio.h>
2323

24+
static double random_uniform( const double min, const double max ) {
25+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
26+
return min + ( v*(max-min) );
27+
}
28+
2429
int main( void ) {
2530
double p;
26-
double alpha;
27-
double beta;
28-
double x;
31+
double alpha;
32+
double beta;
33+
double x;
2934
double y;
3035
int i;
3136

3237
for ( i = 0; i < 10; i++ ) {
33-
x = ( (double)rand() / (double)RAND_MAX );
34-
alpha = ( ( (double)rand() / (double)RAND_MAX )*5.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
35-
beta = ( ( (double)rand() / (double)RAND_MAX )*5.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
36-
y = stdlib_base_dists_beta_cdf( x, alpha, beta );
37-
printf( "x: %1f, α: %1f, β: %1f, F(x;α,β): %lf\n", x, alpha, beta, y );
38+
x = random_uniform( 0.0, 1.0 );
39+
alpha = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 5.0 );
40+
beta = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 5.0 );
41+
y = stdlib_base_dists_beta_cdf( x, alpha, beta );
42+
printf( "x: %1f, α: %1f, β: %1f, F(x;α,β): %lf\n", x, alpha, beta, y );
3843
}
39-
}
44+
}

lib/node_modules/@stdlib/stats/base/dists/beta/cdf/include.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@
5050
'<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libpath; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
5151
],
5252
}, # end variables
53-
}
53+
}

lib/node_modules/@stdlib/stats/base/dists/beta/cdf/include/stdlib/stats/base/dists/beta/cdf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern "C" {
2727
#endif
2828

2929
/**
30-
* Evaluates the cumulative distribution function (CDF) for a beta distribution with first shape parameter `alpha` and second shape parameter `beta` at a value `x`.
30+
* Evaluates the cumulative distribution function (CDF) for a beta distribution.
3131
*/
3232
double stdlib_base_dists_beta_cdf( const double x, const double alpha, const double beta );
3333

0 commit comments

Comments
 (0)