# In BAT.jl I'm unable to find the Log Denstiy Value

**URL:** <https://discourse.julialang.org/t/in-bat-jl-im-unable-to-find-the-log-denstiy-value/60390>\
**Category:** Statistics\
**Tags:** question, statistics, distributions\
**Created:** [May 1, 2021, 5:53pm UTC](https://discourse.julialang.org/t/in-bat-jl-im-unable-to-find-the-log-denstiy-value/60390 "2021-05-01T17:53:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 1, 2021, 5:53pm UTC](https://discourse.julialang.org/t/in-bat-jl-im-unable-to-find-the-log-denstiy-value/60390/1 "2021-05-01T17:53:27Z")

</div>

```julia

data = vcat(
    rand(Normal(-1.0, 0.5), 500),
    rand(Normal( 2.0, 0.5), 1000)
)
hist = append!(Histogram(-2:0.1:4), data)
function fit_function(p::NamedTuple{(:a, :mu, :sigma)}, x::Real)
    p.a[1] * pdf(Normal(p.mu[1], p.sigma), x) +
    p.a[2] * pdf(Normal(p.mu[2], p.sigma), x)
end
true_par_values = (a = [500, 1000], mu = (-1.0, 2.0), sigma = 0.5)
using BAT, IntervalSets
likelihood = let h = hist, f = fit_function
    # Histogram counts for each bin as an array:
    observed_counts = h.weights

    # Histogram binning:
    bin_edges = h.edges[1]
    bin_edges_left = bin_edges[1:end-1]
    bin_edges_right = bin_edges[2:end]
    bin_widths = bin_edges_right - bin_edges_left
    bin_centers = (bin_edges_right + bin_edges_left) / 2

    params -> begin
        # Log-likelihood for a single bin:
        function bin_log_likelihood(i)
            # Simple mid-point rule integration of fit function `f` over bin:
            expected_counts = bin_widths[i] * f(params, bin_centers[i])
            logpdf(Poisson(expected_counts), observed_counts[i])
        end

        # Sum log-likelihood over bins:
        idxs = eachindex(observed_counts)
        ll_value = bin_log_likelihood(idxs[1])
        for i in idxs[2:end]
            ll_value += bin_log_likelihood(i)
        end

        # Wrap `ll_value` in `LogDVal` so BAT knows it's a log density-value.
        return LogDVal(ll_value)
    end
end

```

I just went through the tutoroial for BAT.jl, and am that LogDVal is not defined. Am I missing a parackage, or is a function not defined?
