You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#TODO should become an atomic int when we care about multithreading
const AnyBool = Union{Dist{Bool}, Bool}
#TODO should become an atomic int when we care about multithreading
global_flip_id::Int64=one(Int64)
# number field on 'sampling branch'# Compilation into wbf# The struct def for constructing a new Boolean variable f with the given probability# so you can assign f = Flip(0.6, "x") --> f is a new probabilistic Boolean variable mutable struct Flip <:Dist{Bool}const global_id::Int
prob
const name
## NEW ## - note that bit_index 0 = MSB
bit_index::Union{Nothing, Int}
ordering::Int## End NEW ##Flip(prob, name, bit_index) =beginif prob isa Real
@assert!isone(prob) "Use `true` for deterministic flips"@assert!iszero(prob) "Use `false` for deterministic flips"@assertisnan(prob) ||0< prob <1"Probabilities are between 0 and 1 (or undefined as NaN)"endglobal global_flip_id
id = global_flip_id+=1new(id, prob, name, bit_index, id)
endend# Modified SHOW to include orderingsfunction Base.show(io::IO, f::Flip)
p = f.prob
p =if p isa AbstractFloat round(p, digits=2) else p endifisnothing(f.name)
print(io, "$(typeof(f))($(f.global_id),$(p), ordering=$(f.ordering)), bit_index=$(f.bit_index))")
elseprint(io, "$(typeof(f))($(f.global_id),$(p),$(f.name), ordering=$(f.ordering)), bit_index=$(f.bit_index))")
endend# function Base.show(io::IO, f::Flip)# p = f.prob# p = if p isa AbstractFloat round(p, digits=2) else p end# if isnothing(f.name)# print(io, "$(typeof(f))($(f.global_id),$(p))")# else# print(io, "$(typeof(f))($(f.global_id),$(p),$(f.name))")# end# end"Create a Bernoulli random variable with the given probability (a coin flip)"# C-FLIP (coin flip compilation)# (is returned from this function?)functionflip(prob =NaN16; name =nothing, bit_index =nothing)
if prob isa Real
iszero(prob) &&returnfalseisone(prob) &&returntrueendFlip(prob, name, bit_index)
end"Set the probability of a flip that has not been assigned a probability yet"
The text was updated successfully, but these errors were encountered:
The struct def for constructing a new Boolean variable f with the given probability
so you can assign f = Flip(0.6, "x") --> f is a new probabilistic Boolean variable
p = f.prob
p = if p isa AbstractFloat round(p, digits=2) else p end
if isnothing(f.name)
print(io, "$(typeof(f))($(f.global_id),$ (p))")
else
print(io, "$(typeof(f))($(f.global_id),$ (p),$(f.name))")
end
end
(is returned from this function?)
Dice.jl/src/dist/bool.jl
Line 10 in 9cb0217
The text was updated successfully, but these errors were encountered: