Skip to content

Commit

Permalink
Revert "Make Bernoulli produce Bools (#1079)"
Browse files Browse the repository at this point in the history
This reverts commit 7a2f516.
  • Loading branch information
matbesancon committed Mar 18, 2020
1 parent 7a2f516 commit 0574a0f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
HypothesisTests = "09f84164-cd44-5f33-b23f-e6b0d136a0d5"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
HypothesisTests = "09f84164-cd44-5f33-b23f-e6b0d136a0d5"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Calculus", "Distributed", "FiniteDifferences", "ForwardDiff", "JSON", "StaticArrays", "HypothesisTests", "Test"]
test = ["Calculus", "Distributed", "FiniteDifferences", "ForwardDiff", "JSON",
"StaticArrays", "HypothesisTests", "Test"]
10 changes: 4 additions & 6 deletions src/univariate/discrete/bernoulli.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ end
Bernoulli(p::Integer) = Bernoulli(float(p))
Bernoulli() = Bernoulli(0.5, check_args=false)

@distr_support Bernoulli false true

Base.eltype(::Type{<:Bernoulli}) = Bool
@distr_support Bernoulli 0 1

#### Conversions
convert(::Type{Bernoulli{T}}, p::Real) where {T<:Real} = Bernoulli(T(p))
Expand Down Expand Up @@ -85,11 +83,11 @@ pdf(d::Bernoulli, x::Bool) = x ? succprob(d) : failprob(d)
pdf(d::Bernoulli, x::Int) = x == 0 ? failprob(d) :
x == 1 ? succprob(d) : zero(d.p)

cdf(d::Bernoulli, x::Bool) = x ? one(d.p) : failprob(d)
cdf(d::Bernoulli, x::Bool) = x ? failprob(d) : one(d.p)
cdf(d::Bernoulli, x::Int) = x < 0 ? zero(d.p) :
x < 1 ? failprob(d) : one(d.p)

ccdf(d::Bernoulli, x::Bool) = x ? zero(d.p) : succprob(d)
ccdf(d::Bernoulli, x::Bool) = x ? succprob(d) : one(d.p)
ccdf(d::Bernoulli, x::Int) = x < 0 ? one(d.p) :
x < 1 ? succprob(d) : zero(d.p)

Expand All @@ -106,7 +104,7 @@ cf(d::Bernoulli, t::Real) = failprob(d) + succprob(d) * cis(t)

#### Sampling

rand(rng::AbstractRNG, d::Bernoulli) = rand(rng) <= succprob(d)
rand(rng::AbstractRNG, d::Bernoulli) = rand(rng) <= succprob(d) ? 1 : 0

#### MLE fitting

Expand Down
4 changes: 2 additions & 2 deletions test/bernoulli.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Distributions
using Test, Random

@test rand(Bernoulli()) isa Bool
@test rand(Bernoulli(), 10) isa Vector{Bool}
@test typeof(rand(Bernoulli())) == Int
@test typeof(rand(Bernoulli(), 10)) == Vector{Int}

0 comments on commit 0574a0f

Please sign in to comment.