Skip to content

[BUG]: C implementation for stats/base/dists/kumaraswamy/median has different results than the JavaScript implementation #5047

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

Closed
2 tasks done
anandkaranubc opened this issue Feb 3, 2025 · 16 comments · Fixed by #5452
Labels
Bug Something isn't working. Math Issue or pull request specific to math functionality. Numerical Accuracy Issue or pull request concerns numerical accuracy. Statistics Issue or pull request related to statistical functionality.

Comments

@anandkaranubc
Copy link
Contributor

Description

Pointed out by @Neerajpathak07 and @yuvi-mittal

For context, see comment

When running native tests for stats/base/dists/kumaraswamy/median, the majority of tests fail because the C implementation is generalized for a single value of a = 1.0 rather than any positive number.

The fix is to change

return 1.0 - stdlib_base_pow( 0.5, 1.0 / b );

to:

return stdlib_base_pow( 1.0 - stdlib_base_pow( 2.0, -1.0 / b ), 1.0 / a );

Related Issues

None

Questions

No.

Demo

No response

Reproduction

- Run `make install-node-addons NODE_ADDONS_PATTERN="stats/base/dists/kumaraswamy/median"`
- Run `make test TESTS_FILTER=".*/stats/base/dists/kumaraswamy/median/test/test.native.js"`

Expected Results

total:     1009
passing:   1009

Actual Results

total:     1009
passing:   27
failing:   982

Version

No response

Environments

N/A

Browser Version

No response

Node.js / npm Version

No response

Platform

No response

Checklist

  • Read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
@anandkaranubc anandkaranubc changed the title C implementation for stats/base/dists/kumaraswamy/median has different results than the JavaScript implementation [BUG]: C implementation for stats/base/dists/kumaraswamy/median has different results than the JavaScript implementation Feb 3, 2025
@anandkaranubc anandkaranubc added Bug Something isn't working. Statistics Issue or pull request related to statistical functionality. labels Feb 3, 2025
@anandkaranubc
Copy link
Contributor Author

@Neerajpathak07, do you want to proceed with a PR targeting this issue?

@anandkaranubc anandkaranubc added Numerical Accuracy Issue or pull request concerns numerical accuracy. Math Issue or pull request specific to math functionality. labels Feb 3, 2025
@kgryte
Copy link
Member

kgryte commented Feb 4, 2025

There were a lot of issues with the PR adding the C implementation which were missed during code review. See fc5df17. Someone should take a close look at that package to determine whether everything is correct.

cc @Planeshifter

@kgryte
Copy link
Member

kgryte commented Feb 4, 2025

Also, the tests in test.native.js still don't fully match what is in test.js.

@anandkaranubc
Copy link
Contributor Author

Someone should take a close look at that package to determine whether everything is correct.

I will take a detailed look and update this issue. If it turns out to be a major change, I will likely create a PR to address it.

@Neerajpathak07
Copy link
Contributor

@Neerajpathak07, do you want to proceed with a PR targeting this issue?

Ig @yuvi-mittal has started working upon it after I pointed out what was wrong.

@yuvi-mittal
Copy link
Contributor

I have already started working on it , and i have been checking rest of the distributions too , there are few test cases more that are failing , will raise a PR soon.

@anandkaranubc
Copy link
Contributor Author

@yuvi-mittal Any updates on this :)

@yuvi-mittal
Copy link
Contributor

@anandkaranubc , hey i have been swamped with some college work ,i will get it done before eow.

@anandkaranubc
Copy link
Contributor Author

@anandkaranubc , hey i have been swamped with some college work ,i will get it done before eow.

No rush! Just wanted to check in to see if you needed any help. Good luck with your work!

@Krishna-Sharma-g
Copy link
Contributor

i changed the return statement and all test cases got passed so wanted to making a pr on it @anandkaranubc can i still pr on it

Image

@anandkaranubc
Copy link
Contributor Author

Hey @Krishna-Sharma-g, thanks for working on this and getting all test cases to pass! @yuvi-mittal, just checking in—are you still working on this? If not, he can open a PR.

@Krishna-Sharma-g
Copy link
Contributor

okay @anandkaranubc

@yuvi-mittal
Copy link
Contributor

@Krishna-Sharma-g , You can open a PR , no worries . The goal is to get work done as fast as possible.

@anandkaranubc
Copy link
Contributor Author

@Krishna-Sharma-g, when creating a PR, please also consider the points mentioned by Athan in the discussions here and here.

Here is a reference PR to confirm whether you are on the right track: #3354

@Krishna-Sharma-g
Copy link
Contributor

Krishna-Sharma-g commented Feb 25, 2025

hello @anandkaranubc as mentioned by @kgryte that test.native.js not fully matches the test.js so there are the mismatched things in it

1.there is incorrectly named test that was referring to "gamma" instead of "a" by completely replacing it with the proper test for
nonpositive "a" parameter from test.js.

3.Added the missing test for nonpositive "b" parameter, copying the test cases from test.js.

4.Ensured all edge cases are properly tested with the same combinations of parameter values as in test.js.
Maintained the native-specific parts like the tryRequire setup and opts variable for test skipping.

please tell me that is that what @kgryte is talking about

@anandkaranubc
Copy link
Contributor Author

Awesome! As long as test.native.js closely matches the test.js file with only minor modifications, it should be good. In addition to the test file changes, please carefully review this commit to ensure that the comments have been addressed. Also, we probably also need to check that the C-related files align closely with the changes made in the reference PR: #3354.

Feel free to submit a PR addressing all of this, and then I believe @Neerajpathak07 and @yuvi-mittal can also join the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working. Math Issue or pull request specific to math functionality. Numerical Accuracy Issue or pull request concerns numerical accuracy. Statistics Issue or pull request related to statistical functionality.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants