-
-
Notifications
You must be signed in to change notification settings - Fork 836
bench: refactor random number generation in stats/base/dists/weibull
#5011
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,7 +21,8 @@ | |||||||||||
// MODULES // | ||||||||||||
|
||||||||||||
var bench = require( '@stdlib/bench' ); | ||||||||||||
var randu = require( '@stdlib/random/base/randu' ); | ||||||||||||
var Float64Array = require( '@stdlib/array/float64' ); | ||||||||||||
var uniform = require( '@stdlib/random/base/uniform' ); | ||||||||||||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||||||||||||
var EPS = require( '@stdlib/constants/float64/eps' ); | ||||||||||||
var pkg = require( './../package.json' ).name; | ||||||||||||
|
@@ -32,17 +33,25 @@ var cdf = require( './../lib' ); | |||||||||||
|
||||||||||||
bench( pkg, function benchmark( b ) { | ||||||||||||
var lambda; | ||||||||||||
var len; | ||||||||||||
var k; | ||||||||||||
var x; | ||||||||||||
var y; | ||||||||||||
var i; | ||||||||||||
|
||||||||||||
len = 100; | ||||||||||||
x = new Float64Array( len ); | ||||||||||||
lambda = new Float64Array( len ); | ||||||||||||
k = new Float64Array( len ); | ||||||||||||
for ( i = 0; i < len; i++ ) { | ||||||||||||
x[ i ] = uniform( EPS, 100.0 ); | ||||||||||||
lambda[ i ] = uniform( EPS, 100.0 ); | ||||||||||||
k[ i ] = uniform( EPS, 100.0 ); | ||||||||||||
} | ||||||||||||
|
||||||||||||
b.tic(); | ||||||||||||
for ( i = 0; i < b.iterations; i++ ) { | ||||||||||||
x = ( randu()*100.0 ) + EPS; | ||||||||||||
lambda = ( randu()*100.0 ) + EPS; | ||||||||||||
k = ( randu()*100.0 ) + EPS; | ||||||||||||
y = cdf( x, k, lambda ); | ||||||||||||
y = cdf( x[ i % len ], k[ i % len ], lambda[ i % len ] ); | ||||||||||||
if ( isnan( y ) ) { | ||||||||||||
b.fail( 'should not return NaN' ); | ||||||||||||
} | ||||||||||||
|
@@ -58,6 +67,7 @@ bench( pkg, function benchmark( b ) { | |||||||||||
bench( pkg+':factory', function benchmark( b ) { | ||||||||||||
var lambda; | ||||||||||||
var mycdf; | ||||||||||||
var len; | ||||||||||||
var k; | ||||||||||||
var x; | ||||||||||||
var y; | ||||||||||||
|
@@ -66,11 +76,16 @@ bench( pkg+':factory', function benchmark( b ) { | |||||||||||
lambda = 3.14; | ||||||||||||
k = 2.25; | ||||||||||||
mycdf = cdf.factory( k, lambda ); | ||||||||||||
len = 100; | ||||||||||||
|
||||||||||||
x = new Float64Array( len ); | ||||||||||||
Comment on lines
+79
to
+81
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
No space between initializations |
||||||||||||
for ( i = 0; i < len; i++ ) { | ||||||||||||
x[ i ] = uniform( EPS, 100.0 ); | ||||||||||||
} | ||||||||||||
|
||||||||||||
b.tic(); | ||||||||||||
for ( i = 0; i < b.iterations; i++ ) { | ||||||||||||
x = ( randu()*100.0 ) + EPS; | ||||||||||||
y = mycdf( x ); | ||||||||||||
y = mycdf( x[ i % len ] ); | ||||||||||||
if ( isnan( y ) ) { | ||||||||||||
b.fail( 'should not return NaN' ); | ||||||||||||
} | ||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,7 +21,8 @@ | |||||||||||
// MODULES // | ||||||||||||
|
||||||||||||
var bench = require( '@stdlib/bench' ); | ||||||||||||
var randu = require( '@stdlib/random/base/randu' ); | ||||||||||||
var Float64Array = require( '@stdlib/array/float64' ); | ||||||||||||
var uniform = require( '@stdlib/random/base/uniform' ); | ||||||||||||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||||||||||||
var EPS = require( '@stdlib/constants/float64/eps' ); | ||||||||||||
var pkg = require( './../package.json' ).name; | ||||||||||||
|
@@ -32,17 +33,25 @@ var logcdf = require( './../lib' ); | |||||||||||
|
||||||||||||
bench( pkg, function benchmark( b ) { | ||||||||||||
var lambda; | ||||||||||||
var len; | ||||||||||||
var k; | ||||||||||||
var x; | ||||||||||||
var y; | ||||||||||||
var i; | ||||||||||||
|
||||||||||||
len = 100; | ||||||||||||
x = new Float64Array( len ); | ||||||||||||
lambda = new Float64Array( len ); | ||||||||||||
k = new Float64Array( len ); | ||||||||||||
for ( i = 0; i < len; i++ ) { | ||||||||||||
x[ i ] = uniform( EPS, 100.0); | ||||||||||||
lambda[ i ] = uniform( EPS, 100.0); | ||||||||||||
k[ i ] = uniform( EPS, 100.0); | ||||||||||||
} | ||||||||||||
b.tic(); | ||||||||||||
|
||||||||||||
for ( i = 0; i < b.iterations; i++ ) { | ||||||||||||
Comment on lines
51
to
53
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
|
||||||||||||
x = ( randu()*100.0 ) + EPS; | ||||||||||||
lambda = ( randu()*100.0 ) + EPS; | ||||||||||||
k = ( randu()*100.0 ) + EPS; | ||||||||||||
y = logcdf( x, k, lambda ); | ||||||||||||
y = logcdf( x[ i % len ], k[ i % len ], lambda[ i % len ] ); | ||||||||||||
if ( isnan( y ) ) { | ||||||||||||
b.fail( 'should not return NaN' ); | ||||||||||||
} | ||||||||||||
|
@@ -58,6 +67,7 @@ bench( pkg, function benchmark( b ) { | |||||||||||
bench( pkg+':factory', function benchmark( b ) { | ||||||||||||
var mylogcdf; | ||||||||||||
var lambda; | ||||||||||||
var len; | ||||||||||||
var k; | ||||||||||||
var x; | ||||||||||||
var y; | ||||||||||||
|
@@ -66,11 +76,15 @@ bench( pkg+':factory', function benchmark( b ) { | |||||||||||
lambda = 3.14; | ||||||||||||
k = 2.25; | ||||||||||||
mylogcdf = logcdf.factory( k, lambda ); | ||||||||||||
|
||||||||||||
len = 100; | ||||||||||||
x = new Float64Array( len ); | ||||||||||||
for ( i = 0; i < len; i++ ) { | ||||||||||||
x[ i ] = uniform( EPS, 100.0 ); | ||||||||||||
} | ||||||||||||
b.tic(); | ||||||||||||
|
||||||||||||
for ( i = 0; i < b.iterations; i++ ) { | ||||||||||||
Comment on lines
84
to
86
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
|
||||||||||||
x = ( randu()*100.0 ) + EPS; | ||||||||||||
y = mylogcdf( x ); | ||||||||||||
y = mylogcdf( x[ i % len ] ); | ||||||||||||
if ( isnan( y ) ) { | ||||||||||||
b.fail( 'should not return NaN' ); | ||||||||||||
} | ||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,7 +21,8 @@ | |||||||||||
// MODULES // | ||||||||||||
|
||||||||||||
var bench = require( '@stdlib/bench' ); | ||||||||||||
var randu = require( '@stdlib/random/base/randu' ); | ||||||||||||
var Float64Array = require( '@stdlib/array/float64' ); | ||||||||||||
var uniform = require( '@stdlib/random/base/uniform' ); | ||||||||||||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||||||||||||
var EPS = require( '@stdlib/constants/float64/eps' ); | ||||||||||||
var pkg = require( './../package.json' ).name; | ||||||||||||
|
@@ -32,17 +33,25 @@ var logpdf = require( './../lib' ); | |||||||||||
|
||||||||||||
bench( pkg, function benchmark( b ) { | ||||||||||||
var lambda; | ||||||||||||
var len; | ||||||||||||
var k; | ||||||||||||
var x; | ||||||||||||
var y; | ||||||||||||
var i; | ||||||||||||
|
||||||||||||
len = 100; | ||||||||||||
x = new Float64Array( len ); | ||||||||||||
lambda = new Float64Array( len ); | ||||||||||||
k = new Float64Array( len ); | ||||||||||||
for ( i = 0; i < len; i++ ) { | ||||||||||||
x[ i ] = uniform( EPS, 100.0 ); | ||||||||||||
lambda[ i ] = uniform( EPS, 100.0 ); | ||||||||||||
k[ i ] = uniform( EPS, 100.0 ); | ||||||||||||
} | ||||||||||||
b.tic(); | ||||||||||||
|
||||||||||||
for ( i = 0; i < b.iterations; i++ ) { | ||||||||||||
Comment on lines
51
to
53
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
This change is required throughout the PR. |
||||||||||||
x = ( randu()*100.0 ) + EPS; | ||||||||||||
lambda = ( randu()*100.0 ) + EPS; | ||||||||||||
k = ( randu()*100.0 ) + EPS; | ||||||||||||
y = logpdf( x, k, lambda ); | ||||||||||||
y = logpdf( x[ i % len ], k[ i % len ], lambda[ i % len ] ); | ||||||||||||
if ( isnan( y ) ) { | ||||||||||||
b.fail( 'should not return NaN' ); | ||||||||||||
} | ||||||||||||
|
@@ -58,6 +67,7 @@ bench( pkg, function benchmark( b ) { | |||||||||||
bench( pkg+':factory', function benchmark( b ) { | ||||||||||||
var mylogpdf; | ||||||||||||
var lambda; | ||||||||||||
var len; | ||||||||||||
var k; | ||||||||||||
var x; | ||||||||||||
var y; | ||||||||||||
|
@@ -66,11 +76,15 @@ bench( pkg+':factory', function benchmark( b ) { | |||||||||||
lambda = 3.14; | ||||||||||||
k = 2.25; | ||||||||||||
mylogpdf = logpdf.factory( k, lambda ); | ||||||||||||
|
||||||||||||
len = 100; | ||||||||||||
x = new Float64Array( len ); | ||||||||||||
for ( i = 0; i < len; i++ ) { | ||||||||||||
x[ i ] = uniform( EPS, 100.0 ); | ||||||||||||
} | ||||||||||||
b.tic(); | ||||||||||||
|
||||||||||||
for ( i = 0; i < b.iterations; i++ ) { | ||||||||||||
x = ( randu()*100.0 ) + EPS; | ||||||||||||
y = mylogpdf( x ); | ||||||||||||
y = mylogpdf( x[ i % len ] ); | ||||||||||||
if ( isnan( y ) ) { | ||||||||||||
b.fail( 'should not return NaN' ); | ||||||||||||
} | ||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.