Skip to content

Implement std(::MultivariateDistribution) #1352

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

Merged
merged 7 commits into from
Apr 13, 2025

Conversation

bicycle1885
Copy link
Contributor

This implements std for multivariate distributions as an element-wise square root of variance: std(d) = sqrt.(var(d)).

@codecov-commenter
Copy link

codecov-commenter commented Jun 24, 2021

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.27%. Comparing base (8bb4181) to head (363bf57).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1352      +/-   ##
==========================================
+ Coverage   86.25%   86.27%   +0.01%     
==========================================
  Files         146      146              
  Lines        8766     8777      +11     
==========================================
+ Hits         7561     7572      +11     
  Misses       1205     1205              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

Seems reasonable! Can you also add std to the documentation of multivariate distributions?

@st--
Copy link
Contributor

st-- commented Oct 9, 2021

@bicycle1885 are you still interested in finishing this PR? @devmotion made a reasonable code suggestion that you would just need to accept, the other thing that seems missing is "add std to the documentation of multivariate distributions" - @devmotion could you clarify what you mean by that ?

Comment on lines 129 to 133
function std(d::MultivariateDistribution)
v = var(d)
map!(sqrt, v, v)
return v
end
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately, it seems in general var(d) might not be mutable - eg it can be a Fill array (eg for Dirichlet) or it could be a static array. So either

  • we live with these sometimes unnecessary allocations in the general fallback until Julia provides a native way to distinguish mutable and immutable arrays (similar to ArrayInterface) and demand that one has to implement a more efficient alternative for specific distributions if possible, or
  • we demand that var returns a mutable array in general and one has to implement std for distributions for which var is immutable.

Personally, I think it might be better to have a more efficient default implementation and eg. add a fix for Dirichlet.

Copy link
Member

Choose a reason for hiding this comment

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

@mschauer or @andreasnoack do you think it's fine to add a special case for Dirichlet or should it assume immutability by default? I suggested map! to reduce allocations (#1352 (comment)) but this is problematic for Dirichlet due since Fill arrays are not mutable.

@devmotion
Copy link
Member

@bicycle1885 are you still interested in finishing this PR? @devmotion made a reasonable code suggestion that you would just need to accept, the other thing that seems missing is "add std to the documentation of multivariate distributions" - @devmotion could you clarify what you mean by that ?

I addressed both. I also added a fix for Dirichlet, let's see if tests pass.

@st--
Copy link
Contributor

st-- commented Oct 27, 2021

@devmotion tests are passing, should it get merged now ?

@devmotion
Copy link
Member

devmotion commented Oct 27, 2021

I don't want to approve and merge my own changes. This does not feel right.

@azev77
Copy link
Contributor

azev77 commented Oct 28, 2021

@devmotion @st-- in open source ppl write PRs then forget about them, moving on to other things ALL THE TIME!
If we wait for people, we'll never get anything done

@devmotion devmotion merged commit da3a230 into JuliaStats:master Apr 13, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants