Skip to content

ForwardDiff type error? #716

@Red-Portal

Description

@Red-Portal
in _unsafe_setindex!, in typeassert, expected Float64, got ForwardDiff.Dual{Nothing,Float64,10}

I'm getting this error while using HMC.

    @turing.model LDA(x, K, α, β) = begin
        N, D = size(x)
        L = 5 # ordinal levels

        ϕ = Array{Float64, 3}(undef, L, D, K);
        for i in 1:D
            for j in 1:K
                ϕ[:, i, j] ~ Dirichlet(L, α)
            end
        end

        θ = Matrix{Float64}(undef, K, N)
        for i in 1:N
            θ[:,i] ~ Dirichlet(K, β)
        end

        marginals = reshape(reshape(ϕ, (L * D, K)) * θ,
                            (L, D, N))
        for i in 1:N
            for j in 1:D
                x[i, j] ~ CategoricalReal(marginals[:,j,i])
            end
        end
        return ϕ, θ
    end

This is the model I'm currently using.
The error is caused here.

ϕ[:, i, j] ~ Dirichlet(L, α)

Also, I experienced problems while using the vectorized notation.

ϕ = Array{Float64, 3}(undef, L * D, K);
ϕ ~ [Dirichlet(K, alpha)]

This causes a dimension error.
How can I correctly used the vectorized notation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions