-
Notifications
You must be signed in to change notification settings - Fork 3
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 #41 from charles-river-analytics/develop
New Release. Build succeeds other than nightly.
- Loading branch information
Showing
15 changed files
with
329 additions
and
15 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
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
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,123 @@ | ||
# Continuous uniform sfunc | ||
|
||
export Uniform | ||
|
||
import Distributions | ||
|
||
mutable struct Uniform <: Dist{Float64} | ||
params :: Tuple{Float64, Float64} | ||
Uniform(l, u) = new((l,u)) | ||
end | ||
|
||
lb(u::Uniform) = u.params[1] | ||
ub(u::Uniform) = u.params[2] | ||
|
||
mean(u::Uniform) = (lb(u) + ub(u)) / 2.0 | ||
|
||
sd(u::Uniform) = (ub(u) - lb(u)) / sqrt(12.0) | ||
|
||
dist(u::Uniform) = Distributions.Uniform(lb(u), ub(u)) | ||
|
||
@impl begin | ||
struct UniformSupport end | ||
function support( | ||
sf::Uniform, | ||
::NTuple, | ||
size::Integer, | ||
curr::Vector{Float64} | ||
) | ||
newsize = size - length(curr) | ||
result = curr | ||
if newsize > 0 | ||
x = lb(sf) | ||
push!(result, x) | ||
numsteps = newsize - 1 | ||
step = (ub(sf) - lb(sf)) / numsteps | ||
for i in 1:numsteps | ||
x += step | ||
push!(result, x) | ||
end | ||
end | ||
unique(result) | ||
end | ||
end | ||
|
||
|
||
@impl begin | ||
struct UniformSupportQuality end | ||
function support_quality(::Uniform, parranges) | ||
:IncrementalSupport | ||
end | ||
end | ||
|
||
|
||
@impl begin | ||
struct UniformSample end | ||
function sample(sf::Uniform, x::Tuple{})::Float64 | ||
rand(dist(sf)) | ||
end | ||
end | ||
|
||
@impl begin | ||
struct UniformLogcpdf end | ||
function logcpdf(sf::Uniform, i::Tuple{}, o::Float64)::AbstractFloat | ||
Distributions.logpdf(dist(sf), o) | ||
end | ||
end | ||
|
||
@impl begin | ||
struct UniformBoundedProbs end | ||
|
||
# assumes range is sorted | ||
function bounded_probs( | ||
sf::Uniform, | ||
range::Vector{Float64}, | ||
::NTuple | ||
) | ||
l = lb(sf) | ||
u = ub(sf) | ||
d = u - l | ||
n = length(range) | ||
|
||
# Each element in the range is associated with the interval between the midpoint | ||
# of it and the point below and the midpoint between it and the point above, | ||
# except for the end intervals which go to negative or positive infinity. | ||
points = [-Inf64] | ||
for i in 2:n | ||
push!(points, (range[i-1] + range[i]) / 2) | ||
end | ||
push!(points, Inf64) | ||
|
||
# Each interval might be completely, partially, or not contained in the bounds | ||
# of the uniform distribution. The following code determines the length of each | ||
# interval that is in the bounds. | ||
lengthsinbound = Float64[] | ||
for i in 1:n | ||
a = max(points[i], l) | ||
b = min(points[i+1], u) | ||
push!(lengthsinbound, max(b-a, 0.0)) | ||
end | ||
|
||
ps = [lengthsinbound[i] / d for i in 1:n] | ||
return (ps, ps) | ||
end | ||
|
||
end | ||
|
||
@impl begin | ||
struct UniformComputePi end | ||
|
||
function compute_pi(sf::Uniform, | ||
range::Vector{Float64}, | ||
::NTuple, | ||
::Tuple)::Cat{Float64} | ||
|
||
ps = bounded_probs(sf, range, ())[1] | ||
Cat(range, ps) | ||
end | ||
end | ||
|
||
|
||
|
||
|
||
|
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 |
---|---|---|
@@ -1,17 +1,32 @@ | ||
# Default implementations of basic operators | ||
#= | ||
# Default implementations of operators. These are defined using other operators. | ||
# They will always be called if a more specific implementation is not provided. | ||
# If the operators they rely on are not implemented, they will produce a runtime error. | ||
# Writers of default implementations should avoid infinite loops. | ||
=# | ||
|
||
# cpdf and logcpdf have default operators in terms of the other. Sfuncs should implement one or the other. | ||
# if forward is defined, we get a default implementation of sample | ||
@impl begin | ||
struct DefaultSample end | ||
# This should not produce an infinite loop, because a dist should not implement forward, | ||
# since forwards maps a parent to a dist, but here the parent is empty. | ||
function sample(sf::SFunc{I,O}, i::I)::O where {I,O} | ||
d = forward(sf, i) | ||
return sample(d, tuple()) | ||
end | ||
end | ||
|
||
@impl begin | ||
struct SFuncCpdf end | ||
function cpdf(sf::SFunc{I,O}, i::I, o::O)::AbstractFloat where {I,O} | ||
exp(logcpdf(sf, i, o)) | ||
end | ||
end | ||
|
||
@impl begin | ||
struct SFuncLogcpdf end | ||
function logcpdf(sf::SFunc{I,O}, i::I, o::O)::AbstractFloat where {I,O} | ||
log(cpdf(sf, i, o)) | ||
end | ||
end | ||
|
||
# TODO: Create default implementations of compute_pi and send_lambda | ||
# TODO: Create weighted_sample operator with default implementation using inverse |
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,15 @@ | ||
# MultipleScore lets you assert multiple evidence on the same variable | ||
export MultipleScore | ||
|
||
struct MultipleScore{I} <: Score{I} | ||
components :: Vector{<:Score{I}} | ||
end | ||
|
||
function get_log_score(ms::MultipleScore{I}, i::I) where I | ||
tot = 0.0 | ||
for m in ms.components | ||
tot += get_log_score(m, i) | ||
end | ||
tot | ||
end | ||
|
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 |
---|---|---|
|
@@ -215,4 +215,4 @@ wienerprocess = WienerProcess(0.1) | |
end | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.
37e4282
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.
@JuliaRegistrator register
37e4282
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.
Registration pull request created: JuliaRegistries/General/103435
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
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: