# Custom Likelihood Distribution/increment likelihood

**URL:** <https://discourse.julialang.org/t/custom-likelihood-distribution-increment-likelihood/44292>\
**Category:** Probabilistic Programming\
**Created:** [August 4, 2020, 10:44pm UTC](https://discourse.julialang.org/t/custom-likelihood-distribution-increment-likelihood/44292 "2020-08-04T22:44:08Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![jdselwyn](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jdselwyn](https://discourse.julialang.org/u/jdselwyn)\
**Post date:** [August 7, 2020, 3:34pm UTC](https://discourse.julialang.org/t/custom-likelihood-distribution-increment-likelihood/44292/6 "2020-08-07T15:34:13Z")

</div>

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

```julia

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](https://discourse.julialang.org/t/ann-turing-jl-0-12-0-release/38927) 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?

```julia
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!

---

_[View the full topic](https://discourse.julialang.org/t/custom-likelihood-distribution-increment-likelihood/44292)._
