Custom Likelihood Distribution/increment likelihood

Thank you! When I try running that code I end up getting an error about no method matching acclogp!(::Float64).


C = [0.089398 0.0267295 0.007992; 0.0 0.000164962 4.31057e-5; 0.0170703 0.00223028 0.000291394; 0.0 0.0 0.00431887]
@model function dyadRel(C)
    nCrosses = size(C)[2]
    d ~ Dirichlet(nCrosses, 1 / nCrosses)
    target = sum(log.(C * d))
    Turing.acclogp!(target)
end
sample(dyadRel(C), NUTS(0.5), MCMCThreads(), 100, 4)

julia> sample(dyadRel(C), NUTS(0.5), MCMCThreads(), 100, 4)
ERROR: MethodError: no method matching acclogp!(::Float64)
Closest candidates are:
  acclogp!(::DynamicPPL.VarInfo, ::Any) at C:\Users\jdsel\.julia\packages\DynamicPPL\MRwtL\src\varinfo.jl:617
  acclogp!(::DynamicPPL.ThreadSafeVarInfo, ::Any) at C:\Users\jdsel\.julia\packages\DynamicPPL\MRwtL\src\threadsafe.jl:19

When I modify the code based on what I had been guessing and to have _varinfo based on [ANN] Turing.jl 0.12.0 release the model runs at least. But I get a warning about using an internal variable Warning: you are using the internal variable _varinfo. Is this a warning that should be concerning?

C = [0.089398 0.0267295 0.007992; 0.0 0.000164962 4.31057e-5; 0.0170703 0.00223028 0.000291394; 0.0 0.0 0.00431887]
@model dyadRel(C) = begin
  nCrosses = size(C)[2]
  Δ ~ Dirichlet(nCrosses, 1 / nCrosses)

  lp = sum(log.(C * Δ))
  Turing.acclogp!(_varinfo, lp)
end
sample(dyadRel(C), NUTS(0.5), MCMCThreads(), 100, 4)

Iterations        = 1:50
Thinning interval = 1
Chains            = 1, 2, 3, 4
Samples per chain = 50
internals         = acceptance_rate, hamiltonian_energy, hamiltonian_energy_error, is_accept, log_density, lp, max_hamiltonian_energy_error, n_steps, nom_step_size, numerical_error, step_size, tree_depth
parameters        = Δ[1], Δ[2], Δ[3]

2-element Array{ChainDataFrame,1}

Summary Statistics
  parameters    mean     std  naive_se    mcse       ess   r_hat
  ──────────  ──────  ──────  ────────  ──────  ────────  ──────
        Δ[1]  0.3466  0.2479    0.0175  0.0018  111.7912  1.0274
        Δ[2]  0.2571  0.2373    0.0168  0.0310  125.2170  1.0299
        Δ[3]  0.3963  0.2427    0.0172  0.0293  132.4176  1.0059

Quantiles
  parameters    2.5%   25.0%   50.0%   75.0%   97.5%
  ──────────  ──────  ──────  ──────  ──────  ──────
        Δ[1]  0.0003  0.1239  0.3212  0.5270  0.8542
        Δ[2]  0.0001  0.0385  0.1770  0.4398  0.7939
        Δ[3]  0.0569  0.2049  0.3708  0.5697  0.8781

Thank you for all your help on this!

1 Like