Generalize LocationScale to discrete distributions
#1286
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR generalizes
LocationScaleto discrete distributions. This change is motivated by the example in TuringLang/MCMCChains.jl#263: the distribution of the statistic of interest is a PoissonBinomial distribution whose support is scaled with a constant factor. It seems natural to reuse the existing implementation ofPoissonBinomial(which potentially can be more efficient than a regular DiscreteNonParametric distribution, as explained in #1285) instead of implementing a custom distribution for this use case.When I extended the tests, I noticed the surprising defaults for
(log)(c)cdffor discrete distributions which lead to bugs oflog(c)cdffor DiscreteNonParametric (and potentially other discrete distributions). I fixed the issue for DiscreteNonParametric in this PR but maybe the bugfix should be extracted to a separate PR. In general, I think it would be reasonable to remove the defaults and make(log)(c)cdfconsistent with(log)pdf: each distribution has to decide separately, for which inputs the functions are implemented and in particular if real numbers are rounded to integers.I moved
locationscale.jlto src/univariate/ in the first commit, so for reviewing it might be helpful to inspect the first and the other commits separately.