Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dirichlet type #524

Merged
merged 2 commits into from
Mar 28, 2024
Merged

Fix dirichlet type #524

merged 2 commits into from
Mar 28, 2024

Conversation

deoxyribose
Copy link
Contributor

@deoxyribose deoxyribose commented Mar 28, 2024

Before

using Gen

@gen function rand_prob_vec()
    prob_vec ~ dirichlet([1.0 for _ in 1:3])
end

tr = simulate(rand_prob_vec, ())

throws

ERROR: MethodError: Cannot `convert` an object of type Vector{Float64} to an object of type Float64

Closest candidates are:
  convert(::Type{T}, ::DualNumbers.Dual) where T<:Union{Real, Complex}
   @ DualNumbers ~/.julia/packages/DualNumbers/5knFX/src/dual.jl:24
  convert(::Type{R}, ::T) where {R<:Real, T<:ReverseDiff.TrackedReal}
   @ ReverseDiff ~/.julia/packages/ReverseDiff/UJhiD/src/tracked.jl:260
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:84
  ...

Stacktrace:
 [1] traceat(state::Gen.GFSimulateState, dist::Gen.Dirichlet, args::Tuple{Vector{Float64}}, key::Symbol)
   @ Gen ~/.julia/packages/Gen/ME5el/src/dynamic/simulate.jl:19
 [2] var"##rand_prob_vec#225"(state#227::Gen.GFSimulateState)
   @ Main ~/synthesis/frans/test_dirichlet.jl:4
 [3] exec(gen_fn::DynamicDSLFunction{Any}, state::Gen.GFSimulateState, args::Tuple{})
   @ Gen ~/.julia/packages/Gen/ME5el/src/dynamic/dynamic.jl:58
 [4] simulate(gen_fn::DynamicDSLFunction{Any}, args::Tuple{})
   @ Gen ~/.julia/packages/Gen/ME5el/src/dynamic/simulate.jl:61

@ztangent
Copy link
Member

Thanks for noticing this, surprised our checks didn't catch it! While you're at it, do you think you could adjust the docstring so it fits the rest of the distributions? Currently it is:

"""
    Dirichlet(alpha::Vector{Float64})

Sample a simplex Vector{Float64} from a Dirichlet distribution.
"""

But it shouldn't be capitalized. It should be:

"""
    dirichlet(alpha::Vector{Float64})

Sample a simplex Vector{Float64} from a Dirichlet distribution.
"""

@ztangent ztangent merged commit 73d3790 into probcomp:master Mar 28, 2024
4 of 5 checks passed
@ztangent
Copy link
Member

Awesome, merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants