-
-
Notifications
You must be signed in to change notification settings - Fork 835
bench: refactor random number generation in stats/base/dists/signrank
#5088
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,8 +21,8 @@ | |||||||||||||||||||||||||||
// MODULES // | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
var bench = require( '@stdlib/bench' ); | ||||||||||||||||||||||||||||
var randu = require( '@stdlib/random/base/randu' ); | ||||||||||||||||||||||||||||
var ceil = require( '@stdlib/math/base/special/ceil' ); | ||||||||||||||||||||||||||||
var uniform = require( '@stdlib/random/base/uniform' ); | ||||||||||||||||||||||||||||
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); | ||||||||||||||||||||||||||||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||||||||||||||||||||||||||||
var pkg = require( './../package.json' ).name; | ||||||||||||||||||||||||||||
var cdf = require( './../lib' ); | ||||||||||||||||||||||||||||
|
@@ -31,16 +31,23 @@ var cdf = require( './../lib' ); | |||||||||||||||||||||||||||
// MAIN // | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
bench( pkg, function benchmark( b ) { | ||||||||||||||||||||||||||||
var n; | ||||||||||||||||||||||||||||
var nValues; | ||||||||||||||||||||||||||||
var values; | ||||||||||||||||||||||||||||
Comment on lines
+34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Please add only |
||||||||||||||||||||||||||||
var x; | ||||||||||||||||||||||||||||
var y; | ||||||||||||||||||||||||||||
var i; | ||||||||||||||||||||||||||||
var y; | ||||||||||||||||||||||||||||
Comment on lines
37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
values = new Array( b.iterations ); | ||||||||||||||||||||||||||||
nValues = new Array( b.iterations ); | ||||||||||||||||||||||||||||
for ( i = 0; i < b.iterations; i++ ) { | ||||||||||||||||||||||||||||
values[ i ] = uniform( 0.0, 20.0 ); | ||||||||||||||||||||||||||||
nValues[ i ] = discreteUniform( 1, 20 ); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+40
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
b.tic(); | ||||||||||||||||||||||||||||
for ( i = 0; i < b.iterations; i++ ) { | ||||||||||||||||||||||||||||
x = randu() * 20.0; | ||||||||||||||||||||||||||||
n = ceil( randu()*20.0 ); | ||||||||||||||||||||||||||||
y = cdf( x, n ); | ||||||||||||||||||||||||||||
x = values[ i ]; | ||||||||||||||||||||||||||||
y = cdf( x, nValues[ i ] ); | ||||||||||||||||||||||||||||
Comment on lines
+49
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||
if ( isnan( y ) ) { | ||||||||||||||||||||||||||||
b.fail( 'should not return NaN' ); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
@@ -54,6 +61,7 @@ bench( pkg, function benchmark( b ) { | |||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
bench( pkg+':factory', function benchmark( b ) { | ||||||||||||||||||||||||||||
var values; | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here and also applies throughout the PR. |
||||||||||||||||||||||||||||
var mycdf; | ||||||||||||||||||||||||||||
var n; | ||||||||||||||||||||||||||||
var x; | ||||||||||||||||||||||||||||
|
@@ -63,9 +71,14 @@ bench( pkg+':factory', function benchmark( b ) { | |||||||||||||||||||||||||||
n = 20; | ||||||||||||||||||||||||||||
mycdf = cdf.factory( n ); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
values = new Array( b.iterations ); | ||||||||||||||||||||||||||||
for ( i = 0; i < b.iterations; i++ ) { | ||||||||||||||||||||||||||||
values[ i ] = uniform( 0.0, 20.0 ); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+74
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be updated too by following the example above. |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
b.tic(); | ||||||||||||||||||||||||||||
for ( i = 0; i < b.iterations; i++ ) { | ||||||||||||||||||||||||||||
x = randu() * 20.0; | ||||||||||||||||||||||||||||
x = values[ i ]; | ||||||||||||||||||||||||||||
y = mycdf( x ); | ||||||||||||||||||||||||||||
if ( isnan( y ) ) { | ||||||||||||||||||||||||||||
b.fail( 'should not return NaN' ); | ||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,12 @@ | |
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var randu = require( '@stdlib/random/base/randu' ); | ||
var randint = require( '@stdlib/random/base/discrete-uniform' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var uniform = require( '@stdlib/random/base/uniform' ); | ||
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); | ||
var pkg = require( './../package.json' ).name; | ||
var quantile = require( './../lib' ); | ||
var EPS = 1e-10; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
p = randu(); Thus, using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it is ever used, it should be imported as: var EPS = require( '@stdlib/constants/float64/eps' ); |
||
|
||
|
||
// MAIN // | ||
|
@@ -38,8 +39,8 @@ bench( pkg, function benchmark( b ) { | |
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
p = randu(); | ||
n = randint( 1, 200 ); | ||
p = uniform( EPS, 1.0 ); | ||
n = discreteUniform( 1, 200 ); | ||
y = quantile( p, n ); | ||
if ( isnan( y ) ) { | ||
b.fail( 'should not return NaN' ); | ||
|
@@ -65,7 +66,7 @@ bench( pkg+':factory', function benchmark( b ) { | |
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
p = randu(); | ||
p = uniform( EPS, 1.0 ); | ||
y = myquantile( p ); | ||
if ( isnan( y ) ) { | ||
b.fail( 'should not return NaN' ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Float64Array
should be used instead ofArray