Skip to content

Commit

Permalink
fixing probability bug v0.1.1-v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
bdoolittle committed Feb 24, 2021
1 parent 3f1482f commit 6b4562b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QBase"
uuid = "e52e8ede-12bf-4731-8af7-b01f6064cb11"
authors = ["Brian Doolittle <brian.d.doolittle@gmail.com> and contributors"]
version = "0.1.1"
version = "0.1.2"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Expand Down
4 changes: 2 additions & 2 deletions src/QMath/probability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Returns `true` if the provided vector is a valid probability distribution:
* `p[i] ≥ 0 ∀ i`
"""
function is_probability_distribution(probabilities::Vector)::Bool
is_positive = all(p -> (p > 0) || isapprox(p,0, atol=10e-7), probabilities)
is_normalized = (sum(probabilities) 1)
is_positive = all(p -> (p > 0) || isapprox(p, 0, atol=10e-7), probabilities)
is_normalized = isapprox(sum(probabilities), 1, atol=10e-6)

(is_positive & is_normalized)
end
Expand Down
5 changes: 5 additions & 0 deletions test/unit/QMath/probability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ end
@test conditionals isa QMath.Conditionals
end

@testset "inexact edge case" begin
conditionals = QMath.Conditionals([0.666667 0.166667 0.166667; 0.166667 0.666667 0.166667; 0.166667 0.166667 0.666667])
@test conditionals == [0.666667 0.166667 0.166667; 0.166667 0.666667 0.166667; 0.166667 0.166667 0.666667]
end

@testset "invalid cases" begin
@test_throws DomainError QMath.Conditionals([0.5 -0.5;0.5 1.5])
end
Expand Down

2 comments on commit 6b4562b

@bdoolittle
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/30750

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.2 -m "<description of version>" 6b4562b75143cb08a7fd18a55bb91970c2aec3bc
git push origin v0.1.2

Please sign in to comment.