scipy icon indicating copy to clipboard operation
scipy copied to clipboard

ENH: stats: Implement _munp() for the skewnorm distribution.

Open WarrenWeckesser opened this issue 2 years ago • 8 comments

The skew-normal distribution has a moment-generating function from which we can derive the noncentral moments. This allows _munp(order, a), the method of the rv_continuous class that computes the "standard" (i.e. loc=0, scale=1) noncentral moment, to be implemented. This is much faster and more accurate than the default method, which uses scipy.integrate.quad to compute the moments.

WarrenWeckesser avatar Jun 30 '22 14:06 WarrenWeckesser

#16487 has been merged, if you rebase or merge with upstream you should be able to remove the pytest.mark.timeout mark here:

https://github.com/scipy/scipy/blob/fb0d2d2c8130963b7e49c580a8e261162f57f137/scipy/stats/tests/test_continuous_basic.py#L269

larsoner avatar Jun 30 '22 14:06 larsoner

@larsoner wrote

you should be able to remove the pytest.mark.timeout mark

Done. I left the code for handling custom marks in test_moments, with a comment about how it might be used again in the future. It could all be removed instead, now that it is not being used; I'm fine with that option too.

WarrenWeckesser avatar Jun 30 '22 21:06 WarrenWeckesser

Either way is fine by me. It'll be great just to see this come back green, it'll be a nice speedup!

larsoner avatar Jun 30 '22 21:06 larsoner

It'll be great just to see this come back green...

I don't expect this latest commit to come back all green, because of a recurring unrelated failure in sparse.linalg that is happening in the Main prerelease_deps_coverage_64bit_blas job.

WarrenWeckesser avatar Jun 30 '22 21:06 WarrenWeckesser

The Main prerelease_deps_coverage_64bit_blas job is passing now (thanks @rgommers!), but now the Azure job Main source_distribution is failing in all the PRs.

WarrenWeckesser avatar Jul 03 '22 21:07 WarrenWeckesser

but now the Azure job Main source_distribution is failing in all the PRs.

already fixed by gh-16541

rgommers avatar Jul 04 '22 09:07 rgommers

@tupui, thanks for the review! I have responded to your suggestions, and after merging main to resolve conflicts, I pushed some updates that address your comments.

If/when this gets merged, the commits should be squashed into one commit. The commit message from the first commit (header line and body) are still probably all that is needed in the squashed commit message.

(The CI failures are not related to the changes made here.)

WarrenWeckesser avatar Aug 10 '22 10:08 WarrenWeckesser

FWIW and from 30 thousand feet, I'd welcome this sorts of scripts. They are a big help in "what are these magic coefficients and where did they come from" situations. Where to keep them, a folder named _precompute looks reasonable to me, it's a single ls-l away. A different easily discoverable place would work too, though. Not sure what that would be?

ev-br avatar Aug 10 '22 13:08 ev-br

But the code itself is not good for all that. It just make the boat heavier.... @mdhaber do you have an opinion on this?

Yes, this is one of the things I hoped you would comment on. I confirmed these coefficients by writing my own code to generate them independently, so I don't think should also have to review line-by-line the code used by the author to generate them - especially if it's a script that itself writes Python code. I think it's is valuable code, but I don't think it belongs here in SciPy proper.

The lru_cache was another thing that concerned me, and so was the use of δ in the code. Both of those were removed, so that's good. I'm still not a fan of rewriting and - without comment - refactoring factorial2, but it seems to be correct, so I'll go ahead and merge.

mdhaber avatar Aug 16 '22 17:08 mdhaber