Skip to content

Instantly share code, notes, and snippets.

@Moelf

Moelf/sample.jl Secret

Created April 19, 2022 03:08
Show Gist options
  • Select an option

  • Save Moelf/ab2f10ce45873bb91eaec60ace8388c0 to your computer and use it in GitHub Desktop.

Select an option

Save Moelf/ab2f10ce45873bb91eaec60ace8388c0 to your computer and use it in GitHub Desktop.
using Turing, LiteHF, Optim
###### Dummy data ######
const v_data = [34,22,13,11] # observed data
const v_sig = [2,3,4,5] # signal
const v_bg = [30,19,9,4] # BKG
const variations = [1,2,3,3]
###### Background and Signal modifier definitions ######
const bkgmodis =[
Histosys(v_bg .+ variations, v_bg .- variations),
Normsys(1.1, 0.9)
]
const bkgexp = ExpCounts(v_bg, bkgmodis)
const sigmodis = [Normfactor()];
const sigexp = ExpCounts(v_sig, sigmodis);
###### Expected counts as a function of μ and θs
function expected_bincounts2(μ, θs)
sigexp(μ) + bkgexp(θs)
end
###### Turing.jl models
@model function binned_b(bincounts)
μ ~ Uniform(0, 6)
θs ~ filldist(Normal(), 2)
expected = expected_bincounts2(μ, θs)
@. bincounts ~ Poisson(expected)
end
###### Feed observed data to model to construct a posterior/likelihood object
const mymodel = binned_b(v_data);
###### Inference
chain_map = optimize(mymodel, MAP(), [1,1,1])
display(chain_map)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment