-
Notifications
You must be signed in to change notification settings - Fork 422
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
Add Censored distribution #1470
Merged
+951
−7
Merged
Changes from 1 commit
Commits
Show all changes
138 commits
Select commit
Hold shift + click to select a range
2d2b82c
Implement Censored
sethaxen eba2355
Export Censored and censored
sethaxen 12786be
Apply suggestions from code review
sethaxen ad80bc0
Reorganize code
sethaxen b9a9d23
Move check to constructor
sethaxen 066d15e
Make newline optional
sethaxen c111081
Reformat
sethaxen ec24f3c
Improve show method
sethaxen 97db2f5
Add checks for finiteness
sethaxen 744133b
Implement expectations
sethaxen 1ffed7a
Satisfy required params behavior
sethaxen e9b37cc
Overload truncated for DiscreteUniform
sethaxen 805211c
Don't re-censor
sethaxen 21194d6
Handle case where censored to single point
sethaxen 74d5228
Reformat
sethaxen 1123bd1
Add censored docs page
sethaxen d6f293c
Update censored.md
sethaxen 3d5ae7d
Document censored
sethaxen c555075
Add truncated DiscreteUniform tests
sethaxen d9a1ff3
Add un-called truncated_uniform test suite
sethaxen ae5fa7c
Skip check for DiscreteUniform
sethaxen 3dfbd72
Add loglikelihood
sethaxen e9aa316
Include bounds in support
sethaxen da70bc9
Update src/truncated/discrete_uniform.jl
sethaxen a6204b4
Remove unnecessary checks for finiteness
sethaxen ea7e77a
Swap order of checks
sethaxen 2609bd0
Update censored.jl
sethaxen 40afb67
Support using missing to specify unbounded
sethaxen d8830e1
Merge branch 'master' into censored
sethaxen 5c21d83
Apply suggestions from code review
sethaxen 36c3e7b
Improve docstrings
sethaxen 2b8c621
Reformat
sethaxen 7ac66f6
Rewrap signature
sethaxen ba1cdd3
Use ismissing everywhere
sethaxen 595c227
Reformat
sethaxen 9760a93
Fix maximum
sethaxen abfca6d
Fix support check
sethaxen 8be8573
Support fields that are equivalent
sethaxen f8c5171
Add basic censored tests
sethaxen 5ef0974
Apply suggestions from code review
sethaxen a40b2b8
Resolve ambiguity
sethaxen 791795c
Resolve ambiguity
sethaxen 06db648
Use equivalence check for missing everywhere
sethaxen f140cb6
Fix ccdf and logccdf
sethaxen f21afba
Better construct mixture equivalent
sethaxen 90dba2d
Implement mixture model for continuous censored dists
sethaxen a972a55
Add uniform tests
sethaxen 5a383ea
Enhance discrete uniform tests
sethaxen 14e4f79
Add Poisson tests
sethaxen 3f48e7f
Fix implementation of entropy
sethaxen 66f4735
Test mean/std of censored Poisson
sethaxen 29be974
Add normal tests
sethaxen ad6d76a
Remove unused methods
sethaxen 7391d13
Test bounds check
sethaxen 5a9b598
Add log-likelihood test
sethaxen 4ec91a0
Add test for censorship to empty interval
sethaxen 625d8d7
Support censorship to empty intervals
sethaxen a241067
Add comments about expectations
sethaxen 247d52b
Add more checks for inferrability
sethaxen e29bdb9
Test explicit expectations for DiscreteUniform
sethaxen cc19906
Rewrite censored docstring
sethaxen 7219dab
Indicate interval censoring
sethaxen f55d7e0
Update docs/src/index.md
sethaxen 6e11add
Apply suggestions from code review
sethaxen f926b62
Don't use now-deleted function
sethaxen cc4c3eb
Fix tes for new params definition
sethaxen 5630be0
Make loglikelihood type-stable
sethaxen b296aa9
Add comment about equivalence check
sethaxen 67c0259
Unabbreviate name
sethaxen e444b80
Remove inlines
sethaxen 87b68c2
Add plaintext mimetype
sethaxen a85bdca
Add more truncated DiscreteUniform tests
sethaxen f8bb1f7
Add xexpx
sethaxen 804eba9
Compute probabilities on log scale
sethaxen bed8267
Clarify variable names
sethaxen 73e5615
Eliminate deprecation warnings
sethaxen ff6d487
Fix inferrability error
sethaxen 3f79d2a
Reformat
sethaxen 9688143
Add check_args keyword
sethaxen d7b8eef
Merge branch 'master' into censored
sethaxen d778052
Promote each xi
sethaxen bb33140
Fix checking of args
sethaxen d1468a0
Use bounds also to set types
sethaxen 98c4b0b
Use check_args macro
sethaxen 70c2cd3
Check for ArgumentError
sethaxen 4547804
Use eps to detect empty truncation
sethaxen d2e20f4
Use more accurate variable name
sethaxen ac3b799
Use oneunit
sethaxen f024f45
Improve type-stability everywhere
sethaxen 768cfca
Exhaustively test for type-inferribility
sethaxen 16633c6
Remove now-unneeded test
sethaxen 72a6efb
Revert "Improve type-stability everywhere"
sethaxen f487cc6
Add convenient types
sethaxen 13b016f
Use convenient types
sethaxen f9457db
Add missing check for in support of uncensored
sethaxen e5e3246
Avoid promoting inputs based on bounds
sethaxen 5ac7dc7
Avoid promoting inputs based on bounds
sethaxen 6c0c789
Separate expectations to own methods
sethaxen f135580
Check in interval first
sethaxen 19a331f
Don't promote input types
sethaxen c712050
Apply suggestions from code review
sethaxen b4a1dda
Remove lingering reference to udnefined type
sethaxen 0fb63a9
Docstring fixes
sethaxen 286e8e6
Consistently use d0 for uncensored
sethaxen eb20f91
Use nothing instead of missing
sethaxen 386f779
Reorganize
sethaxen a11f0e8
Add keyword constructor
sethaxen 18085ac
Document and promote keyword constructors
sethaxen 125dee4
Use keyword arguments in show
sethaxen 72e6135
Don't use isnothing in tests
sethaxen ddde5cd
Don't print nothing
sethaxen ccef571
Export Censored
sethaxen 7af5e83
Once sentence per line
sethaxen f0342a0
Docstring improvements
sethaxen f155cda
Fix variable rendering
sethaxen d70e518
Add missing comma
sethaxen 6ed1e96
Revert "Export Censored"
sethaxen 399d9bf
Prepend with module so docs build
sethaxen 6062f7f
Document with module prepended
sethaxen e9d93a4
Use function ... end syntax
sethaxen d2759ad
Apply suggestions from code review
sethaxen c584c85
LeftCensored ⇌ RightCensored
sethaxen e41b221
Apply suggestions from code review
sethaxen 0273192
Introduce xexpy
sethaxen 63b03f0
Remove test for no-longer-supported case
sethaxen f323ae1
Simplify implementations
sethaxen f4e3aa0
Rearrange left before right
sethaxen 461c19a
Merge branch 'master' into censored
sethaxen cc4051b
Increment version number
sethaxen fcf9fbc
Use information theory notation for entropy
sethaxen c89458d
Use d0 notation
sethaxen b33f0f4
Add header
sethaxen 36f2430
Test infinite bounds just in case
sethaxen ba60409
Merge branch 'master' into censored
mschauer 68e5de2
Apply suggestions from code review
sethaxen 8308cda
Merge branch 'master' into censored
sethaxen a1e8fe3
Add and test partially truncated overloads for discrete uniform
sethaxen f632f10
Update src/censored.jl
sethaxen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add basic censored tests
commit f8c517171a833f4e210e01fe1da998d5eb9d0588
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Testing censored distributions | ||
|
||
module TestCensored | ||
|
||
using Distributions, Test | ||
using Distributions: Censored | ||
|
||
@testset "censored" begin | ||
d0 = Normal(0, 1) | ||
@test_throws ErrorException censored(d0, 1, -1) | ||
|
||
d = censored(d0, -1, 1.0) | ||
@test d isa Censored | ||
@test d.lower === -1.0 | ||
@test d.upper === 1.0 | ||
|
||
d = censored(d0, missing, -1) | ||
@test d isa Censored | ||
@test ismissing(d.lower) | ||
@test d.upper == -1 | ||
|
||
d = censored(d0, 1, missing) | ||
@test d isa Censored | ||
@test ismissing(d.upper) | ||
@test d.lower == 1 | ||
|
||
d = censored(d0, missing, missing) | ||
@test d === d0 | ||
end | ||
|
||
@testset "Censored" begin | ||
@testset "basic" begin | ||
d = Censored(Normal(0.0, 1.0), -1, 2) | ||
@test d isa Censored | ||
@test eltype(d) === Float64 | ||
@test params(d) === (params(Normal(0.0, 1.0))..., -1, 2) | ||
@test partype(d) === Float64 | ||
@test @inferred extrema(d) == (-1, 2) | ||
@test @inferred islowerbounded(d) | ||
@test @inferred isupperbounded(d) | ||
@test @inferred insupport(d, 0.1) | ||
@test insupport(d, -1) | ||
@test insupport(d, 2) | ||
@test !insupport(d, -1.1) | ||
@test !insupport(d, 2.1) | ||
@test sprint(show, "text/plain", d) == "Censored($(Normal(0.0, 1.0)), range=(-1, 2))" | ||
|
||
d = Censored(Cauchy(0, 1), missing, 2) | ||
@test d isa Censored | ||
@test eltype(d) === Base.promote_type(eltype(Cauchy(0, 1)), Int) | ||
@test params(d) == (params(Cauchy(0, 1))..., 2) | ||
@test partype(d) === Float64 | ||
@test extrema(d) == (-Inf, 2.0) | ||
@test @inferred !islowerbounded(d) | ||
@test @inferred isupperbounded(d) | ||
@test @inferred insupport(d, 0.1) | ||
@test insupport(d, -3) | ||
@test insupport(d, 2) | ||
@test !insupport(d, 2.1) | ||
@test sprint(show, "text/plain", d) == "Censored($(Cauchy(0.0, 1.0)), range=(missing, 2))" | ||
|
||
d = Censored(Gamma(1, 2), 2, missing) | ||
@test d isa Censored | ||
@test eltype(d) === Base.promote_type(eltype(Gamma(1, 2)), Int) | ||
@test params(d) == (params(Gamma(1, 2))..., 2) | ||
@test partype(d) === Float64 | ||
@test extrema(d) == (2.0, Inf) | ||
@test @inferred islowerbounded(d) | ||
@test @inferred !isupperbounded(d) | ||
@test @inferred insupport(d, 2.1) | ||
@test insupport(d, 2.0) | ||
@test !insupport(d, 1.9) | ||
@test sprint(show, "text/plain", d) == "Censored($(Gamma(1, 2)), range=(2, missing))" | ||
|
||
d = Censored(Binomial(10, 0.2), -1.5, 9.5) | ||
@test extrema(d) === (0.0, 9.5) | ||
@test @inferred islowerbounded(d) | ||
@test @inferred isupperbounded(d) | ||
@test @inferred !insupport(d, -1.5) | ||
@test insupport(d, 0) | ||
@test insupport(d, 9.5) | ||
@test !insupport(d, 10) | ||
|
||
@test censored(Censored(Normal(), 1, missing), missing, 2) == Censored(Normal(), 1, 2) | ||
@test censored(Censored(Normal(), missing, 1), -1, missing) == Censored(Normal(), -1, 1) | ||
@test censored(Censored(Normal(), 1, 2), 1.5, 2.5) == Censored(Normal(), 1.5, 2.0) | ||
@test censored(Censored(Normal(), 1, 3), 1.5, 2.5) == Censored(Normal(), 1.5, 2.5) | ||
@test censored(Censored(Normal(), 1, 2), 0.5, 2.5) == Censored(Normal(), 1.0, 2.0) | ||
@test censored(Censored(Normal(), 1, 2), 0.5, 1.5) == Censored(Normal(), 1.0, 1.5) | ||
|
||
@test censored(Censored(Normal(), missing, 1), missing, 1) == Censored(Normal(), missing, 1) | ||
@test censored(Censored(Normal(), missing, 1), missing, 2) == Censored(Normal(), missing, 1) | ||
@test censored(Censored(Normal(), missing, 1), missing, 1.5) == Censored(Normal(), missing, 1) | ||
@test censored(Censored(Normal(), missing, 1.5), missing, 1) == Censored(Normal(), missing, 1) | ||
|
||
@test censored(Censored(Normal(), 1, missing), 1, missing) == Censored(Normal(), 1, missing) | ||
@test censored(Censored(Normal(), 1, missing), 2, missing) == Censored(Normal(), 2, missing) | ||
@test censored(Censored(Normal(), 1, missing), 1.5, missing) == Censored(Normal(), 1.5, missing) | ||
@test censored(Censored(Normal(), 1.5, missing), 1, missing) == Censored(Normal(), 1.5, missing) | ||
end | ||
end | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
Testing eltype once we figured that part out.