-
Notifications
You must be signed in to change notification settings - Fork 421
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
Store nothing
bounds in Truncated
#1720
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #1720 +/- ##
==========================================
- Coverage 85.85% 85.83% -0.03%
==========================================
Files 138 138
Lines 8337 8350 +13
==========================================
+ Hits 7158 7167 +9
- Misses 1179 1183 +4
☔ View full report in Codecov by Sentry. |
@@ -1,7 +1,7 @@ | |||
name = "Distributions" | |||
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" | |||
authors = ["JuliaStats"] | |||
version = "0.25.90" | |||
version = "0.25.91" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a JuliaHub package search to see whether any packages might be relying on Truncated{D,S}
being concrete and/or using the bounds directly and assuming they're real-valued. Looks like we're in the clear for the former but there are a few registered packages that will break due to the latter: ModelConstructors, DiffEqBayes, and DiffEqBayesStan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that this is an internal change and things may break for downstream packages that access fields of (to be internal) structs that are not part of the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For instance, I don't think code such as in ModelConstructors is a reason to move this change to a breaking release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
access fields of (to be internal) structs
? I'm not sure what you mean by "to be internal" here.
I am generally of the opinion that if you touch the fields/properties of an object then you should expect to lose a finger at any moment. That said, it doesn't seem to be documented that these fields aren't public, though the fields themselves also aren't documented so perhaps it can be reasonably assumed that they aren't public.
I don't think code such as in ModelConstructors is a reason to move this change to a breaking release.
That's fair, but it could be worthwhile to submit PRs to the packages that will be affected by this change to ensure they use extrema
(or similar) instead to avoid any issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? I'm not sure what you mean by "to be internal" here.
I meant that generally I think these fields do not belong to any official API, so there are no guarantees at all and code that accesses them may break at any time, but that in this case even the whole struct is intended to be an internal implementation detail in the next breaking release. For backward compatibility, Truncated
is still exported but all outer constructors are already deprecated since users are supposed to call truncated
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think probably a middle ground would be good: Not exporting Truncated
anymore (since as long as it is exported, users will construct truncated distributions with available constructors of Truncated
even though it is deprecated and not recommended) but mentioning it in the docs as a fallback that can be dispatched on without any guarantees on the fields or type parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding your initial comment, I submitted PRs to the three affected packages: SciML/DiffEqBayes.jl#304, StanJulia/DiffEqBayesStan.jl#18, FRBNY-DSGE/ModelConstructors.jl#18
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the deprecated constructor methods are removed, the only remaining method for Truncated
is its inner constructor. If a user really wants to go through the trouble of computing all of the requisite quantities that get stored in Truncated
in order to pass them to the inner constructor, they either have a very good reason to do so or all hope is lost and they're simply an agent of chaos who will do as they please regardless of whether it's exported.
I'd recommend we continue to export Truncated
but add a note to its docstring that it isn't intended to be constructed directly and to use truncated
for that purpose (currently truncated
links to Truncated
but not vice versa), and that the fields are an implementation detail. The one guarantee it would be nice to make is that the first type parameter is a Distribution
but there may be more so don't assume Truncated{D}
is concrete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why export it if you should not use it? To me it seems more reasonable to not export it and only clearly state and document the guarantees on the fallback type (and hence make changes to them require a breaking release).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why export it if you should not use it?
IMO it's not that you shouldn't use it, just that you shouldn't assume that its constructor is The Way™ to obtain a truncated distribution.
The PR to ModelConstructors should not block this PR IMO since the latest tagged release of this package does not even support Distributions 0.25 it seems. It is also a bit unclear to me if it is still actively maintained given that there are no recent commits on the master branch. |
@ararslan Since the PRs to DiffEqBayes and DiffEqBayesStan are merged, do you think this PR is ready to be merged? |
const LeftTruncated{D<:UnivariateDistribution,S<:ValueSupport,T<:Real} = Truncated{D,S,T,T,Nothing} | ||
const RightTruncated{D<:UnivariateDistribution,S<:ValueSupport,T<:Real} = Truncated{D,S,T,Nothing,T} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps export these to accompany Truncated
? They seem generally useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this should be part of the PR, mainly for the following three reasons: 1) LeftCensored
/RightCensored
are not exported either, 2) It is easy to export them in a future non-breaking release but they can't be un-exported in a non-breaking release once they are exported, 3) Noy every left/right Truncated
distribution is of type LeftTruncated
/RightTruncated
.
Seems that 32cea9b#diff-0c632d946a50f0251329e7ba1bc19ab4e19bd0f1815607122fc8ef30efe4dadbL15-L16 is causing the type inference tests added by #1717 to fail. With those more specific definitions, the extrema of a truncated normal with |
Unfortunate that this was not discovered before merging the PR. I think removing the specialization in this PR is correct - why should Another question is, of course, whether we want |
Yeah I agree, I only mention it because it seems to be the cause of the issue. I'm mostly indifferent on what |
This PR adds support for
nothing
bounds inTruncated
: While they are supported (and in fact encouraged) bytruncated
for specifying left- or right-truncated distributions, currently they are not stored inTruncated
as given but instead converted to and saved as+Inf
/-Inf
.This loss of information is not only surprising but also problematic whenever specializations with specialized return types for left- or right-truncated distributions are needed. For instance, one application (in a private repo) is Bayesian inference in which different transformations of the support are required depending on whether the support of a truncated normal distribution is lower- and/or upper-bounded.
The PR uses the same approach (and also some of the code) that is already used for
censored
/Censored
.