Skip to content
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

feat: refactor random number generation stats/base/dists/weibull #5011

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ShabiShett07
Copy link

Resolves #4992

Description

What is the purpose of this pull request?

This pull request:

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

What about the benchmark of ctor? Do we need to change that too?

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@stdlib-bot
Copy link
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/weibull/cdf $\color{green}222/222$
$\color{green}+100.00\%$
$\color{green}23/23$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}222/222$
$\color{green}+100.00\%$
stats/base/dists/weibull/entropy $\color{green}126/126$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}126/126$
$\color{green}+100.00\%$
stats/base/dists/weibull/kurtosis $\color{green}137/137$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}137/137$
$\color{green}+100.00\%$
stats/base/dists/weibull/logcdf $\color{green}235/235$
$\color{green}+100.00\%$
$\color{green}26/26$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}235/235$
$\color{green}+100.00\%$
stats/base/dists/weibull/logpdf $\color{green}236/236$
$\color{green}+100.00\%$
$\color{green}33/33$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}236/236$
$\color{green}+100.00\%$
stats/base/dists/weibull/mean $\color{green}125/125$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}125/125$
$\color{green}+100.00\%$
stats/base/dists/weibull/median $\color{green}126/126$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}126/126$
$\color{green}+100.00\%$
stats/base/dists/weibull/mgf $\color{red}262/264$
$\color{green}+99.24\%$
$\color{red}23/25$
$\color{green}+92.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{red}262/264$
$\color{green}+99.24\%$
stats/base/dists/weibull/mode $\color{green}128/128$
$\color{green}+100.00\%$
$\color{green}10/10$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}128/128$
$\color{green}+100.00\%$
stats/base/dists/weibull/pdf $\color{green}238/238$
$\color{green}+100.00\%$
$\color{green}34/34$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}238/238$
$\color{green}+100.00\%$
stats/base/dists/weibull/quantile $\color{green}218/218$
$\color{green}+100.00\%$
$\color{green}23/23$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}218/218$
$\color{green}+100.00\%$
stats/base/dists/weibull/skewness $\color{green}139/139$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}139/139$
$\color{green}+100.00\%$
stats/base/dists/weibull/stdev $\color{green}128/128$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}128/128$
$\color{green}+100.00\%$
stats/base/dists/weibull/variance $\color{green}128/128$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}128/128$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

@anandkaranubc
Copy link
Contributor

Can you please change the title to:

bench: refactor random number generation in stats/base/dists/weibull

@anandkaranubc
Copy link
Contributor

Also, I am not sure if you have the most recent changes in your current branch. Try to update your branch with the latest changes so you can also apply the required changes to all the benchmark.native.js files. Good luck! :)

Comment on lines +48 to +50
x[ i ] = uniform( EPS, 100 );
lambda[ i ] = uniform( EPS, 100 );
k[ i ] = uniform( EPS, 100 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved outside the benchmarking loops in a different loop before b.tic()

Since random generation is expensive, we don't want it to interfere with the benchmarks. You can see the reference PRs. Also, this change is consistent throughout the whole PR.

lambda = ( randu()*100.0 ) + EPS;
k = ( randu()*100.0 ) + EPS;
y = cdf( x, k, lambda );
for ( i = 0; i < len; i++ ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for ( i = 0; i < len; i++ ) {
for ( i = 0; i < b.iterations; i++ ) {

The range remains the same.

x[ i ] = uniform( EPS, 100 );
lambda[ i ] = uniform( EPS, 100 );
k[ i ] = uniform( EPS, 100 );
y = cdf( x[ i%len ], k[ i%len ], lambda[ i%len ] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
y = cdf( x[ i%len ], k[ i%len ], lambda[ i%len ] );
y = cdf( x[ i % len ], k[ i % len ], lambda[ i % len ] );

k = ( randu()*100.0 ) + EPS;
y = cdf( x, k, lambda );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( EPS, 100 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x[ i ] = uniform( EPS, 100 );
x[ i ] = uniform( EPS, 100.0 );

Comment on lines 73 to +82
lambda = 3.14;
k = 2.25;
mycdf = cdf.factory( k, lambda );
len = 100;

x = new Float64Array( len );
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100.0 ) + EPS;
y = mycdf( x );
x[ i ] = uniform( EPS, 100.0 );
y = mycdf( x[ i%len ] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	lambda = 3.14;
	k = 2.25;
	len = 100
	mycdf = cdf.factory( k, lambda );
	x = new Float64Array( len );
	for ( i = 0; i < len; i++ ) {
		x = uniform( EPS, 100.0 );
	}

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		y = mycdf( x[ i % len ] );

Make sure to follow consistent spacing, following the code conventions.

@anandkaranubc anandkaranubc added the Needs Changes Pull request which needs changes before being merged. label Feb 3, 2025
@stdlib-bot stdlib-bot added the Statistics Issue or pull request related to statistical functionality. label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Changes Pull request which needs changes before being merged. Statistics Issue or pull request related to statistical functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: Refactor random number generation in JS benchmarks for stats/base/dists/weibull
3 participants