-
Notifications
You must be signed in to change notification settings - Fork 53
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
Allow obtaining the mean of a distribution #285
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #285 +/- ##
==========================================
+ Coverage 82.89% 82.98% +0.09%
==========================================
Files 52 52
Lines 14947 15000 +53
==========================================
+ Hits 12390 12448 +58
+ Misses 2557 2552 -5 ☔ View full report in Codecov by Sentry. |
I'm not sure how the 'there must be at least one part in a dist' error can be produced; I assume it's a failsafe prevented by parsing (e.g. |
probably too annoying to implement for the little performance difference in most scenarios(aspecially because of how poor the performance of dice is to begin with) but to get the mean for dice it can just be (dice.sum()+dice.len())/2 via some simple logic about how the distribution is in the center always, and wouldn't mode/median be the same as mean? unless there are non dice distributions then it makes sense |
I realize that I implemented the mean calculation incorrectly; the current formula should work for all currently supported distributions, but a skewed distribution will have an incorrect mean due to the formula not accounting for probabilities. The correct calculation is more like the following, with no division at the end: result = Exact::new(k, true)
.mul(&Exact::new(Complex::from(Real::from(v)), true), int)?
.add(result, int)?; The big rational to real to complex to exact conversion is a bit verbose, so if there's a more direct way I can do this, I can use that method instead. |
Thanks for the PR! It is actually already possible to generate skewed distributions with fend, for example:
Would you be able to fix this bug and add a test case for it?
The code coverage checks are just to remind people to write the occasional test. There's no need to worry about small areas of missed coverage like that.
You're right, there's no shorter way to do that conversion atm unfortunately. |
Thank you! I had a feeling there was something I missed that would allow for skewed distributions. In that case, I've committed the fix along with test cases. |
Fixes #284