This repository has been archived by the owner on Apr 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from JuliaPOMDP/bool
added bool distribution
- Loading branch information
Showing
5 changed files
with
51 additions
and
0 deletions.
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
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
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,21 @@ | ||
""" | ||
BoolDistribution | ||
A distribution that provides the probabilities of true or false. | ||
Can construct with `BoolDistribution(p_true)`. | ||
""" | ||
struct BoolDistribution | ||
p::Float64 # probability of true | ||
end | ||
|
||
pdf(d::BoolDistribution, s::Bool) = s ? d.p : 1.0-d.p | ||
|
||
rand(rng::AbstractRNG, d::BoolDistribution) = rand(rng) <= d.p | ||
|
||
iterator(d::BoolDistribution) = [true, false] | ||
|
||
==(d1::BoolDistribution, d2::BoolDistribution) = d1.p == d2.p | ||
|
||
Base.hash(d::BoolDistribution) = hash(d.p) | ||
|
||
Base.length(d::BoolDistribution) = 2 |
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
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,21 @@ | ||
using POMDPToolbox | ||
using Base.Test | ||
|
||
# Hack to get this to build with POMDPModels | ||
# this can be removed once BoolDistribution is removed from POMDPModels | ||
BoolDistribution = POMDPToolbox.BoolDistribution | ||
|
||
# testing constructor and pdf | ||
d = BoolDistribution(0.3) | ||
@test pdf(d, true) == 0.3 | ||
@test pdf(d, false) == 0.7 | ||
|
||
# testing iterator | ||
@test iterator(d) == [true, false] | ||
|
||
# testing == | ||
d2 = BoolDistribution(0.3) | ||
@test d == d2 | ||
|
||
# testing hash | ||
@test hash(d) == hash(d.p) |