Skip to content

feat: add stats/base/dists/bradford/skewness #6401

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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

vivekmaurya001
Copy link
Contributor

Progresses #168.

This pull request:

  • add stats/base/dists/bradford/skewness

Related Issues

Does this pull request have any related issues?

This pull request:

  • resolves #{{TODO: add issue number}}

Questions

Any questions for reviewers of this pull request?

No.

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

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: passed
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: passed
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Mar 26, 2025
@vivekmaurya001
Copy link
Contributor Author

/stdlib update-copyright-years

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Mar 26, 2025
@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Mar 26, 2025
@vivekmaurya001
Copy link
Contributor Author

currently there are 10 test cases which fail at tolerance factor of 50, but these cases persists even I increase the factor to 1e4

Screenshot from 2025-03-26 21-09-18

@vivekmaurya001
Copy link
Contributor Author

@anandkaranubc , @kgryte , Any suggestion on this

@anandkaranubc
Copy link
Contributor

@vivekmaurya001, that's the main reason I didn’t submit my PRs on skewness and kurtosis — they lead to large divergent results due to ("My Hypothesis"):

  1. A lot of calculations being performed, which causes floating-point precision errors.
  2. The shape parameter being very small, leading to differences in the ln calculations compared to the reference (SciPy) implementation.
  3. The expected values being very small.

These are my local results:

  • For small c: tol = 930226.0 * EPS * abs(expected[i])
  • For large c: tol = 600.0 * EPS * abs(expected[i])

There are actually two ways to implement this:

k = ln(1.0 + c);
out = SQRT2;
out *= ( (12.0*c*c) - (9.0*k*c*(c+2.0)) + (2.0*k*k*(c*(c+3.0)+3.0)) );
out /= sqrt(c * (c*(k-2.0) + (2.0*k)));
out /= ( (3.0*c*(k-2.0)) + (6.0*k) );
return out;

or

var g1 = SQRT2 * (12*c*c - 9*c*k*(c+2) + 2*k*k*(c*(c+3)+3));
g1 /= sqrt(c*(c*(k-2)+2*k)) * (3*c*(k-2) + 6*k);
return g1;

The second one gives better results than the first. Here, better results mean less divergence from SciPy.

That said, I think we might need to check if there have been any changes in the upstream implementations of ln or log1p, and update ours if needed.

cc: @kgryte

@vivekmaurya001
Copy link
Contributor Author

Yess, Also the scipy docs are using log(1+c) instead of log1p

@anandkaranubc
Copy link
Contributor

anandkaranubc commented Mar 26, 2025

Yess, Also the scipy docs are using log(1+c) instead of log1p

Would you mind checking the upstream implementation of ln to see if there's any difference? If there is, create an issue and we can sync up on that.

FreeBSD implementation
Our implementation

@vivekmaurya001
Copy link
Contributor Author

Sure I will try it first

@vivekmaurya001
Copy link
Contributor Author

@anandkaranubc , I found some slight differences in lg2, lg3 etc values in free bsd and our, I tried correcting it and running but still not improved, apart from this all looked same

@anandkaranubc
Copy link
Contributor

anandkaranubc commented Mar 26, 2025

@anandkaranubc , I found some slight differences in lg2, lg3 etc values in free bsd and our, I tried correcting it and running but still not improved, apart from this all looked same

Could you create a separate issue for this so we can tackle it there and get some feedback? It might also be worthwhile to check how SciPy has implemented ln.

Edit: Are you sure about that?

The values seem the same to me:

// Polynomial coefficients ordered in ascending degree...
var P = [
3.999999999940941908e-01, // 3FD99999 9997FA04
2.222219843214978396e-01, // 3FCC71C5 1D8E78AF
1.531383769920937332e-01 // 3FC39A09 D078C69F
];
var Q = [
6.666666666666735130e-01, // 3FE55555 55555593
2.857142874366239149e-01, // 3FD24924 94229359
1.818357216161805012e-01, // 3FC74664 96CB03DE
1.479819860511658591e-01 // 3FC2F112 DF3E5244
];

@vivekmaurya001
Copy link
Contributor Author

vivekmaurya001 commented Mar 27, 2025

Oops yes, I realised some last digits were not matching

@vivekmaurya001
Copy link
Contributor Author

Added ln logic instead of log1p and TODO comment in test file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review A pull request which needs code review. Statistics Issue or pull request related to statistical functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants