Skip to content
Snippets Groups Projects
visualize.jl 912 B
Newer Older
Luca Lenz's avatar
Luca Lenz committed

function plot_pdf!(ax, d::Distribution, x=[-1:.1e-4:1 ... ]; kwargs...)
    y = pdf.(d, x)
    return lines!(ax, x, y; kwargs...)
end

function plot_pdf!(ax, f::Function, x=[-1:.1e-4:1 ... ]; kwargs... )
    a,b = extrema(x)
    y = exp.(f.(x))
    y = y ./ ( (b-a) * mean(y))
    return lines!(ax, x, y; kwargs...)  
end

function plot_pdf!(ax, f::MultilevelChainSampler.AbstractLogDensity, x=[-1:.1e-4:1 ...]; kwargs...)
    return plot_pdf!(ax, x->logdensity(f, x), x; kwargs...)
end
Luca Lenz's avatar
Luca Lenz committed


function errorlines!(ax, x, m, s; clamp=-Inf, rate=false, args...)
    if rate 
        r = asymptotic_rate(x[2:end], m[2:end])
        r = round(r, sigdigits=4)
        l = lines!(ax, x, m; label = L"O(n^{\alpha}), \quad \alpha = %$r", args...)
    else
        l = lines!(ax, x, m; args...)
    end
    c = l.color[]; c = RGBAf(c.r, c.g, c.b, 0.125)
    s = min.(m .- clamp, s)
    band!(ax,  x, m-s, m+s; color=c )
end